KiCad PCB EDA Suite
BBOX_3D Struct Reference

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

#include <bbox_3d.h>

Public Member Functions

 BBOX_3D ()
 Create with default values a bounding box (not initialized) More...
 
 BBOX_3D (const SFVEC3F &aPbInit)
 Initialize a bounding box with a given point. More...
 
 BBOX_3D (const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
 Initialize a bounding box with a minimum and a maximum point. More...
 
 ~BBOX_3D ()
 
void Set (const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
 Set bounding box with new parameters. More...
 
void Set (const BBOX_3D &aBBox)
 
void Set (const SFVEC3F &aPoint)
 Set bounding box to one point. More...
 
void Union (const SFVEC3F &aPoint)
 Recalculate the bounding box adding a point. More...
 
void Union (const BBOX_3D &aBBox)
 Recalculate the bounding box adding other bounding box. More...
 
void Scale (float aScale)
 Scales a bounding box by its center. More...
 
void ScaleNextUp ()
 Scale a bounding box to the next float representation making it larger. More...
 
void ScaleNextDown ()
 Scale a bounding box to the next float representation making it smaller. More...
 
bool Intersects (const BBOX_3D &aBBox) const
 Test if a bounding box intersects this box. More...
 
bool Inside (const SFVEC3F &aPoint) const
 Check if a point is inside this bounding box. More...
 
void ApplyTransformation (glm::mat4 aTransformMatrix)
 Apply a transformation matrix to the box points. More...
 
void ApplyTransformationAA (glm::mat4 aTransformMatrix)
 Apply a transformation matrix to the box points and recalculate it to fit an axis aligned bounding box. More...
 
float Volume () const
 Calculate the volume of a bounding box. More...
 
void debug () const
 Output this BBOX_3D to the stdout. More...
 
bool IsInitialized () const
 Check if this bounding box is already initialized. More...
 
void Reset ()
 Reset the bounding box to zero and de-initialize it. More...
 
SFVEC3F GetCenter () const
 Return the center point of the bounding box. More...
 
float GetCenter (unsigned int aAxis) const
 Return the center point of the bounding box for one axis (0, 1 or 2). More...
 
SFVEC3F Offset (const SFVEC3F &p) const
 
const SFVEC3F GetExtent () const
 
const SFVEC3FMin () const
 Return the minimum vertex pointer. More...
 
const SFVEC3FMax () const
 Return the maximum vertex pointer. More...
 
unsigned int MaxDimension () const
 
float GetMaxDimension () const
 
float SurfaceArea () const
 
bool Intersect (const RAY &aRay, float *t) const
 
bool Intersect (const RAY &aRay) const
 
bool Intersect (const RAY &aRay, float *aOutHitt0, float *aOutHitt1) const
 Fetch the enter and exit position when a ray starts inside the bounding box. 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

Manage a bounding box defined by two SFVEC3F min max points.

Definition at line 41 of file bbox_3d.h.

Constructor & Destructor Documentation

◆ BBOX_3D() [1/3]

BBOX_3D::BBOX_3D ( )

Create with default values a bounding box (not initialized)

Definition at line 37 of file bbox_3d.cpp.

38 {
39  Reset();
40 }
void Reset()
Reset the bounding box to zero and de-initialize it.
Definition: bbox_3d.cpp:95

References Reset().

Referenced by ApplyTransformationAA().

◆ BBOX_3D() [2/3]

BBOX_3D::BBOX_3D ( const SFVEC3F aPbInit)
explicit

Initialize a bounding box with a given point.

Parameters
aPbInita point for the bounding box initialization.

Definition at line 43 of file bbox_3d.cpp.

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

References m_max, and m_min.

◆ BBOX_3D() [3/3]

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

Initialize a bounding box with a minimum and a maximum point.

Parameters
aPbMinthe minimum point to initialize the bounding box.
aPbMaxthe maximum point to initialize the bounding box.

Definition at line 50 of file bbox_3d.cpp.

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

References Set().

◆ ~BBOX_3D()

BBOX_3D::~BBOX_3D ( )

Definition at line 56 of file bbox_3d.cpp.

57 {
58 }

Member Function Documentation

◆ ApplyTransformation()

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

Apply a transformation matrix to the box points.

Parameters
aTransformMatrixmatrix to apply to the points of the bounding box

Definition at line 347 of file bbox_3d.cpp.

348 {
349  wxASSERT( IsInitialized() );
350 
351  const SFVEC3F v1 = SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) );
352 
353  const SFVEC3F v2 = SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) );
354 
355  Reset();
356  Union( v1 );
357  Union( v2 );
358 }
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
void Union(const SFVEC3F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_3d.cpp:102
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241
void Reset()
Reset the bounding box to zero and de-initialize it.
Definition: bbox_3d.cpp:95

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

◆ ApplyTransformationAA()

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

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 361 of file bbox_3d.cpp.

362 {
363  wxASSERT( IsInitialized() );
364 
365  // apply the transformation matrix for each of vertices of the bounding box
366  // and make a union with all vertices
367  BBOX_3D tmpBBox = BBOX_3D(
368  SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) ) );
369  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_min.y, m_min.z, 1.0f ) ) );
370  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_max.y, m_min.z, 1.0f ) ) );
371  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_max.z, 1.0f ) ) );
372  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_max.y, m_max.z, 1.0f ) ) );
373  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_min.z, 1.0f ) ) );
374  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_min.y, m_max.z, 1.0f ) ) );
375  tmpBBox.Union( SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) ) );
376 
377  m_min = tmpBBox.m_min;
378  m_max = tmpBBox.m_max;
379 }
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:41
void Union(const SFVEC3F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_3d.cpp:102
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
BBOX_3D()
Create with default values a bounding box (not initialized)
Definition: bbox_3d.cpp:37
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

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

◆ debug()

void BBOX_3D::debug ( ) const

Output this BBOX_3D to the stdout.

Definition at line 382 of file bbox_3d.cpp.

383 {
384  wxLogDebug( "min(%f, %f, %f) - max(%f, %f, %f)\n", m_min.x, m_min.y, m_min.z,
385  m_max.x, m_max.y, m_max.z );
386 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

◆ GetCenter() [1/2]

SFVEC3F BBOX_3D::GetCenter ( ) const

Return the center point of the bounding box.

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

Definition at line 132 of file bbox_3d.cpp.

133 {
134  return ( m_max + m_min ) * 0.5f;
135 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

Referenced by CYLINDER::CYLINDER(), DUMMY_BLOCK::DUMMY_BLOCK(), C3D_MODEL_VIEWER::OnPaint(), HLBVH_SAH_Evaluator::operator()(), TRIANGLE::pre_calc_const(), BVH_PBRT::recursiveBuild(), RENDER_3D_RAYTRACE::Reload(), ROUND_SEGMENT::ROUND_SEGMENT(), Scale(), and XY_PLANE::XY_PLANE().

◆ GetCenter() [2/2]

float BBOX_3D::GetCenter ( unsigned int  aAxis) const

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 138 of file bbox_3d.cpp.

139 {
140  wxASSERT( aAxis < 3 );
141  return ( m_max[aAxis] + m_min[aAxis] ) * 0.5f;
142 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

◆ GetExtent()

const SFVEC3F BBOX_3D::GetExtent ( ) const
Returns
SFVEC3F - max-min.

Definition at line 145 of file bbox_3d.cpp.

146 {
147  return m_max - m_min;
148 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

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

◆ GetMaxDimension()

float BBOX_3D::GetMaxDimension ( ) const
Returns
the max dimension.

Definition at line 167 of file bbox_3d.cpp.

168 {
169  unsigned int max_dimensions_idx = 0;
170 
171  SFVEC3F extent = GetExtent();
172 
173  if( extent.y > extent.x )
174  max_dimensions_idx = 1;
175 
176  if( extent.z > extent.y )
177  max_dimensions_idx = 2;
178 
179  return extent[max_dimensions_idx];
180 }
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References GetExtent().

Referenced by C3D_MODEL_VIEWER::OnPaint().

◆ Inside()

bool BBOX_3D::Inside ( const SFVEC3F aPoint) const

Check if a point is inside this bounding box.

Parameters
aPointpoint to test.

Definition at line 240 of file bbox_3d.cpp.

241 {
242  wxASSERT( IsInitialized() );
243 
244  return ( aPoint.x >= m_min.x ) && ( aPoint.x <= m_max.x ) &&
245  ( aPoint.y >= m_min.y ) && ( aPoint.y <= m_max.y ) &&
246  ( aPoint.z >= m_min.z ) && ( aPoint.z <= m_max.z );
247 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References IsInitialized(), m_max, and m_min.

Referenced by LAYER_ITEM::Intersect().

◆ Intersect() [1/3]

bool BBOX_3D::Intersect ( const RAY aRay,
float *  t 
) const
Parameters
aRayThe ray to intersect the box.
tThe distance point of the ray of the intersection (if true).
Returns
true if the ray hits the box.

Definition at line 46 of file bbox_3d_ray.cpp.

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

◆ Intersect() [2/3]

bool BBOX_3D::Intersect ( const RAY aRay) const

Definition at line 561 of file bbox_3d_ray.cpp.

562 {
563  switch( aRay.m_Classification )
564  {
566  {
567  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
568  || ( aRay.m_Origin.z < m_min.z )
569  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
570  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
571  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
572  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
573  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
574  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
575  return false;
576 
577  return true;
578  }
579 
581  {
582  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
583  || ( aRay.m_Origin.z > m_max.z )
584  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
585  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 )
586  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
587  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
588  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
589  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
590  return false;
591 
592  return true;
593  }
594 
596  {
597  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
598  || ( aRay.m_Origin.z < m_min.z )
599  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
600  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
601  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
602  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
603  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
604  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
605  return false;
606 
607  return true;
608  }
609 
611  {
612  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
613  || ( aRay.m_Origin.z > m_max.z )
614  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
615  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 )
616  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
617  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
618  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
619  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
620  return false;
621 
622  return true;
623  }
624 
626  {
627  if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
628  || ( aRay.m_Origin.z < m_min.z )
629  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
630  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
631  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
632  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 )
633  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
634  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
635  return false;
636 
637  return true;
638  }
639 
640 
642  {
643  if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
644  || ( aRay.m_Origin.z > m_max.z )
645  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
646  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 )
647  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
648  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 )
649  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
650  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
651  return false;
652 
653  return true;
654  }
655 
657  {
658  if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
659  || ( aRay.m_Origin.z < m_min.z )
660  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
661  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
662  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
663  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 )
664  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
665  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
666  return false;
667 
668  return true;
669  }
670 
672  {
673  if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
674  || ( aRay.m_Origin.z > m_max.z )
675  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
676  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 )
677  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
678  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 )
679  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
680  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
681  return false;
682 
683  return true;
684  }
685 
687  {
688  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
689  || ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z < m_min.z )
690  || ( aRay.jbyk * m_min.z - m_max.y + aRay.c_zy > 0 )
691  || ( aRay.kbyj * m_min.y - m_max.z + aRay.c_yz > 0 ) )
692  return false;
693 
694  return true;
695  }
696 
698  {
699  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
700  || ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.z > m_max.z )
701  || ( aRay.jbyk * m_max.z - m_max.y + aRay.c_zy > 0 )
702  || ( aRay.kbyj * m_min.y - m_min.z + aRay.c_yz < 0 ) )
703  return false;
704 
705  return true;
706  }
707 
709  {
710  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
711  || ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
712  || ( aRay.jbyk * m_min.z - m_min.y + aRay.c_zy < 0 )
713  || ( aRay.kbyj * m_max.y - m_max.z + aRay.c_yz > 0 ) )
714  return false;
715 
716  return true;
717  }
718 
720  {
721  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.x > m_max.x )
722  || ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z > m_max.z )
723  || ( aRay.jbyk * m_max.z - m_min.y + aRay.c_zy < 0 )
724  || ( aRay.kbyj * m_max.y - m_min.z + aRay.c_yz < 0 ) )
725  return false;
726 
727  return true;
728  }
729 
731  {
732  if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
733  || ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z < m_min.z )
734  || ( aRay.kbyi * m_min.x - m_max.z + aRay.c_xz > 0 )
735  || ( aRay.ibyk * m_min.z - m_max.x + aRay.c_zx > 0 ) )
736  return false;
737 
738  return true;
739  }
740 
742  {
743  if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
744  || ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.z > m_max.z )
745  || ( aRay.kbyi * m_min.x - m_min.z + aRay.c_xz < 0 )
746  || ( aRay.ibyk * m_max.z - m_max.x + aRay.c_zx > 0 ) )
747  return false;
748 
749  return true;
750  }
751 
753  {
754  if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
755  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
756  || ( aRay.kbyi * m_max.x - m_max.z + aRay.c_xz > 0 )
757  || ( aRay.ibyk * m_min.z - m_min.x + aRay.c_zx < 0 ) )
758  return false;
759 
760  return true;
761  }
762 
764  {
765  if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.y > m_max.y )
766  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z > m_max.z )
767  || ( aRay.kbyi * m_max.x - m_min.z + aRay.c_xz < 0 )
768  || ( aRay.ibyk * m_max.z - m_min.x + aRay.c_zx < 0 ) )
769  return false;
770 
771  return true;
772  }
773 
775  {
776  if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
777  || ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
778  || ( aRay.jbyi * m_min.x - m_max.y + aRay.c_xy > 0 )
779  || ( aRay.ibyj * m_min.y - m_max.x + aRay.c_yx > 0 ) )
780  return false;
781 
782  return true;
783  }
784 
786  {
787  if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
788  || ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y > m_max.y )
789  || ( aRay.jbyi * m_min.x - m_min.y + aRay.c_xy < 0 )
790  || ( aRay.ibyj * m_max.y - m_max.x + aRay.c_yx > 0 ) )
791  return false;
792 
793  return true;
794  }
795 
797  {
798  if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
799  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
800  || ( aRay.jbyi * m_max.x - m_max.y + aRay.c_xy > 0 )
801  || ( aRay.ibyj * m_min.y - m_min.x + aRay.c_yx < 0 ) )
802  return false;
803 
804  return true;
805  }
806 
808  {
809  if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.z > m_max.z )
810  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y > m_max.y )
811  || ( aRay.jbyi * m_max.x - m_min.y + aRay.c_xy < 0 )
812  || ( aRay.ibyj * m_max.y - m_min.x + aRay.c_yx < 0 ) )
813  return false;
814 
815  return true;
816  }
817 
819  {
820  if( ( aRay.m_Origin.x < m_min.x ) || ( aRay.m_Origin.y < m_min.y )
821  || ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
822  || ( aRay.m_Origin.z > m_max.z ) )
823  return false;
824 
825  return true;
826  }
827 
829  {
830  if( ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
831  || ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.z < m_min.z )
832  || ( aRay.m_Origin.z > m_max.z ) )
833  return false;
834 
835  return true;
836  }
837 
839  {
840  if( ( aRay.m_Origin.y < m_min.y ) || ( aRay.m_Origin.x < m_min.x )
841  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
842  || ( aRay.m_Origin.z > m_max.z ) )
843  return false;
844 
845  return true;
846  }
847 
849  {
850  if( ( aRay.m_Origin.y > m_max.y ) || ( aRay.m_Origin.x < m_min.x )
851  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.z < m_min.z )
852  || ( aRay.m_Origin.z > m_max.z ) )
853  return false;
854 
855  return true;
856  }
857 
859  {
860  if( ( aRay.m_Origin.z < m_min.z ) || ( aRay.m_Origin.x < m_min.x )
861  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
862  || ( aRay.m_Origin.y > m_max.y ) )
863  return false;
864 
865  return true;
866  }
867 
869  {
870  if( ( aRay.m_Origin.z > m_max.z ) || ( aRay.m_Origin.x < m_min.x )
871  || ( aRay.m_Origin.x > m_max.x ) || ( aRay.m_Origin.y < m_min.y )
872  || ( aRay.m_Origin.y > m_max.y ) )
873  return false;
874 
875  return true;
876  }
877  }
878 
879  return false;
880 }
float c_xy
Definition: ray.h:78
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_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
float kbyj
Definition: ray.h:77
RAY_CLASSIFICATION m_Classification
Definition: ray.h:73
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
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241
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 BBOX_3D::Intersect ( const RAY aRay,
float *  aOutHitt0,
float *  aOutHitt1 
) const

Fetch the enter and exit position when a ray starts inside the bounding box.

Parameters
aRayThe ray to intersect the box.
aOutHitt0The distance point of the ray of the intersection (if true).
aOutHitt1The distance point of the ray of the exit (if true).
Returns
true if the ray hits the box
Todo:
Why are we keeping both implementations of Intersect()?

Definition at line 308 of file bbox_3d.cpp.

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

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

◆ Intersects()

bool BBOX_3D::Intersects ( const BBOX_3D aBBox) const

Test if a bounding box intersects this box.

Parameters
aBBoxthe bounding box to check if it intersects.

Definition at line 227 of file bbox_3d.cpp.

228 {
229  wxASSERT( IsInitialized() );
230  wxASSERT( aBBox.IsInitialized() );
231 
232  bool x = ( m_max.x >= aBBox.m_min.x ) && ( m_min.x <= aBBox.m_max.x );
233  bool y = ( m_max.y >= aBBox.m_min.y ) && ( m_min.y <= aBBox.m_max.y );
234  bool z = ( m_max.z >= aBBox.m_min.z ) && ( m_min.z <= aBBox.m_max.z );
235 
236  return ( x && y && z );
237 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References IsInitialized(), m_max, and m_min.

Referenced by LAYER_ITEM::Intersects(), ROUND_SEGMENT::Intersects(), DUMMY_BLOCK::Intersects(), CYLINDER::Intersects(), XY_PLANE::Intersects(), and TRIANGLE::Intersects().

◆ IsInitialized()

bool BBOX_3D::IsInitialized ( ) const

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 bbox_3d.cpp.

89 {
90  return !( ( FLT_MAX == m_min.x ) || ( FLT_MAX == m_min.y ) || ( FLT_MAX == m_min.z )
91  || ( -FLT_MAX == m_max.x ) || ( -FLT_MAX == m_max.y ) || ( -FLT_MAX == m_max.z ) );
92 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

Referenced by ApplyTransformation(), ApplyTransformationAA(), DrawBoundingBox(), Inside(), Intersects(), MODEL_3D::MODEL_3D(), RENDER_3D_RAYTRACE::Reload(), Scale(), Set(), Union(), and Volume().

◆ Max()

const SFVEC3F& BBOX_3D::Max ( ) const
inline

◆ MaxDimension()

unsigned int BBOX_3D::MaxDimension ( ) const
Returns
the index of the max dimension (0=x, 1=y, 2=z).

Definition at line 151 of file bbox_3d.cpp.

152 {
153  unsigned int result = 0;
154 
155  SFVEC3F extent = GetExtent();
156 
157  if( extent.y > extent.x )
158  result = 1;
159 
160  if( extent.z > extent.y )
161  result = 2;
162 
163  return result;
164 }
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References GetExtent().

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

◆ Min()

const SFVEC3F& BBOX_3D::Min ( ) const
inline

◆ Offset()

SFVEC3F BBOX_3D::Offset ( const SFVEC3F p) const
Returns
SFVEC3F - return the offset relative to max-min.

Definition at line 260 of file bbox_3d.cpp.

261 {
262  return (p - m_min) / (m_max - m_min);
263 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

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

◆ Reset()

void BBOX_3D::Reset ( )

Reset the bounding box to zero and de-initialize it.

Definition at line 95 of file bbox_3d.cpp.

96 {
97  m_min = SFVEC3F( FLT_MAX, FLT_MAX, FLT_MAX );
98  m_max = SFVEC3F( -FLT_MAX, -FLT_MAX, -FLT_MAX );
99 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

Referenced by ACCELERATOR_3D::ACCELERATOR_3D(), ApplyTransformation(), BBOX_3D(), BOARD_ADAPTER::BOARD_ADAPTER(), BVH_PBRT::buildUpperSAH(), BVH_PBRT::BVH_PBRT(), BVHPrimitiveInfo::BVHPrimitiveInfo(), CONTAINER_3D_BASE::Clear(), CONTAINER_3D_BASE::CONTAINER_3D_BASE(), DUMMY_BLOCK::DUMMY_BLOCK(), BVH_PBRT::emitLBVH(), BVH_PBRT::HLBVHBuild(), LAYER_ITEM::LAYER_ITEM(), TRIANGLE::pre_calc_const(), BVH_PBRT::recursiveBuild(), ROUND_SEGMENT::ROUND_SEGMENT(), and XY_PLANE::XY_PLANE().

◆ Scale()

void BBOX_3D::Scale ( float  aScale)

Scales a bounding box by its center.

Parameters
aScalescale factor to apply.

Definition at line 191 of file bbox_3d.cpp.

192 {
193  wxASSERT( IsInitialized() );
194 
195  SFVEC3F scaleV = SFVEC3F( aScale, aScale, aScale );
196  SFVEC3F centerV = GetCenter();
197 
198  m_min = ( m_min - centerV ) * scaleV + centerV;
199  m_max = ( m_max - centerV ) * scaleV + centerV;
200 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition: bbox_3d.cpp:132
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

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

Referenced by LAYER_ITEM::LAYER_ITEM(), and RENDER_3D_RAYTRACE::Reload().

◆ ScaleNextDown()

void BBOX_3D::ScaleNextDown ( )

Scale a bounding box to the next float representation making it smaller.

Definition at line 215 of file bbox_3d.cpp.

216 {
217  m_min.x = NextFloatUp( m_min.x );
218  m_min.y = NextFloatUp( m_min.y );
219  m_min.z = NextFloatUp( m_min.z );
220 
221  m_max.x = NextFloatDown( m_max.x );
222  m_max.y = NextFloatDown( m_max.y );
223  m_max.z = NextFloatDown( m_max.z );
224 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

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

◆ ScaleNextUp()

void BBOX_3D::ScaleNextUp ( )

Scale a bounding box to the next float representation making it larger.

Definition at line 203 of file bbox_3d.cpp.

204 {
205  m_min.x = NextFloatDown( m_min.x );
206  m_min.y = NextFloatDown( m_min.y );
207  m_min.z = NextFloatDown( m_min.z );
208 
209  m_max.x = NextFloatUp( m_max.x );
210  m_max.y = NextFloatUp( m_max.y );
211  m_max.z = NextFloatUp( m_max.z );
212 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

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

Referenced by CYLINDER::CYLINDER(), LAYER_ITEM::LAYER_ITEM(), TRIANGLE::pre_calc_const(), and ROUND_SEGMENT::ROUND_SEGMENT().

◆ Set() [1/3]

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

Set bounding box with new parameters.

Parameters
aPbMinthe minimum point to set for the bounding box.
aPbMaxthe maximum point to set for the bounding box.

Definition at line 68 of file bbox_3d.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_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

Referenced by BBOX_3D(), CYLINDER::CYLINDER(), DUMMY_BLOCK::DUMMY_BLOCK(), BVHBuildNode::InitInterior(), LAYER_ITEM::LAYER_ITEM(), TRIANGLE::pre_calc_const(), ROUND_SEGMENT::ROUND_SEGMENT(), Set(), and XY_PLANE::XY_PLANE().

◆ Set() [2/3]

void BBOX_3D::Set ( const BBOX_3D aBBox)

Definition at line 80 of file bbox_3d.cpp.

81 {
82  wxASSERT( aBBox.IsInitialized() );
83 
84  Set( aBBox.Min(), aBBox.Max() );
85 }
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition: bbox_3d.h:203
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition: bbox_3d.h:196
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_3d.cpp:68

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

◆ Set() [3/3]

void BBOX_3D::Set ( const SFVEC3F aPoint)

Set bounding box to one point.

Parameters
aPointthe single point to set the bounding box to.

Definition at line 61 of file bbox_3d.cpp.

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

References m_max, and m_min.

◆ SurfaceArea()

float BBOX_3D::SurfaceArea ( ) const
Returns
the surface area of the box.

Definition at line 183 of file bbox_3d.cpp.

184 {
185  SFVEC3F extent = GetExtent();
186 
187  return 2.0f * ( extent.x * extent.z + extent.x * extent.y + extent.y * extent.z );
188 }
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References GetExtent().

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

◆ Union() [1/2]

void BBOX_3D::Union ( const SFVEC3F aPoint)

Recalculate the bounding box adding a point.

Parameters
aPointthe point to be bounded.

Definition at line 102 of file bbox_3d.cpp.

103 {
104  // get the minimum value between the added point and the existent bounding box
105  m_min.x = fminf( m_min.x, aPoint.x );
106  m_min.y = fminf( m_min.y, aPoint.y );
107  m_min.z = fminf( m_min.z, aPoint.z );
108 
109  // get the maximum value between the added point and the existent bounding box
110  m_max.x = fmaxf( m_max.x, aPoint.x );
111  m_max.y = fmaxf( m_max.y, aPoint.y );
112  m_max.z = fmaxf( m_max.z, aPoint.z );
113 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References m_max, and m_min.

Referenced by CONTAINER_3D_BASE::Add(), ApplyTransformation(), ApplyTransformationAA(), BVH_PBRT::buildUpperSAH(), BVH_PBRT::emitLBVH(), BVH_PBRT::HLBVHBuild(), BVHBuildNode::InitInterior(), MODEL_3D::MODEL_3D(), TRIANGLE::pre_calc_const(), and BVH_PBRT::recursiveBuild().

◆ Union() [2/2]

void BBOX_3D::Union ( const BBOX_3D aBBox)

Recalculate the bounding box adding other bounding box.

Parameters
aBBoxthe bounding box to be bounded.

Definition at line 116 of file bbox_3d.cpp.

117 {
118  wxASSERT( aBBox.IsInitialized() );
119 
120  // get the minimum value between the added bounding box and the existent bounding box
121  m_min.x = fmin( m_min.x, aBBox.m_min.x );
122  m_min.y = fmin( m_min.y, aBBox.m_min.y );
123  m_min.z = fmin( m_min.z, aBBox.m_min.z );
124 
125  // get the maximum value between the added bounding box and the existent bounding box
126  m_max.x = fmax( m_max.x, aBBox.m_max.x );
127  m_max.y = fmax( m_max.y, aBBox.m_max.y );
128  m_max.z = fmax( m_max.z, aBBox.m_max.z );
129 }
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:242
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
SFVEC3F m_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:241

References IsInitialized(), m_max, and m_min.

◆ Volume()

float BBOX_3D::Volume ( ) const

Calculate the volume of a bounding box.

Returns
float - volume of this bounding box.

Definition at line 250 of file bbox_3d.cpp.

251 {
252  wxASSERT( IsInitialized() );
253 
254  SFVEC3F extent = GetExtent();
255 
256  return extent.x * extent.y * extent.z;
257 }
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References GetExtent(), and IsInitialized().

Member Data Documentation

◆ m_max

SFVEC3F BBOX_3D::m_max
private

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

Definition at line 242 of file bbox_3d.h.

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

◆ m_min

SFVEC3F BBOX_3D::m_min
private

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

Definition at line 241 of file bbox_3d.h.

Referenced by ApplyTransformation(), ApplyTransformationAA(), BBOX_3D(), 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: