KiCad PCB EDA Suite
CFRUSTUM Struct Reference

#include <cfrustum.h>

Public Member Functions

void GenerateFrustum (const RAY &topLeft, const RAY &topRight, const RAY &bottomLeft, const RAY &bottomRight)
 GenerateFrustum. More...
 
bool Intersect (const CBBOX &aBBox) const
 Intersect - Intersects a bbox with this frustum. More...
 

Private Attributes

SFVEC3F m_normals [4]
 
SFVEC3F m_point [4]
 

Detailed Description

Definition at line 41 of file cfrustum.h.

Member Function Documentation

void CFRUSTUM::GenerateFrustum ( const RAY topLeft,
const RAY topRight,
const RAY bottomLeft,
const RAY bottomRight 
)

GenerateFrustum.

Parameters
topLeft
topRight
bottomLeft
bottomRight

Definition at line 42 of file cfrustum.cpp.

References RAY::m_Dir, m_normals, RAY::m_Origin, and m_point.

Referenced by RAYPACKET_GenerateFrustum().

46 {
47  m_point[0] = topLeft.m_Origin;
48  m_point[1] = topRight.m_Origin;
49  m_point[2] = bottomLeft.m_Origin;
50  m_point[3] = topLeft.m_Origin;
51 
52  m_normals[0] = glm::cross( topRight.m_Dir, topLeft.m_Dir ); // TOP
53  m_normals[1] = glm::cross( bottomRight.m_Dir, topRight.m_Dir ); // RIGHT
54  m_normals[2] = glm::cross( bottomLeft.m_Dir, bottomRight.m_Dir ); // BOTTOM
55  m_normals[3] = glm::cross( topLeft.m_Dir, bottomLeft.m_Dir ); // LEFT
56 }
SFVEC3F m_normals[4]
Definition: cfrustum.h:65
SFVEC3F m_point[4]
Definition: cfrustum.h:66
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F m_Origin
Definition: ray.h:45
bool CFRUSTUM::Intersect ( const CBBOX aBBox) const

Intersect - Intersects a bbox with this frustum.

Parameters
aBBoxa bbox to test
Returns
true if the bbox intersects this frustum

Definition at line 65 of file cfrustum.cpp.

References m_normals, m_point, CBBOX::Max(), and CBBOX::Min().

Referenced by getFirstHit(), and CBVH_PBRT::Intersect().

66 {
67  const SFVEC3F box[8] = { aBBox.Min(),
68  aBBox.Max(),
69  SFVEC3F(aBBox.Min().x, aBBox.Min().y, aBBox.Max().z),
70  SFVEC3F(aBBox.Min().x, aBBox.Max().y, aBBox.Min().z),
71  SFVEC3F(aBBox.Min().x, aBBox.Max().y, aBBox.Max().z),
72  SFVEC3F(aBBox.Max().x, aBBox.Min().y, aBBox.Min().z),
73  SFVEC3F(aBBox.Max().x, aBBox.Min().y, aBBox.Max().z),
74  SFVEC3F(aBBox.Max().x, aBBox.Max().y, aBBox.Min().z) };
75 
76  // test each plane of frustum individually; if the point is on the wrong
77  // side of the plane, the box is outside the frustum and we can exit
78  int out_side = 0;
79 
80  for( unsigned int i = 0; i < 4; ++i )
81  {
82  const SFVEC3F &pointPlane = m_point[i];
83  const SFVEC3F &normalPlane = m_normals[i];
84 
85  for( unsigned int j = 0; j < 8; ++j )
86  {
87  const SFVEC3F OP = pointPlane - box[j];
88  const float dot = glm::dot( OP, normalPlane );
89 
90  if( dot < FLT_EPSILON )
91  {
92  out_side++;
93 
94  break;
95  }
96  }
97  }
98 
99  if( out_side == 4 )
100  return true;
101 
102  return false;
103 }
SFVEC3F m_normals[4]
Definition: cfrustum.h:65
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
SFVEC3F m_point[4]
Definition: cfrustum.h:66
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:212
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

Member Data Documentation

SFVEC3F CFRUSTUM::m_normals[4]
private

Definition at line 65 of file cfrustum.h.

Referenced by GenerateFrustum(), and Intersect().

SFVEC3F CFRUSTUM::m_point[4]
private

Definition at line 66 of file cfrustum.h.

Referenced by GenerateFrustum(), and Intersect().


The documentation for this struct was generated from the following files: