MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / castRay

Method castRay

Engine/source/ts/tsMesh.cpp:630–772  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628}
629
630bool TSMesh::castRay( S32 frame, const Point3F & start, const Point3F & end, RayInfo * rayInfo, TSMaterialList* materials )
631{
632 if ( mPlaneNormals.empty() )
633 buildConvexHull(); // if haven't done it yet...
634
635 // Keep track of startTime and endTime. They start out at just under 0 and just over 1, respectively.
636 // As we check against each plane, prune start and end times back to represent current intersection of
637 // line with all the planes (or rather with all the half-spaces defined by the planes).
638 // But, instead of explicitly keeping track of startTime and endTime, keep track as numerator and denominator
639 // so that we can avoid as many divisions as possible.
640
641 // F32 startTime = -0.01f;
642 F32 startNum = -0.01f;
643 F32 startDen = 1.00f;
644 // F32 endTime = 1.01f;
645 F32 endNum = 1.01f;
646 F32 endDen = 1.00f;
647
648 S32 curPlane = 0;
649 U32 curMaterial = 0;
650 bool found = false;
651
652 // the following block of code is an optimization...
653 // it isn't necessary if the longer version of the main loop is used
654 bool tmpFound;
655 S32 tmpPlane;
656 F32 sgn = -1.0f;
657 F32 * pnum = &startNum;
658 F32 * pden = &startDen;
659 S32 * pplane = &curPlane;
660 bool * pfound = &found;
661
662 S32 startPlane = frame * mPlanesPerFrame;
663 for ( S32 i = startPlane; i < startPlane + mPlanesPerFrame; i++ )
664 {
665 // if start & end outside, no collision
666 // if start & end inside, continue
667 // if start outside, end inside, or visa versa, find intersection of line with plane
668 // then update intersection of line with hull (using startTime and endTime)
669 F32 dot1 = mDot(mPlaneNormals[i], start ) - mPlaneConstants[i];
670 F32 dot2 = mDot(mPlaneNormals[i], end) - mPlaneConstants[i];
671 if ( dot1 * dot2 > 0.0f )
672 {
673 // same side of the plane...which side -- dot==0 considered inside
674 if ( dot1 > 0.0f )
675 return false; // start and end outside of this plane, no collision
676
677 // start and end inside plane, continue
678 continue;
679 }
680
681 //AssertFatal( dot1 / ( dot1 - dot2 ) >= 0.0f && dot1 / ( dot1 - dot2 ) <= 1.0f,"TSMesh::castRay (1)" );
682
683 // find intersection (time) with this plane...
684 // F32 time = dot1 / (dot1-dot2);
685 F32 num = mFabs( dot1 );
686 F32 den = mFabs( dot1 - dot2 );
687

Callers 14

lightVectorMethod · 0.45
onRightMouseDownMethod · 0.45
_cursorCastMethod · 0.45
on3DMouseDownMethod · 0.45
_renderOutlineMethod · 0.45
collideMethod · 0.45
dropBelowSelectionMethod · 0.45
terrainSnapSelectionMethod · 0.45
visitNextMethod · 0.45
testEdgeCoverMethod · 0.45
get3DCentreMethod · 0.45
on3DMouseDownMethod · 0.45

Calls 6

mFabsFunction · 0.85
getMaterialInstMethod · 0.80
setContactPointMethod · 0.80
mDotFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected