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

Method createSplit

Engine/source/T3D/fx/lightning.cpp:1255–1293  ·  view source on GitHub ↗

---------------------------------------------------------------------------- Recursive algo to create bolts that split off from main bolt ----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1253// Recursive algo to create bolts that split off from main bolt
1254//----------------------------------------------------------------------------
1255void LightningBolt::createSplit( const Point3F &startingPoint, const Point3F &endingPoint, U32 depth, F32 splitWidth )
1256{
1257 if( depth == 0 )
1258 return;
1259
1260 F32 chanceToEnd = gRandGen.randF();
1261 if( chanceToEnd > 0.70f )
1262 return;
1263
1264 if(splitWidth < 0.75f )
1265 splitWidth = 0.75f;
1266
1267 VectorF diff = endingPoint - startingPoint;
1268 F32 length = diff.len();
1269 diff.normalizeSafe();
1270
1271 LightningBolt newBolt;
1272 newBolt.startPoint = startingPoint;
1273 newBolt.endPoint = endingPoint;
1274 newBolt.width = splitWidth;
1275 newBolt.numMajorNodes = 3;
1276 newBolt.maxMajorAngle = 30.0f;
1277 newBolt.numMinorNodes = 3;
1278 newBolt.maxMinorAngle = 10.0f;
1279 newBolt.startRender = true;
1280 newBolt.generate();
1281
1282 splitList.pushBack( newBolt );
1283
1284 VectorF newDir1 = MathUtils::randomDir( diff, 10.0f, 45.0f );
1285 Point3F newEndPoint1 = endingPoint + newDir1 * gRandGen.randF( 0.5f, 1.5f ) * length;
1286
1287 VectorF newDir2 = MathUtils::randomDir( diff, 10.0f, 45.0f );
1288 Point3F newEndPoint2 = endingPoint + newDir2 * gRandGen.randF( 0.5f, 1.5f ) * length;
1289
1290 createSplit(endingPoint, newEndPoint1, depth - 1, splitWidth * 0.30f );
1291 createSplit(endingPoint, newEndPoint2, depth - 1, splitWidth * 0.30f );
1292
1293}
1294
1295//----------------------------------------------------------------------------
1296// Start split - kick off the recursive 'createSplit' procedure

Callers

nothing calls this directly

Calls 6

randomDirFunction · 0.85
randFMethod · 0.80
lenMethod · 0.45
normalizeSafeMethod · 0.45
generateMethod · 0.45
pushBackMethod · 0.45

Tested by

no test coverage detected