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 );
232 const float zNormalDir = hit_top?1.0f:hit_bot?-1.0f:0.0f;
234 if( ( outNormal.x == 0.0f ) && ( outNormal.y == 0.0f ) )
243 if( hit_top || hit_bot )
245 float zDistanceToTopOrBot;
250 zDistanceToTopOrBot = (
m_bbox.
Max().z - hitPoint.z );
254 zDistanceToTopOrBot = ( hitPoint.z -
m_bbox.
Min().z );
263 if( ( zDistanceToTopOrBot > 0.0f ) && ( zDistanceToTopOrBot < bevelThickness ) )
266 zBend = ( bevelThickness - zDistanceToTopOrBot ) / bevelThickness;
270 const SFVEC3F normalLateral =
SFVEC3F( outNormal.x, outNormal.y, 0.0f );
274 aHitInfo.
m_HitNormal = glm::mix( normalLateral, normalTopBot, zBend );
292 const SFVEC3F boxHitPointStart = aRay.
at( tBBoxStart );
293 const SFVEC3F boxHitPointEnd = aRay.
at( tBBoxEnd );
295 const SFVEC2F boxHitPointStart2D( boxHitPointStart.x, boxHitPointStart.y );
297 const SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
305 RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
310 if( tBBoxEnd < aHitInfo.
m_tHit )
312 aHitInfo.
m_tHit = tBBoxEnd;
316 if( aRay.
m_Dir.z > 0.0f )
333 const SFVEC3F hitPoint = boxHitPointStart +
334 ( boxHitPointEnd - boxHitPointStart ) * tOut;
336 const float t = glm::length( hitPoint - aRay.
m_Origin );
366 if( ( tBBoxStart > aMaxDistance ) || ( fabs( tBBoxStart - tBBoxEnd ) < FLT_EPSILON ) )
369 float tTop = FLT_MAX;
370 float tBot = FLT_MAX;
371 bool hit_top =
false;
372 bool hit_bot =
false;
374 if( (
float)fabs( aRay.
m_Dir.z ) > FLT_EPSILON )
379 const float tBBoxStartAdjusted =
NextFloatUp( tBBoxStart );
381 if( tBot > FLT_EPSILON )
383 hit_bot = tBot <= tBBoxStartAdjusted;
387 if( tTop > FLT_EPSILON )
389 hit_top = tTop <= tBBoxStartAdjusted;
408 if( hit_top && hit_bot )
414 if( tBot < aMaxDistance )
424 if( tTop < aMaxDistance )
439 if( tTop < aMaxDistance )
454 if( tBot < aMaxDistance )
470 SFVEC3F boxHitPointStart = aRay.
at( tBBoxStart );
471 SFVEC3F boxHitPointEnd = aRay.
at( tBBoxEnd );
473 SFVEC2F boxHitPointStart2D( boxHitPointStart.x, boxHitPointStart.y );
475 SFVEC2F boxHitPointEnd2D( boxHitPointEnd.x, boxHitPointEnd.y );
479 RAYSEG2D raySeg( boxHitPointStart2D, boxHitPointEnd2D );
488 const SFVEC3F hitPoint = boxHitPointStart +
489 ( boxHitPointEnd - boxHitPointStart ) * tOut;
490 const float t = glm::length( hitPoint - aRay.
m_Origin );
492 if( ( t < aMaxDistance ) && ( t > FLT_EPSILON ) )
Defines math related functions.
float NextFloatDown(float v)
float NextFloatUp(float v)
float g_BevelThickness3DU
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
bool Intersects(const BBOX_3D &aBBox) const override
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
const OBJECT_2D * m_object2d
LAYER_ITEM(const OBJECT_2D *aObject2D, float aZMin, float aZMax)
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
virtual bool Intersects(const BBOX_2D &aBBox) const =0
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
const SFVEC2F & GetCentroid() const
const BBOX_2D & GetBBox() const
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
const MATERIAL * m_material
double m_3DRT_BevelExtentFactor
3D-Viewer raytracing factor applied to Extent.z of the item layer.
float g_BevelThickness3DU
Manage a bounding box defined by two SFVEC2F min max points.
const SFVEC2F & Min() const
const SFVEC2F & Max() const
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Manage a bounding box defined by two SFVEC3F min max points.
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
const SFVEC3F GetExtent() const
bool Intersect(const RAY &aRay, float *t) const
const SFVEC3F & Min() const
Return the minimum vertex pointer.
const SFVEC3F & Max() const
Return the maximum vertex pointer.
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
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.
bool Inside(const SFVEC3F &aPoint) const
Check if a point is inside this bounding box.
void Scale(float aScale)
Scales a bounding box by its center.
Stores the hit information of a ray with a point on the surface of a object.
float m_tHit
( 4) distance
const OBJECT_3D * pHitObject
( 4) Object that was hitted
SFVEC3F m_HitNormal
(12) normal at the hit point
SFVEC3F m_HitPoint
(12) hit position
SFVEC3F at(float t) const