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

Method generateNormals

Engine/source/environment/meshRoad.cpp:373–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373void MeshRoadProfile::generateNormals()
374{
375 VectorF t, b, n, t2, n2;
376 Point3F averagePt;
377
378 mNodeNormals.clear();
379
380 // Loop through all profile line segments
381 for(U32 i=0; i < mNodes.size()-1; i++)
382 {
383 // Calculate normal for each node in line segment
384 for(U32 j=0; j<2; j++)
385 {
386 // Smoothed Node: Average the node with nodes before and after.
387 // Direction between the node and the average is the smoothed normal.
388 if( mNodes[i+j].isSmooth() )
389 {
390 b = Point3F(0.0f, 0.0f, 1.0f);
391 t = mNodes[i+j-1].getPosition() - mNodes[i+j].getPosition();
392 n = mCross(t, b);
393 n.normalizeSafe();
394
395 t2 = mNodes[i+j].getPosition() - mNodes[i+j+1].getPosition();
396 n2 = mCross(t2, b);
397 n2.normalizeSafe();
398
399 n += n2;
400 }
401 // Non-smoothed Node: Normal is perpendicular to segment.
402 else
403 {
404 b = Point3F(0.0f, 0.0f, 1.0f);
405 t = mNodes[i].getPosition() - mNodes[i+1].getPosition();
406 n = mCross(t, b);
407 }
408
409 n.normalizeSafe();
410 mNodeNormals.push_back(n);
411 }
412 }
413}
414
415void MeshRoadProfile::generateEndCap(F32 width)
416{

Callers 5

_captureVertsMethod · 0.45
onAddMethod · 0.45
unpackUpdateMethod · 0.45
undoMethod · 0.45
clipDecalMethod · 0.45

Calls 8

isSmoothMethod · 0.80
Point3FClass · 0.50
mCrossFunction · 0.50
clearMethod · 0.45
sizeMethod · 0.45
getPositionMethod · 0.45
normalizeSafeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected