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

Method castRay

Engine/source/ts/tsMesh.cpp:632–774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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