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

Method castRay

Engine/source/environment/river.cpp:1204–1294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1202}
1203
1204bool River::castRay(const Point3F &s, const Point3F &e, RayInfo* info)
1205{
1206 Point3F start = s;
1207 Point3F end = e;
1208 mObjToWorld.mulP(start);
1209 mObjToWorld.mulP(end);
1210
1211 F32 out = 1.0f; // The output fraction/percentage along the line defined by s and e
1212 VectorF norm(0.0f, 0.0f, 0.0f); // The normal of the face intersected
1213
1214 Vector<RiverHitSegment> hitSegments;
1215
1216 for ( U32 i = 0; i < mSegments.size(); i++ )
1217 {
1218 const RiverSegment &segment = mSegments[i];
1219
1220 F32 t;
1221 VectorF n;
1222
1223 if ( segment.worldbounds.collideLine( start, end, &t, &n ) )
1224 {
1225 hitSegments.increment();
1226 hitSegments.last().t = t;
1227 hitSegments.last().idx = i;
1228 }
1229 }
1230
1231 dQsort( hitSegments.address(), hitSegments.size(), sizeof(RiverHitSegment), compareHitSegments );
1232
1233 U32 idx0, idx1, idx2;
1234 F32 t;
1235
1236 for ( U32 i = 0; i < hitSegments.size(); i++ )
1237 {
1238 U32 segIdx = hitSegments[i].idx;
1239 const RiverSegment &segment = mSegments[segIdx];
1240
1241 // Each segment has 6 faces
1242 for ( U32 j = 0; j < 6; j++ )
1243 {
1244 if ( j == 4 && segIdx != 0 )
1245 continue;
1246
1247 if ( j == 5 && segIdx != mSegments.size() - 1 )
1248 continue;
1249
1250 // Each face has 2 triangles
1251 for ( U32 k = 0; k < 2; k++ )
1252 {
1253 idx0 = gIdxArray[j][k][0];
1254 idx1 = gIdxArray[j][k][1];
1255 idx2 = gIdxArray[j][k][2];
1256
1257 const Point3F &v0 = segment[idx0];
1258 const Point3F &v1 = segment[idx1];
1259 const Point3F &v2 = segment[idx2];
1260
1261 if ( !MathUtils::mLineTriangleCollide( start, end,

Callers 9

_getTerrainHeightMethod · 0.45
_process3DMouseDownMethod · 0.45
on3DMouseMoveMethod · 0.45
getStaticPosMethod · 0.45
on3DMouseMoveMethod · 0.45
getTerrainPosMethod · 0.45
on3DMouseDownMethod · 0.45
on3DMouseMoveMethod · 0.45
getStaticPosMethod · 0.45

Calls 10

dQsortFunction · 0.85
mLineTriangleCollideFunction · 0.85
mulPMethod · 0.80
collideLineMethod · 0.80
incrementMethod · 0.80
PlaneFClass · 0.50
sizeMethod · 0.45
lastMethod · 0.45
addressMethod · 0.45
interpolateMethod · 0.45

Tested by

no test coverage detected