KiCad PCB EDA Suite
CBBOX Struct Reference

CBBOX manages a bounding box defined by two SFVEC3F min max points. More...

#include <cbbox.h>

Public Member Functions

 CBBOX ()
 Constructor CBBOX Create with default values a bounding box (not inizialized) More...
 
 CBBOX (const SFVEC3F &aPbInit)
 Constructor CBBOX Initialize a bounding box with a given point. More...
 
 CBBOX (const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
 Constructor CBBOX Initialize a bounding box with a minimon and a maximun point. More...
 
 ~CBBOX ()
 
void Set (const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
 Function Set Set bounding box with new parameters. More...
 
void Set (const CBBOX &aBBox)
 
void Set (const SFVEC3F &aPoint)
 Set. More...
 
void Union (const SFVEC3F &aPoint)
 Function Union recalculate the bounding box adding a point. More...
 
void Union (const CBBOX &aBBox)
 Function Union recalculate the bounding box adding other bounding box. More...
 
void Scale (float aScale)
 Function Scale scales a bounding box by its center. More...
 
void ScaleNextUp ()
 Function ScaleNextUp scales a bounding box to the next float representation making it larger. More...
 
void ScaleNextDown ()
 Function ScaleNextDown scales a bounding box to the next float representation making it smaller. More...
 
bool Intersects (const CBBOX &aBBox) const
 Function Intersects test if a bounding box intersects this box. More...
 
bool Inside (const SFVEC3F &aPoint) const
 Function Inside check is a point is inside this bounding box. More...
 
void ApplyTransformation (glm::mat4 aTransformMatrix)
 Function ApplyTransformation apply a transformation matrix to the box points. More...
 
void ApplyTransformationAA (glm::mat4 aTransformMatrix)
 Function ApplyTransformationAA apply a transformation matrix to the box points and recalculate it to fit an axis aligned bounding box. More...
 
float Volume () const
 Function Volume calculate the volume of a bounding box. More...
 
void debug () const
 Function debug output to stdout. More...
 
bool IsInitialized () const
 Function IsInitialized check if this bounding box is already initialized. More...
 
void Reset ()
 Function Reset reset the bounding box to zero and de-initialized it. More...
 
SFVEC3F GetCenter () const
 Function GetCenter return the center point of the bounding box. More...
 
float GetCenter (unsigned int aAxis) const
 Function GetCenter return the center point of the bounding box for one Axis (0, 1 or 2) More...
 
SFVEC3F Offset (const SFVEC3F &p) const
 Function Offset. More...
 
const SFVEC3F GetExtent () const
 Function GetExtent. More...
 
const SFVEC3FMin () const
 Function Min return the minimun vertex pointer. More...
 
const SFVEC3FMax () const
 Function Max return the maximum vertex pointer. More...
 
unsigned int MaxDimension () const
 Function MaxDimension. More...
 
float GetMaxDimension () const
 GetMaxDimension. More...
 
float SurfaceArea () const
 Function SurfaceArea. More...
 
bool Intersect (const RAY &aRay, float *t) const
 Function Intersect. More...
 
bool Intersect (const RAY &aRay) const
 
bool Intersect (const RAY &aRay, float *aOutHitt0, float *aOutHitt1) const
 Function Intersect - Useful for get the enter and exit position If the ray starts inside the bbox, it will return aOutHitt0 = 0.0. More...
 

Private Attributes

SFVEC3F m_min
 (12) point of the lower position of the bounding box More...
 
SFVEC3F m_max
 (12) point of the higher position of the bounding box More...
 

Detailed Description

CBBOX manages a bounding box defined by two SFVEC3F min max points.

Definition at line 39 of file cbbox.h.

Constructor & Destructor Documentation

◆ CBBOX() [1/3]

CBBOX::CBBOX ( )

Constructor CBBOX Create with default values a bounding box (not inizialized)

Definition at line 37 of file cbbox.cpp.

38 {
39  Reset();
40 }
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:99

References Reset().

Referenced by ApplyTransformationAA().

◆ CBBOX() [2/3]

CBBOX::CBBOX ( const SFVEC3F aPbInit)
explicit

Constructor CBBOX Initialize a bounding box with a given point.

Parameters
aPbInita point for the bounding box initialization

Definition at line 43 of file cbbox.cpp.

44 {
45  m_min = aPbInit;
46  m_max = aPbInit;
47 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

◆ CBBOX() [3/3]

CBBOX::CBBOX ( const SFVEC3F aPbMin,
const SFVEC3F aPbMax 
)

Constructor CBBOX Initialize a bounding box with a minimon and a maximun point.

Parameters
aPbMinthe minimun point to initialize the bounding box
aPbMaxthe maximun point to initialize the bounding box

Definition at line 50 of file cbbox.cpp.

51 {
52  Set( aPbMin, aPbMax );
53 }
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:68

References Set().

◆ ~CBBOX()

CBBOX::~CBBOX ( )

Definition at line 56 of file cbbox.cpp.

57 {
58 }

Member Function Documentation

◆ ApplyTransformation()

void CBBOX::ApplyTransformation ( glm::mat4  aTransformMatrix)

Function ApplyTransformation apply a transformation matrix to the box points.

Parameters
aTransformMatrixmatrix to apply to the points of the bounding box

Definition at line 352 of file cbbox.cpp.

353 {
354  wxASSERT( IsInitialized() );
355 
356  const SFVEC3F v1 = SFVEC3F( aTransformMatrix *
357  glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) );
358 
359  const SFVEC3F v2 = SFVEC3F( aTransformMatrix *
360  glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) );
361 
362  Reset();
363  Union( v1 );
364  Union( v2 );
365 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
void Union(const SFVEC3F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox.cpp:106
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:99
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References IsInitialized(), m_max, m_min, Reset(), and Union().

◆ ApplyTransformationAA()

void CBBOX::ApplyTransformationAA ( glm::mat4  aTransformMatrix)

Function ApplyTransformationAA apply a transformation matrix to the box points and recalculate it to fit an axis aligned bounding box.

Parameters
aTransformMatrixmatrix to apply to the points of the bounding box

Definition at line 368 of file cbbox.cpp.

369 {
370  wxASSERT( IsInitialized() );
371 
372  // apply the transformation matrix for each of vertices of the bounding box
373  // and make a union with all vertices
374  CBBOX tmpBBox = CBBOX(
375  SFVEC3F( aTransformMatrix *
376  glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) ) );
377  tmpBBox.Union( SFVEC3F( aTransformMatrix *
378  glm::vec4( m_max.x, m_min.y, m_min.z, 1.0f ) ) );
379  tmpBBox.Union( SFVEC3F( aTransformMatrix *
380  glm::vec4( m_min.x, m_max.y, m_min.z, 1.0f ) ) );
381  tmpBBox.Union( SFVEC3F( aTransformMatrix *
382  glm::vec4( m_min.x, m_min.y, m_max.z, 1.0f ) ) );
383  tmpBBox.Union( SFVEC3F( aTransformMatrix *
384  glm::vec4( m_min.x, m_max.y, m_max.z, 1.0f ) ) );
385  tmpBBox.Union( SFVEC3F( aTransformMatrix *
386  glm::vec4( m_max.x, m_max.y, m_min.z, 1.0f ) ) );
387  tmpBBox.Union( SFVEC3F( aTransformMatrix *
388  glm::vec4( m_max.x, m_min.y, m_max.z, 1.0f ) ) );
389  tmpBBox.Union( SFVEC3F( aTransformMatrix *
390  glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) ) );
391 
392  m_min = tmpBBox.m_min;
393  m_max = tmpBBox.m_max;
394 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
CBBOX()
Constructor CBBOX Create with default values a bounding box (not inizialized)
Definition: cbbox.cpp:37
void Union(const SFVEC3F &aPoint)
Function Union recalculate the bounding box adding a point.
Definition: cbbox.cpp:106
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:39
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References CBBOX(), IsInitialized(), m_max, m_min, and Union().

◆ debug()

void CBBOX::debug ( ) const

Function debug output to stdout.

Definition at line 397 of file cbbox.cpp.

398 {
399  wxLogDebug( "min(%f, %f, %f) - max(%f, %f, %f)\n", m_min.x, m_min.y, m_min.z,
400  m_max.x, m_max.y, m_max.z );
401 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

◆ GetCenter() [1/2]

SFVEC3F CBBOX::GetCenter ( ) const

Function GetCenter return the center point of the bounding box.

Returns
SFVEC3F - the position of the center of this bounding box

Definition at line 136 of file cbbox.cpp.

137 {
138  return (m_max + m_min) * 0.5f;
139 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by CDUMMYBLOCK::CDUMMYBLOCK(), CROUNDSEG::CROUNDSEG(), CVCYLINDER::CVCYLINDER(), CXYPLANE::CXYPLANE(), C3D_MODEL_VIEWER::OnPaint(), HLBVH_SAH_Evaluator::operator()(), CTRIANGLE::pre_calc_const(), CBVH_PBRT::recursiveBuild(), C3D_RENDER_RAYTRACING::Reload(), and Scale().

◆ GetCenter() [2/2]

float CBBOX::GetCenter ( unsigned int  aAxis) const

Function GetCenter return the center point of the bounding box for one Axis (0, 1 or 2)

Returns
float - the position of the center of this bounding box for the axis

Definition at line 142 of file cbbox.cpp.

143 {
144  wxASSERT( aAxis < 3 );
145  return (m_max[aAxis] + m_min[aAxis]) * 0.5f;
146 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

◆ GetExtent()

const SFVEC3F CBBOX::GetExtent ( ) const

Function GetExtent.

Returns
SFVEC3F - max-min

Definition at line 149 of file cbbox.cpp.

150 {
151  return m_max - m_min;
152 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by CXYPLANE::CXYPLANE(), GetMaxDimension(), MaxDimension(), SurfaceArea(), and Volume().

◆ GetMaxDimension()

float CBBOX::GetMaxDimension ( ) const

GetMaxDimension.

Returns
the max dimension

Definition at line 170 of file cbbox.cpp.

171 {
172  unsigned int max_dimensions_idx = 0;
173 
174  SFVEC3F extent = GetExtent();
175 
176  if( extent.y > extent.x )
177  max_dimensions_idx = 1;
178  if( extent.z > extent.y )
179  max_dimensions_idx = 2;
180 
181  return extent[max_dimensions_idx];
182 }
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:149
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

References GetExtent().

Referenced by C3D_MODEL_VIEWER::OnPaint().

◆ Inside()

bool CBBOX::Inside ( const SFVEC3F aPoint) const

Function Inside check is a point is inside this bounding box.

Parameters
aPointpoint to test

Definition at line 244 of file cbbox.cpp.

245 {
246  wxASSERT( IsInitialized() );
247 
248  return (( aPoint.x >= m_min.x ) && ( aPoint.x <= m_max.x ) &&
249  ( aPoint.y >= m_min.y ) && ( aPoint.y <= m_max.y ) &&
250  ( aPoint.z >= m_min.z ) && ( aPoint.z <= m_max.z ));
251 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References IsInitialized(), m_max, and m_min.

Referenced by CLAYERITEM::Intersect().

◆ Intersect() [1/3]

bool CBBOX::Intersect ( const RAY aRay,
float *  t 
) const

Function Intersect.

Parameters
aRay= ray to intersect the box
t= distance point of the ray of the intersection (if true)
Returns
true if the ray hits the box

Definition at line 45 of file cbbox_ray.cpp.

46 {
47  switch( aRay.m_Classification )
48  {
50  {
51  if( ( aRay.m_Origin.x < m_min.x )
52  || ( aRay.m_Origin.y < m_min.y )
53  || ( aRay.m_Origin.z < m_min.z )
54  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
55  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
56  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
57  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0)
58  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
59  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
60  )
61  return false;
62 
63  // compute the intersection distance
64 
65  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
66 
67  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
68 
69  if( t1 > *t )
70  *t = t1;
71 
72  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
73 
74  if( t2 > *t )
75  *t = t2;
76 
77  return true;
78  }
79 
80 
82  {
83  if( ( aRay.m_Origin.x < m_min.x )
84  || ( aRay.m_Origin.y < m_min.y )
85  || ( aRay.m_Origin.z > m_max.z )
86  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
87  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
88  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
89  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
90  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
91  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
92  )
93  return false;
94 
95  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
96 
97  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
98 
99  if( t1 > *t )
100  *t = t1;
101 
102  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
103 
104  if( t2 > *t )
105  *t = t2;
106 
107  return true;
108  }
109 
111  {
112  if( ( aRay.m_Origin.x < m_min.x )
113  || ( aRay.m_Origin.y > m_max.y )
114  || ( aRay.m_Origin.z < m_min.z )
115  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
116  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
117  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
118  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
119  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
120  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
121  )
122  return false;
123 
124  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
125 
126  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
127 
128  if( t1 > *t )
129  *t = t1;
130 
131  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
132 
133  if( t2 > *t )
134  *t = t2;
135 
136  return true;
137  }
138 
140  {
141  if( ( aRay.m_Origin.x < m_min.x )
142  || ( aRay.m_Origin.y > m_max.y )
143  || ( aRay.m_Origin.z > m_max.z )
144  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
145  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
146  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
147  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
148  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
149  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
150  )
151  return false;
152 
153  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
154 
155  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
156 
157  if( t1 > *t )
158  *t = t1;
159 
160  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
161 
162  if( t2 > *t )
163  *t = t2;
164 
165  return true;
166  }
167 
169  {
170  if( ( aRay.m_Origin.x > m_max.x )
171  || ( aRay.m_Origin.y < m_min.y )
172  || ( aRay.m_Origin.z < m_min.z )
173  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
174  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
175  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
176  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0)
177  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
178  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
179  )
180  return false;
181 
182  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
183 
184  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
185 
186  if( t1 > *t )
187  *t = t1;
188 
189  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
190 
191  if( t2 > *t )
192  *t = t2;
193 
194  return true;
195  }
196 
197 
199  {
200  if( ( aRay.m_Origin.x > m_max.x )
201  || ( aRay.m_Origin.y < m_min.y )
202  || ( aRay.m_Origin.z > m_max.z )
203  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
204  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
205  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
206  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
207  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
208  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
209  )
210  return false;
211 
212  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
213 
214  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
215 
216  if( t1 > *t )
217  *t = t1;
218 
219  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
220 
221  if( t2 > *t )
222  *t = t2;
223 
224  return true;
225  }
226 
228  {
229  if( ( aRay.m_Origin.x > m_max.x )
230  || ( aRay.m_Origin.y > m_max.y )
231  || ( aRay.m_Origin.z < m_min.z )
232  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
233  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
234  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
235  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
236  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
237  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
238  )
239  return false;
240 
241  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
242 
243  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
244 
245  if( t1 > *t )
246  *t = t1;
247 
248  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
249 
250  if( t2 > *t )
251  *t = t2;
252 
253  return true;
254  }
255 
257  {
258  if( ( aRay.m_Origin.x > m_max.x )
259  || ( aRay.m_Origin.y > m_max.y )
260  || ( aRay.m_Origin.z > m_max.z )
261  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
262  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
263  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
264  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
265  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
266  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
267  )
268  return false;
269 
270  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
271 
272  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
273 
274  if( t1 > *t )
275  *t = t1;
276 
277  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
278 
279  if( t2 > *t )
280  *t = t2;
281 
282  return true;
283  }
284 
286  {
287  if( ( aRay.m_Origin.x < m_min.x )
288  || ( aRay.m_Origin.x > m_max.x )
289  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.z < m_min.z)
290  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
291  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0)
292  )
293  return false;
294 
295  *t = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
296 
297  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
298 
299  if( t2 > *t )
300  *t = t2;
301 
302  return true;
303  }
304 
306  {
307  if( ( aRay.m_Origin.x < m_min.x )
308  || ( aRay.m_Origin.x > m_max.x )
309  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.z > m_max.z)
310  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
311  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
312  )
313  return false;
314 
315  *t = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
316 
317  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
318 
319  if( t2 > *t )
320  *t = t2;
321 
322  return true;
323  }
324 
326  {
327  if( ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
328  || ( aRay.m_Origin.y > m_max.y) || ( aRay.m_Origin.z < m_min.z)
329  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
330  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
331  )
332  return false;
333 
334  *t = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
335 
336  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
337 
338  if( t2 > *t )
339  *t = t2;
340 
341  return true;
342  }
343 
345  {
346  if( ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
347  || ( aRay.m_Origin.y > m_max.y) || ( aRay.m_Origin.z > m_max.z)
348  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
349  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
350  )
351  return false;
352 
353  *t = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
354 
355  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
356 
357  if( t2 > *t )
358  *t = t2;
359 
360  return true;
361  }
362 
363 
365  {
366  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
367  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.z < m_min.z)
368  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
369  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
370  )
371  return false;
372 
373  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
374 
375  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
376 
377  if( t2 > *t )
378  *t = t2;
379 
380  return true;
381  }
382 
383 
385  {
386  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
387  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.z > m_max.z)
388  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
389  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
390  )
391  return false;
392 
393  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
394 
395  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
396 
397  if( t2 > *t )
398  *t = t2;
399 
400  return true;
401  }
402 
404  {
405  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
406  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.z < m_min.z)
407  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
408  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
409  )
410  return false;
411 
412  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
413 
414  float t2 = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
415 
416  if( t2 > *t )
417  *t = t2;
418 
419  return true;
420  }
421 
422 
424  {
425  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
426  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.z > m_max.z)
427  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
428  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
429  )
430  return false;
431 
432  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
433 
434  float t2 = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
435 
436  if( t2 > *t )
437  *t = t2;
438 
439  return true;
440  }
441 
443  {
444  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
445  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.y < m_min.y)
446  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
447  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
448  )
449  return false;
450 
451  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
452 
453  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
454 
455  if( t1 > *t )
456  *t = t1;
457 
458  return true;
459  }
460 
462  {
463  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
464  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.y > m_max.y)
465  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
466  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
467  )
468  return false;
469 
470  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
471 
472  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
473 
474  if( t1 > *t )
475  *t = t1;
476 
477  return true;
478  }
479 
480 
482  {
483  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
484  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.y < m_min.y)
485  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
486  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
487  )
488  return false;
489 
490  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
491 
492  float t1 = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
493 
494  if( t1 > *t )
495  *t = t1;
496 
497  return true;
498  }
499 
501  {
502  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
503  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.y > m_max.y)
504  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
505  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
506  )
507  return false;
508 
509  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
510 
511  float t1 = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
512 
513  if( t1 > *t )
514  *t = t1;
515 
516  return true;
517  }
518 
519 
521  {
522  if( ( aRay.m_Origin.x < m_min.x)
523  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
524  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
525  )
526  return false;
527 
528  *t = (m_max.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
529 
530  return true;
531  }
532 
534  {
535  if( ( aRay.m_Origin.x > m_max.x)
536  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
537  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
538  )
539  return false;
540 
541  *t = (m_min.x - aRay.m_Origin.x) * aRay.m_InvDir.x;
542 
543  return true;
544  }
545 
547  {
548  if( ( aRay.m_Origin.y < m_min.y)
549  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
550  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
551  )
552  return false;
553 
554  *t = (m_max.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
555 
556  return true;
557  }
558 
560  {
561  if( ( aRay.m_Origin.y > m_max.y)
562  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
563  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
564  )
565  return false;
566 
567  *t = (m_min.y - aRay.m_Origin.y) * aRay.m_InvDir.y;
568 
569  return true;
570  }
571 
572 
574  {
575  if( ( aRay.m_Origin.z < m_min.z)
576  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
577  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
578  )
579  return false;
580 
581  *t = (m_max.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
582 
583  return true;
584  }
585 
587  {
588  if( ( aRay.m_Origin.z > m_max.z)
589  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
590  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
591  )
592  return false;
593 
594  *t = (m_min.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
595 
596  return true;
597  }
598  }
599 
600  return false;
601 }
float c_xy
Definition: ray.h:78
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
float c_zy
Definition: ray.h:78
float jbyk
Definition: ray.h:77
float kbyi
Definition: ray.h:77
float c_yx
Definition: ray.h:78
SFVEC3F m_InvDir
Definition: ray.h:75
float kbyj
Definition: ray.h:77
RAY_CLASSIFICATION m_Classification
Definition: ray.h:73
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
float ibyj
Definition: ray.h:77
float jbyi
Definition: ray.h:77
float c_yz
Definition: ray.h:78
SFVEC3F m_Origin
Definition: ray.h:69
float c_zx
Definition: ray.h:78
float c_xz
Definition: ray.h:78
float ibyk
Definition: ray.h:77

References RAY::c_xy, RAY::c_xz, RAY::c_yx, RAY::c_yz, RAY::c_zx, RAY::c_zy, RAY::ibyj, RAY::ibyk, RAY::jbyi, RAY::jbyk, RAY::kbyi, RAY::kbyj, RAY::m_Classification, RAY::m_InvDir, m_max, m_min, RAY::m_Origin, MMM, MMO, MMP, MOM, MOO, MOP, MPM, MPO, MPP, OMM, OMO, OMP, OOM, OOP, OPM, OPO, OPP, PMM, PMO, PMP, POM, POO, POP, PPM, PPO, and PPP.

Referenced by getFirstHit(), getLastHit(), CDUMMYBLOCK::Intersect(), CLAYERITEM::Intersect(), CCONTAINER::Intersect(), CBVH_PBRT::Intersect(), CDUMMYBLOCK::IntersectP(), CLAYERITEM::IntersectP(), CBVH_PBRT::IntersectP(), and EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

◆ Intersect() [2/3]

bool CBBOX::Intersect ( const RAY aRay) const

Definition at line 604 of file cbbox_ray.cpp.

605 {
606  switch( aRay.m_Classification )
607  {
609  {
610  if( ( aRay.m_Origin.x < m_min.x )
611  || ( aRay.m_Origin.y < m_min.y )
612  || ( aRay.m_Origin.z < m_min.z )
613  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
614  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
615  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
616  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0)
617  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
618  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
619  )
620  return false;
621 
622  return true;
623  }
624 
625 
627  {
628  if( ( aRay.m_Origin.x < m_min.x )
629  || ( aRay.m_Origin.y < m_min.y )
630  || ( aRay.m_Origin.z > m_max.z )
631  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
632  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
633  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
634  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
635  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
636  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
637  )
638  return false;
639 
640  return true;
641  }
642 
644  {
645  if( ( aRay.m_Origin.x < m_min.x )
646  || ( aRay.m_Origin.y > m_max.y )
647  || ( aRay.m_Origin.z < m_min.z )
648  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
649  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
650  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
651  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
652  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
653  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
654  )
655  return false;
656 
657  return true;
658  }
659 
661  {
662  if( ( aRay.m_Origin.x < m_min.x )
663  || ( aRay.m_Origin.y > m_max.y )
664  || ( aRay.m_Origin.z > m_max.z )
665  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
666  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
667  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
668  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
669  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
670  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
671  )
672  return false;
673 
674  return true;
675  }
676 
678  {
679  if( ( aRay.m_Origin.x > m_max.x )
680  || ( aRay.m_Origin.y < m_min.y )
681  || ( aRay.m_Origin.z < m_min.z )
682  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
683  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
684  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
685  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0)
686  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
687  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
688  )
689  return false;
690 
691  return true;
692  }
693 
694 
696  {
697  if( ( aRay.m_Origin.x > m_max.x )
698  || ( aRay.m_Origin.y < m_min.y )
699  || ( aRay.m_Origin.z > m_max.z )
700  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
701  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
702  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
703  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
704  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
705  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
706  )
707  return false;
708 
709  return true;
710  }
711 
713  {
714  if( ( aRay.m_Origin.x > m_max.x )
715  || ( aRay.m_Origin.y > m_max.y )
716  || ( aRay.m_Origin.z < m_min.z )
717  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
718  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
719  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
720  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
721  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
722  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
723  )
724  return false;
725 
726  return true;
727  }
728 
730  {
731  if( ( aRay.m_Origin.x > m_max.x )
732  || ( aRay.m_Origin.y > m_max.y )
733  || ( aRay.m_Origin.z > m_max.z )
734  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
735  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
736  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
737  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
738  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
739  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
740  )
741  return false;
742 
743  return true;
744  }
745 
747  {
748  if( ( aRay.m_Origin.x < m_min.x )
749  || ( aRay.m_Origin.x > m_max.x )
750  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.z < m_min.z)
751  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0)
752  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0) )
753  return false;
754 
755  return true;
756  }
757 
759  {
760  if( ( aRay.m_Origin.x < m_min.x )
761  || ( aRay.m_Origin.x > m_max.x )
762  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.z > m_max.z)
763  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0)
764  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0)
765  )
766  return false;
767 
768  return true;
769  }
770 
772  {
773  if( ( aRay.m_Origin.x < m_min.x )
774  || ( aRay.m_Origin.x > m_max.x )
775  || ( aRay.m_Origin.y > m_max.y) || ( aRay.m_Origin.z < m_min.z)
776  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0)
777  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0)
778  )
779  return false;
780 
781  return true;
782  }
783 
785  {
786  if( ( aRay.m_Origin.x < m_min.x )
787  || ( aRay.m_Origin.x > m_max.x )
788  || ( aRay.m_Origin.y > m_max.y) || ( aRay.m_Origin.z > m_max.z)
789  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0)
790  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0)
791  )
792  return false;
793 
794  return true;
795  }
796 
797 
799  {
800  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
801  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.z < m_min.z)
802  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0)
803  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0)
804  )
805  return false;
806 
807  return true;
808  }
809 
810 
812  {
813  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
814  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.z > m_max.z)
815  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0)
816  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0)
817  )
818  return false;
819 
820  return true;
821  }
822 
824  {
825  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
826  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.z < m_min.z)
827  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0)
828  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0)
829  )
830  return false;
831 
832  return true;
833  }
834 
835 
837  {
838  if( ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
839  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.z > m_max.z)
840  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0)
841  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0)
842  )
843  return false;
844 
845  return true;
846  }
847 
849  {
850  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
851  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.y < m_min.y)
852  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0)
853  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0)
854  )
855  return false;
856 
857  return true;
858  }
859 
861  {
862  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
863  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.y > m_max.y)
864  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0)
865  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0)
866  )
867  return false;
868 
869  return true;
870  }
871 
872 
874  {
875  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
876  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.y < m_min.y)
877  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0)
878  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0)
879  )
880  return false;
881 
882  return true;
883  }
884 
886  {
887  if( ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
888  || ( aRay.m_Origin.x > m_max.x) || ( aRay.m_Origin.y > m_max.y)
889  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0)
890  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0)
891  )
892  return false;
893 
894  return true;
895  }
896 
897 
899  {
900  if( ( aRay.m_Origin.x < m_min.x)
901  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
902  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
903  )
904  return false;
905 
906  return true;
907  }
908 
910  {
911  if( ( aRay.m_Origin.x > m_max.x)
912  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
913  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
914  )
915  return false;
916 
917  return true;
918  }
919 
921  {
922  if( ( aRay.m_Origin.y < m_min.y)
923  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
924  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
925  )
926  return false;
927 
928  return true;
929  }
930 
932  {
933  if( ( aRay.m_Origin.y > m_max.y)
934  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
935  || ( aRay.m_Origin.z < m_min.z) || ( aRay.m_Origin.z > m_max.z)
936  )
937  return false;
938 
939  return true;
940  }
941 
942 
944  {
945  if( ( aRay.m_Origin.z < m_min.z)
946  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
947  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
948  )
949  return false;
950 
951  return true;
952  }
953 
955  {
956  if( ( aRay.m_Origin.z > m_max.z)
957  || ( aRay.m_Origin.x < m_min.x) || ( aRay.m_Origin.x > m_max.x)
958  || ( aRay.m_Origin.y < m_min.y) || ( aRay.m_Origin.y > m_max.y)
959  )
960  return false;
961 
962  return true;
963  }
964  }
965 
966  return false;
967 }
float c_xy
Definition: ray.h:78
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
float c_zy
Definition: ray.h:78
float jbyk
Definition: ray.h:77
float kbyi
Definition: ray.h:77
float c_yx
Definition: ray.h:78
float kbyj
Definition: ray.h:77
RAY_CLASSIFICATION m_Classification
Definition: ray.h:73
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
float ibyj
Definition: ray.h:77
float jbyi
Definition: ray.h:77
float c_yz
Definition: ray.h:78
SFVEC3F m_Origin
Definition: ray.h:69
float c_zx
Definition: ray.h:78
float c_xz
Definition: ray.h:78
float ibyk
Definition: ray.h:77

References RAY::c_xy, RAY::c_xz, RAY::c_yx, RAY::c_yz, RAY::c_zx, RAY::c_zy, RAY::ibyj, RAY::ibyk, RAY::jbyi, RAY::jbyk, RAY::kbyi, RAY::kbyj, RAY::m_Classification, m_max, m_min, RAY::m_Origin, MMM, MMO, MMP, MOM, MOO, MOP, MPM, MPO, MPP, OMM, OMO, OMP, OOM, OOP, OPM, OPO, OPP, PMM, PMO, PMP, POM, POO, POP, PPM, PPO, and PPP.

◆ Intersect() [3/3]

bool CBBOX::Intersect ( const RAY aRay,
float *  aOutHitt0,
float *  aOutHitt1 
) const

Function Intersect - Useful for get the enter and exit position If the ray starts inside the bbox, it will return aOutHitt0 = 0.0.

Parameters
aRay= ray to intersect the box
aOutHitt0= distance point of the ray of the intersection (if true)
aOutHitt1= distance point of the ray of the exit (if true)
Returns
true if the ray hits the box

Definition at line 311 of file cbbox.cpp.

314 {
315  wxASSERT( aOutHitt0 );
316  wxASSERT( aOutHitt1 );
317 
318  const SFVEC3F bounds[2] = {m_min, m_max};
319 
320  // Check for ray intersection against x and y slabs
321  float tmin = (bounds[ aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
322  float tmax = (bounds[1 - aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
323  const float tymin = (bounds[ aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
324  const float tymax = (bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
325 
326  if( (tmin > tymax) || (tymin > tmax) )
327  return false;
328 
329  tmin = (tymin > tmin)? tymin : tmin;
330  tmax = (tymax < tmax)? tymax : tmax;
331 
332  // Check for ray intersection against z slab
333  const float tzmin = (bounds[ aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z;
334  const float tzmax = (bounds[1 - aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z) * aRay.m_InvDir.z;
335 
336  if( (tmin > tzmax) || (tzmin > tmax) )
337  return false;
338 
339  tmin = (tzmin > tmin)? tzmin : tmin;
340  tmin = ( tmin < 0.0f)? 0.0f : tmin;
341 
342  tmax = (tzmax < tmax)? tzmax : tmax;
343 
344  *aOutHitt0 = tmin;
345  *aOutHitt1 = tmax;
346 
347  return true;
348 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_InvDir
Definition: ray.h:75
unsigned int m_dirIsNeg[3]
Definition: ray.h:80
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
SFVEC3F m_Origin
Definition: ray.h:69
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

References RAY::m_dirIsNeg, RAY::m_InvDir, m_max, m_min, and RAY::m_Origin.

◆ Intersects()

bool CBBOX::Intersects ( const CBBOX aBBox) const

Function Intersects test if a bounding box intersects this box.

Parameters
aBBoxthe bounding box to check if it intersects

Definition at line 231 of file cbbox.cpp.

232 {
233  wxASSERT( IsInitialized() );
234  wxASSERT( aBBox.IsInitialized() );
235 
236  bool x = ( m_max.x >= aBBox.m_min.x ) && ( m_min.x <= aBBox.m_max.x );
237  bool y = ( m_max.y >= aBBox.m_min.y ) && ( m_min.y <= aBBox.m_max.y );
238  bool z = ( m_max.z >= aBBox.m_min.z ) && ( m_min.z <= aBBox.m_max.z );
239 
240  return ( x && y && z );
241 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References IsInitialized(), m_max, and m_min.

Referenced by CDUMMYBLOCK::Intersects(), CLAYERITEM::Intersects(), CROUNDSEG::Intersects(), CVCYLINDER::Intersects(), CXYPLANE::Intersects(), and CTRIANGLE::Intersects().

◆ IsInitialized()

bool CBBOX::IsInitialized ( ) const

Function IsInitialized check if this bounding box is already initialized.

Returns
bool - return true if it was initialized, false if otherwise

Definition at line 88 of file cbbox.cpp.

89 {
90  return !( ( FLT_MAX == m_min.x) ||
91  ( FLT_MAX == m_min.y) ||
92  ( FLT_MAX == m_min.z) ||
93  (-FLT_MAX == m_max.x) ||
94  (-FLT_MAX == m_max.y) ||
95  (-FLT_MAX == m_max.z) );
96 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by ApplyTransformation(), ApplyTransformationAA(), C_OGL_3DMODEL::C_OGL_3DMODEL(), Inside(), Intersects(), OGL_draw_bbox(), C3D_RENDER_RAYTRACING::Reload(), Scale(), Set(), Union(), and Volume().

◆ Max()

const SFVEC3F& CBBOX::Max ( ) const
inline

◆ MaxDimension()

unsigned int CBBOX::MaxDimension ( ) const

Function MaxDimension.

Returns
the index of the max dimention (0=x, 1=y, 2=z)

Definition at line 155 of file cbbox.cpp.

156 {
157  unsigned int result = 0;
158 
159  SFVEC3F extent = GetExtent();
160 
161  if( extent.y > extent.x )
162  result = 1;
163  if( extent.z > extent.y )
164  result = 2;
165 
166  return result;
167 }
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:149
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

References GetExtent().

Referenced by CBVH_PBRT::buildUpperSAH(), and CBVH_PBRT::recursiveBuild().

◆ Min()

const SFVEC3F& CBBOX::Min ( ) const
inline

◆ Offset()

SFVEC3F CBBOX::Offset ( const SFVEC3F p) const

Function Offset.

Returns
SFVEC3F - return the offset relative to max-min

Definition at line 264 of file cbbox.cpp.

265 {
266  return (p - m_min) / (m_max - m_min);
267 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by CBVH_PBRT::HLBVHBuild(), and CBVH_PBRT::recursiveBuild().

◆ Reset()

void CBBOX::Reset ( )

Function Reset reset the bounding box to zero and de-initialized it.

Definition at line 99 of file cbbox.cpp.

100 {
101  m_min = SFVEC3F( FLT_MAX, FLT_MAX, FLT_MAX );
102  m_max = SFVEC3F(-FLT_MAX,-FLT_MAX,-FLT_MAX );
103 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

References m_max, and m_min.

Referenced by ApplyTransformation(), BOARD_ADAPTER::BOARD_ADAPTER(), CBVH_PBRT::buildUpperSAH(), BVHPrimitiveInfo::BVHPrimitiveInfo(), CBBOX(), CBVH_PBRT::CBVH_PBRT(), CDUMMYBLOCK::CDUMMYBLOCK(), CGENERICACCELERATOR::CGENERICACCELERATOR(), CGENERICCONTAINER::CGENERICCONTAINER(), CLAYERITEM::CLAYERITEM(), CGENERICCONTAINER::Clear(), CROUNDSEG::CROUNDSEG(), CXYPLANE::CXYPLANE(), CBVH_PBRT::emitLBVH(), CBVH_PBRT::HLBVHBuild(), CTRIANGLE::pre_calc_const(), and CBVH_PBRT::recursiveBuild().

◆ Scale()

void CBBOX::Scale ( float  aScale)

Function Scale scales a bounding box by its center.

Parameters
aScalescale factor to apply

Definition at line 195 of file cbbox.cpp.

196 {
197  wxASSERT( IsInitialized() );
198 
199  SFVEC3F scaleV = SFVEC3F( aScale, aScale, aScale );
200  SFVEC3F centerV = GetCenter();
201 
202  m_min = (m_min - centerV) * scaleV + centerV;
203  m_max = (m_max - centerV) * scaleV + centerV;
204 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:136
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References GetCenter(), IsInitialized(), m_max, and m_min.

Referenced by CLAYERITEM::CLAYERITEM(), and C3D_RENDER_RAYTRACING::Reload().

◆ ScaleNextDown()

void CBBOX::ScaleNextDown ( )

Function ScaleNextDown scales a bounding box to the next float representation making it smaller.

Definition at line 219 of file cbbox.cpp.

220 {
221  m_min.x = NextFloatUp( m_min.x );
222  m_min.y = NextFloatUp( m_min.y );
223  m_min.z = NextFloatUp( m_min.z );
224 
225  m_max.x = NextFloatDown( m_max.x );
226  m_max.y = NextFloatDown( m_max.y );
227  m_max.z = NextFloatDown( m_max.z );
228 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136

References m_max, m_min, NextFloatDown(), and NextFloatUp().

◆ ScaleNextUp()

void CBBOX::ScaleNextUp ( )

Function ScaleNextUp scales a bounding box to the next float representation making it larger.

Definition at line 207 of file cbbox.cpp.

208 {
209  m_min.x = NextFloatDown( m_min.x );
210  m_min.y = NextFloatDown( m_min.y );
211  m_min.z = NextFloatDown( m_min.z );
212 
213  m_max.x = NextFloatUp( m_max.x );
214  m_max.y = NextFloatUp( m_max.y );
215  m_max.z = NextFloatUp( m_max.z );
216 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136

References m_max, m_min, NextFloatDown(), and NextFloatUp().

Referenced by CLAYERITEM::CLAYERITEM(), CROUNDSEG::CROUNDSEG(), CVCYLINDER::CVCYLINDER(), and CTRIANGLE::pre_calc_const().

◆ Set() [1/3]

void CBBOX::Set ( const SFVEC3F aPbMin,
const SFVEC3F aPbMax 
)

Function Set Set bounding box with new parameters.

Parameters
aPbMinthe minimun point to initialize the bounding box
aPbMaxthe maximun point to initialize the bounding box

Definition at line 68 of file cbbox.cpp.

69 {
70  m_min.x = fminf( aPbMin.x, aPbMax.x );
71  m_min.y = fminf( aPbMin.y, aPbMax.y );
72  m_min.z = fminf( aPbMin.z, aPbMax.z );
73 
74  m_max.x = fmaxf( aPbMin.x, aPbMax.x );
75  m_max.y = fmaxf( aPbMin.y, aPbMax.y );
76  m_max.z = fmaxf( aPbMin.z, aPbMax.z );
77 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by CBBOX(), CDUMMYBLOCK::CDUMMYBLOCK(), CLAYERITEM::CLAYERITEM(), CROUNDSEG::CROUNDSEG(), CVCYLINDER::CVCYLINDER(), CXYPLANE::CXYPLANE(), BVHBuildNode::InitInterior(), CTRIANGLE::pre_calc_const(), and Set().

◆ Set() [2/3]

void CBBOX::Set ( const CBBOX aBBox)

Definition at line 80 of file cbbox.cpp.

81 {
82  wxASSERT( aBBox.IsInitialized() );
83 
84  Set( aBBox.Min(), aBBox.Max() );
85 }
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:211
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:68
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:204
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References IsInitialized(), Max(), Min(), and Set().

◆ Set() [3/3]

void CBBOX::Set ( const SFVEC3F aPoint)

Set.

Parameters
aPbMin
aPbMax

Definition at line 61 of file cbbox.cpp.

62 {
63  m_min = aPoint;
64  m_max = aPoint;
65 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

◆ SurfaceArea()

float CBBOX::SurfaceArea ( ) const

Function SurfaceArea.

Returns
the surface are of the box

Definition at line 185 of file cbbox.cpp.

186 {
187  SFVEC3F extent = GetExtent();
188 
189  return 2.0f * ( extent.x * extent.z +
190  extent.x * extent.y +
191  extent.y * extent.z );
192 }
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:149
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47

References GetExtent().

Referenced by CBVH_PBRT::buildUpperSAH(), and CBVH_PBRT::recursiveBuild().

◆ Union() [1/2]

void CBBOX::Union ( const SFVEC3F aPoint)

Function Union recalculate the bounding box adding a point.

Parameters
aPointthe point to be bounded

Definition at line 106 of file cbbox.cpp.

107 {
108  // get the minimun value between the added point and the existent bounding box
109  m_min.x = fminf( m_min.x, aPoint.x );
110  m_min.y = fminf( m_min.y, aPoint.y );
111  m_min.z = fminf( m_min.z, aPoint.z );
112 
113  // get the maximun value between the added point and the existent bounding box
114  m_max.x = fmaxf( m_max.x, aPoint.x );
115  m_max.y = fmaxf( m_max.y, aPoint.y );
116  m_max.z = fmaxf( m_max.z, aPoint.z );
117 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255

References m_max, and m_min.

Referenced by CGENERICCONTAINER::Add(), ApplyTransformation(), ApplyTransformationAA(), CBVH_PBRT::buildUpperSAH(), C_OGL_3DMODEL::C_OGL_3DMODEL(), CBVH_PBRT::emitLBVH(), CBVH_PBRT::HLBVHBuild(), BVHBuildNode::InitInterior(), CTRIANGLE::pre_calc_const(), and CBVH_PBRT::recursiveBuild().

◆ Union() [2/2]

void CBBOX::Union ( const CBBOX aBBox)

Function Union recalculate the bounding box adding other bounding box.

Parameters
aBBoxthe bounding box to be bounded

Definition at line 120 of file cbbox.cpp.

121 {
122  wxASSERT( aBBox.IsInitialized() );
123 
124  // get the minimun value between the added bounding box and the existent bounding box
125  m_min.x = fmin( m_min.x, aBBox.m_min.x );
126  m_min.y = fmin( m_min.y, aBBox.m_min.y );
127  m_min.z = fmin( m_min.z, aBBox.m_min.z );
128 
129  // get the maximun value between the added bounding box and the existent bounding box
130  m_max.x = fmax( m_max.x, aBBox.m_max.x );
131  m_max.y = fmax( m_max.y, aBBox.m_max.y );
132  m_max.z = fmax( m_max.z, aBBox.m_max.z );
133 }
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: cbbox.h:254
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: cbbox.h:255
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References IsInitialized(), m_max, and m_min.

◆ Volume()

float CBBOX::Volume ( ) const

Function Volume calculate the volume of a bounding box.

Returns
float - volume of this bounding box

Definition at line 254 of file cbbox.cpp.

255 {
256  wxASSERT( IsInitialized() );
257 
258  SFVEC3F extent = GetExtent();
259 
260  return extent.x * extent.y * extent.z;
261 }
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:149
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:88

References GetExtent(), and IsInitialized().

Member Data Documentation

◆ m_max

SFVEC3F CBBOX::m_max
private

(12) point of the higher position of the bounding box

Definition at line 255 of file cbbox.h.

Referenced by ApplyTransformation(), ApplyTransformationAA(), CBBOX(), debug(), GetCenter(), GetExtent(), Inside(), Intersect(), Intersects(), IsInitialized(), Max(), Offset(), Reset(), Scale(), ScaleNextDown(), ScaleNextUp(), Set(), and Union().

◆ m_min

SFVEC3F CBBOX::m_min
private

(12) point of the lower position of the bounding box

Definition at line 254 of file cbbox.h.

Referenced by ApplyTransformation(), ApplyTransformationAA(), CBBOX(), debug(), GetCenter(), GetExtent(), Inside(), Intersect(), Intersects(), IsInitialized(), Min(), Offset(), Reset(), Scale(), ScaleNextDown(), ScaleNextUp(), Set(), and Union().


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