KiCad PCB EDA Suite
FRUSTUM Struct Reference

#include <frustum.h>

Public Member Functions

void GenerateFrustum (const RAY &topLeft, const RAY &topRight, const RAY &bottomLeft, const RAY &bottomRight)
 
bool Intersect (const BBOX_3D &aBBox) const
 Intersect aBBox with this frustum. More...
 

Private Attributes

SFVEC3F m_normals [4]
 
SFVEC3F m_point [4]
 

Detailed Description

Definition at line 41 of file frustum.h.

Member Function Documentation

◆ GenerateFrustum()

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

Definition at line 41 of file frustum.cpp.

43 {
44  m_point[0] = topLeft.m_Origin;
45  m_point[1] = topRight.m_Origin;
46  m_point[2] = bottomLeft.m_Origin;
47  m_point[3] = topLeft.m_Origin;
48 
49  m_normals[0] = glm::cross( topRight.m_Dir, topLeft.m_Dir ); // TOP
50  m_normals[1] = glm::cross( bottomRight.m_Dir, topRight.m_Dir ); // RIGHT
51  m_normals[2] = glm::cross( bottomLeft.m_Dir, bottomRight.m_Dir ); // BOTTOM
52  m_normals[3] = glm::cross( topLeft.m_Dir, bottomLeft.m_Dir ); // LEFT
53 }
SFVEC3F m_normals[4]
Definition: frustum.h:56
SFVEC3F m_point[4]
Definition: frustum.h:57
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69

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

Referenced by RAYPACKET_GenerateFrustum().

◆ Intersect()

bool FRUSTUM::Intersect ( const BBOX_3D aBBox) const

Intersect aBBox with this frustum.

Parameters
aBBoxis a bounding box to test.
Returns
true if the bounding box intersects this frustum.

Definition at line 62 of file frustum.cpp.

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

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

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

Member Data Documentation

◆ m_normals

SFVEC3F FRUSTUM::m_normals[4]
private

Definition at line 56 of file frustum.h.

Referenced by GenerateFrustum(), and Intersect().

◆ m_point

SFVEC3F FRUSTUM::m_point[4]
private

Definition at line 57 of file frustum.h.

Referenced by GenerateFrustum(), and Intersect().


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