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...
 
bool Inside (const BBOX_3D &aBBox) const
 Check if a bounding box is inside this bounding box. More...
 
void ApplyTransformation (glm::mat4 aTransformMatrix)
 Apply a transformation matrix to the box points. More...
 
float Volume () const
 Calculate the volume of a bounding box. 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().

◆ 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_min
(12) point of the lower position of the bounding box
Definition: bbox_3d.h:236
SFVEC3F m_max
(12) point of the higher position of the bounding box
Definition: bbox_3d.h:237

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

307{
308 wxASSERT( IsInitialized() );
309
310 const SFVEC3F v1 = SFVEC3F( aTransformMatrix * glm::vec4( m_min.x, m_min.y, m_min.z, 1.0f ) );
311
312 const SFVEC3F v2 = SFVEC3F( aTransformMatrix * glm::vec4( m_max.x, m_max.y, m_max.z, 1.0f ) );
313
314 Reset();
315 Union( v1 );
316 Union( v2 );
317}
void Union(const SFVEC3F &aPoint)
Recalculate the bounding box adding a point.
Definition: bbox_3d.cpp:102
bool IsInitialized() const
Check if this bounding box is already initialized.
Definition: bbox_3d.cpp:88
VECTOR3I v1(5, 5, 5)
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

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

◆ 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}

References m_max, and m_min.

Referenced by CYLINDER::CYLINDER(), MODEL_3D::Draw(), DUMMY_BLOCK::DUMMY_BLOCK(), EDA_3D_MODEL_VIEWER::OnPaint(), HLBVH_SAH_Evaluator::operator()(), TRIANGLE::pre_calc_const(), BVH_PBRT::recursiveBuild(), RENDER_3D_RAYTRACE::Reload(), RENDER_3D_OPENGL::renderTransparentModels(), 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}

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}

References m_max, and m_min.

Referenced by GetMaxDimension(), LAYER_ITEM::Intersect(), 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 SFVEC3F extent = GetExtent();
170 return std::max( std::max( extent.x, extent.y ), extent.z );
171}
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145

References GetExtent().

Referenced by EDA_3D_MODEL_VIEWER::OnPaint(), and RENDER_3D_RAYTRACE::Reload().

◆ Inside() [1/2]

bool BBOX_3D::Inside ( const BBOX_3D aBBox) const

Check if a bounding box is inside this bounding box.

Parameters
aBBoxthe bounding box to test if it is inside
Returns
true if aBBox is smaller and all points are inside

Definition at line 241 of file bbox_3d.cpp.

242{
243 wxASSERT( IsInitialized() );
244 wxASSERT( aBBox.IsInitialized() );
245
246 return Inside( aBBox.Min() ) &&
247 Inside( aBBox.Max() );
248}
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition: bbox_3d.h:191
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition: bbox_3d.h:198
bool Inside(const SFVEC3F &aPoint) const
Check if a point is inside this bounding box.
Definition: bbox_3d.cpp:231

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

◆ Inside() [2/2]

bool BBOX_3D::Inside ( const SFVEC3F aPoint) const

Check if a point is inside this bounding box.

Parameters
aPointpoint to test.

Definition at line 231 of file bbox_3d.cpp.

232{
233 wxASSERT( IsInitialized() );
234
235 return ( aPoint.x >= m_min.x ) && ( aPoint.x <= m_max.x ) &&
236 ( aPoint.y >= m_min.y ) && ( aPoint.y <= m_max.y ) &&
237 ( aPoint.z >= m_min.z ) && ( aPoint.z <= m_max.z );
238}

References IsInitialized(), m_max, and m_min.

Referenced by Inside(), and LAYER_ITEM::Intersect().

◆ Intersect() [1/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 ibyj
Definition: ray.h:72
float c_zx
Definition: ray.h:73
float jbyk
Definition: ray.h:72
RAY_CLASSIFICATION m_Classification
Definition: ray.h:68
float jbyi
Definition: ray.h:72
float c_xz
Definition: ray.h:73
float c_xy
Definition: ray.h:73
float c_yz
Definition: ray.h:73
float kbyi
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:64
float ibyk
Definition: ray.h:72
float c_yx
Definition: ray.h:73
float c_zy
Definition: ray.h:73
float kbyj
Definition: ray.h:72

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() [2/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

Definition at line 268 of file bbox_3d.cpp.

269{
270 wxASSERT( aOutHitt0 );
271 wxASSERT( aOutHitt1 );
272
273 const SFVEC3F bounds[2] = {m_min, m_max};
274
275 // Check for ray intersection against x and y slabs
276 float tmin = ( bounds[aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
277 float tmax = ( bounds[1 - aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x ) * aRay.m_InvDir.x;
278 const float tymin = ( bounds[aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
279 const float tymax = ( bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y ) * aRay.m_InvDir.y;
280
281 if( ( tmin > tymax ) || ( tymin > tmax ) )
282 return false;
283
284 tmin = ( tymin > tmin ) ? tymin : tmin;
285 tmax = ( tymax < tmax ) ? tymax : tmax;
286
287 // Check for ray intersection against z slab
288 const float tzmin = ( bounds[aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
289 const float tzmax = ( bounds[1 - aRay.m_dirIsNeg[2]].z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
290
291 if( ( tmin > tzmax ) || ( tzmin > tmax ) )
292 return false;
293
294 tmin = (tzmin > tmin)? tzmin : tmin;
295 tmin = ( tmin < 0.0f)? 0.0f : tmin;
296
297 tmax = (tzmax < tmax)? tzmax : tmax;
298
299 *aOutHitt0 = tmin;
300 *aOutHitt1 = tmax;
301
302 return true;
303}
unsigned int m_dirIsNeg[3]
Definition: ray.h:75
SFVEC3F m_InvDir
Definition: ray.h:70

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

◆ Intersect() [3/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}

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(), NL_3D_VIEWER_PLUGIN_IMPL::GetHitLookAt(), getLastHit(), BVH_PBRT::Intersect(), CONTAINER_3D::Intersect(), DUMMY_BLOCK::Intersect(), LAYER_ITEM::Intersect(), BVH_PBRT::IntersectP(), DUMMY_BLOCK::IntersectP(), LAYER_ITEM::IntersectP(), and EDA_3D_CANVAS::move_pivot_based_on_cur_mouse_position().

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

219{
220 wxASSERT( IsInitialized() );
221 wxASSERT( aBBox.IsInitialized() );
222
223 bool x = ( m_max.x >= aBBox.m_min.x ) && ( m_min.x <= aBBox.m_max.x );
224 bool y = ( m_max.y >= aBBox.m_min.y ) && ( m_min.y <= aBBox.m_max.y );
225 bool z = ( m_max.z >= aBBox.m_min.z ) && ( m_min.z <= aBBox.m_max.z );
226
227 return ( x && y && z );
228}

References IsInitialized(), m_max, and m_min.

Referenced by CYLINDER::Intersects(), DUMMY_BLOCK::Intersects(), LAYER_ITEM::Intersects(), XY_PLANE::Intersects(), ROUND_SEGMENT::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}

References m_max, and m_min.

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

◆ Max()

◆ 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}

References GetExtent().

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

◆ Min()

◆ Offset()

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

Definition at line 261 of file bbox_3d.cpp.

262{
263 return (p - m_min) / (m_max - m_min);
264}

References m_max, and m_min.

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

◆ Reset()

◆ Scale()

void BBOX_3D::Scale ( float  aScale)

Scales a bounding box by its center.

Parameters
aScalescale factor to apply.

Definition at line 182 of file bbox_3d.cpp.

183{
184 wxASSERT( IsInitialized() );
185
186 SFVEC3F scaleV = SFVEC3F( aScale, aScale, aScale );
187 SFVEC3F centerV = GetCenter();
188
189 m_min = ( m_min - centerV ) * scaleV + centerV;
190 m_max = ( m_max - centerV ) * scaleV + centerV;
191}
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition: bbox_3d.cpp:132

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

207{
208 m_min.x = NextFloatUp( m_min.x );
209 m_min.y = NextFloatUp( m_min.y );
210 m_min.z = NextFloatUp( m_min.z );
211
212 m_max.x = NextFloatDown( m_max.x );
213 m_max.y = NextFloatDown( m_max.y );
214 m_max.z = NextFloatDown( m_max.z );
215}
float NextFloatDown(float v)
Definition: 3d_fastmath.h:157
float NextFloatUp(float v)
Definition: 3d_fastmath.h:136

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

195{
196 m_min.x = NextFloatDown( m_min.x );
197 m_min.y = NextFloatDown( m_min.y );
198 m_min.z = NextFloatDown( m_min.z );
199
200 m_max.x = NextFloatUp( m_max.x );
201 m_max.y = NextFloatUp( m_max.y );
202 m_max.z = NextFloatUp( m_max.z );
203}

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 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}

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

◆ Set() [2/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}

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() [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}

References m_max, and m_min.

◆ SurfaceArea()

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

Definition at line 174 of file bbox_3d.cpp.

175{
176 SFVEC3F extent = GetExtent();
177
178 return 2.0f * ( extent.x * extent.z + extent.x * extent.y + extent.y * extent.z );
179}

References GetExtent().

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

◆ Union() [1/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}

References IsInitialized(), m_max, and m_min.

◆ Union() [2/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}

References m_max, and m_min.

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

◆ Volume()

float BBOX_3D::Volume ( ) const

Calculate the volume of a bounding box.

Returns
float - volume of this bounding box.

Definition at line 251 of file bbox_3d.cpp.

252{
253 wxASSERT( IsInitialized() );
254
255 SFVEC3F extent = GetExtent();
256
257 return extent.x * extent.y * extent.z;
258}

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 237 of file bbox_3d.h.

Referenced by ApplyTransformation(), BBOX_3D(), 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 236 of file bbox_3d.h.

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