36 m_object2d( aObject2D )
38 wxASSERT( aObject2D );
51 ( aZMax + aZMin ) * 0.5f );
63 if( tBBoxStart >= aHitInfo.
m_tHit )
66 if( fabs( tBBoxStart - tBBoxEnd ) <= FLT_EPSILON )
78 if( (
float) fabs( aRay.
m_Dir.z ) > FLT_EPSILON )
83 float tBBoxStartAdjusted =
NextFloatUp( tBBoxStart );
85 if( tBot > FLT_EPSILON )
87 hit_bot = tBot <= tBBoxStartAdjusted;
91 if( tTop > FLT_EPSILON )
93 hit_top = tTop <= tBBoxStartAdjusted;
109 if( hit_top && hit_bot )
115 if( tBot < aHitInfo.
m_tHit )
134 if( tTop < aHitInfo.
m_tHit )
158 if( tTop < aHitInfo.
m_tHit )
182 if( tBot < aHitInfo.
m_tHit )
207 SFVEC3F boxHitPointStart = aRay.
at( tBBoxStart );
208 SFVEC3F boxHitPointEnd = aRay.
at( tBBoxEnd );
210 SFVEC2F boxHitPointStart2D( boxHitPointStart.x, boxHitPointStart.y );
211 SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
215 RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
222 SFVEC3F hitPoint = boxHitPointStart + ( boxHitPointEnd - boxHitPointStart ) * tOut;
224 const float t = glm::length( hitPoint - aRay.
m_Origin );
231 if( ( outNormal.x == 0.0f ) && ( outNormal.y == 0.0f ) )
257 const SFVEC3F boxHitPointStart = aRay.
at( tBBoxStart );
258 const SFVEC3F boxHitPointEnd = aRay.
at( tBBoxEnd );
260 const SFVEC2F boxHitPointStart2D( boxHitPointStart.x, boxHitPointStart.y );
262 const SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
270 RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
275 if( tBBoxEnd < aHitInfo.
m_tHit )
277 aHitInfo.
m_tHit = tBBoxEnd;
281 if( aRay.
m_Dir.z > 0.0f )
298 const SFVEC3F hitPoint = boxHitPointStart +
299 ( boxHitPointEnd - boxHitPointStart ) * tOut;
301 const float t = glm::length( hitPoint - aRay.
m_Origin );
331 if( ( tBBoxStart > aMaxDistance ) || ( fabs( tBBoxStart - tBBoxEnd ) < FLT_EPSILON ) )
334 float tTop = FLT_MAX;
335 float tBot = FLT_MAX;
336 bool hit_top =
false;
337 bool hit_bot =
false;
339 if( (
float)fabs( aRay.
m_Dir.z ) > FLT_EPSILON )
344 const float tBBoxStartAdjusted =
NextFloatUp( tBBoxStart );
346 if( tBot > FLT_EPSILON )
348 hit_bot = tBot <= tBBoxStartAdjusted;
352 if( tTop > FLT_EPSILON )
354 hit_top = tTop <= tBBoxStartAdjusted;
373 if( hit_top && hit_bot )
379 if( tBot < aMaxDistance )
389 if( tTop < aMaxDistance )
404 if( tTop < aMaxDistance )
419 if( tBot < aMaxDistance )
435 SFVEC3F boxHitPointStart = aRay.
at( tBBoxStart );
436 SFVEC3F boxHitPointEnd = aRay.
at( tBBoxEnd );
438 SFVEC2F boxHitPointStart2D( boxHitPointStart.x, boxHitPointStart.y );
440 SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
444 RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
453 const SFVEC3F hitPoint = boxHitPointStart +
454 ( boxHitPointEnd - boxHitPointStart ) * tOut;
455 const float t = glm::length( hitPoint - aRay.
m_Origin );
457 if( ( t < aMaxDistance ) && ( t > FLT_EPSILON ) )
Defines math related functions.
const SFVEC3F & Max() const
Return the maximum vertex pointer.
const SFVEC2F & GetCentroid() const
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
Manage a bounding box defined by two SFVEC3F min max points.
bool Intersect(const RAY &aRay, float *t) const
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
float m_tHit
( 4) distance
SFVEC3F at(float t) const
bool Inside(const SFVEC3F &aPoint) const
Check if a point is inside this bounding box.
const SFVEC3F & Min() const
Return the minimum vertex pointer.
SFVEC3F m_HitPoint
(12) hit position
const SFVEC2F & Max() const
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
void Scale(float aScale)
Scales a bounding box by its center.
float NextFloatDown(float v)
const BBOX_2D & GetBBox() const
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
Manage a bounding box defined by two SFVEC2F min max points.
const MATERIAL * m_material
const OBJECT_3D * pHitObject
( 4) Object that was hitted
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
const SFVEC2F & Min() const
LAYER_ITEM(const OBJECT_2D *aObject2D, float aZMin, float aZMax)
bool Intersects(const BBOX_3D &aBBox) const override
Stores the hit information of a ray with a point on the surface of a object.
float NextFloatUp(float v)
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
SFVEC3F m_HitNormal
(12) normal at the hit point
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
const OBJECT_2D * m_object2d
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
virtual bool Intersects(const BBOX_2D &aBBox) const =0
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
void Reset()
Reset the bounding box to zero and de-initialize it.
bool Intersects(const BBOX_3D &aBBox) const
Test if a bounding box intersects this box.