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

Method buildBoxData

Engine/source/math/mPolyhedron.impl.h:447–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445
446template< typename Polyhedron >
447void PolyhedronData::buildBoxData( Polyhedron& poly, const MatrixF& mat, const Box3F& box, bool invertNormals )
448{
449 AssertFatal( poly.getNumPoints() == 8, "PolyhedronData::buildBox - Incorrect point count!" );
450 AssertFatal( poly.getNumEdges() == 12, "PolyhedronData::buildBox - Incorrect edge count!" );
451 AssertFatal( poly.getNumPlanes() == 6, "PolyhedronData::buildBox - Incorrect plane count!" );
452
453 // Box is assumed to be axis aligned in the source space.
454 // Transform into geometry space.
455
456 Point3F xvec = mat.getRightVector() * box.len_x();
457 Point3F yvec = mat.getForwardVector() * box.len_y();
458 Point3F zvec = mat.getUpVector() * box.len_z();
459
460 Point3F min;
461 mat.mulP( box.minExtents, &min );
462
463 // Corner points.
464
465 typename Polyhedron::PointListType& pointList = poly.mPointList;
466
467 pointList[ 0 ] = min; // near left bottom
468 pointList[ 1 ] = min + yvec; // far left bottom
469 pointList[ 2 ] = min + xvec + yvec; // far right bottom
470 pointList[ 3 ] = min + xvec; // near right bottom
471 pointList[ 4 ] = pointList[ 0 ] + zvec; // near left top
472 pointList[ 5 ] = pointList[ 1 ] + zvec; // far left top
473 pointList[ 6 ] = pointList[ 2 ] + zvec; // far right top
474 pointList[ 7 ] = pointList[ 3 ] + zvec; // near right top
475
476 // Side planes.
477
478 typename Polyhedron::PlaneListType& planeList = poly.mPlaneList;
479
480 const F32 pos = invertNormals ? -1.f : 1.f;
481 const F32 neg = - pos;
482
483 planeList[ 0 ].set( pointList[ 0 ], xvec * pos ); // left
484 planeList[ 1 ].set( pointList[ 2 ], yvec * neg ); // far
485 planeList[ 2 ].set( pointList[ 2 ], xvec * neg ); // right
486 planeList[ 3 ].set( pointList[ 0 ], yvec * pos ); // front
487 planeList[ 4 ].set( pointList[ 0 ], zvec * pos ); // bottom
488 planeList[ 5 ].set( pointList[ 4 ], zvec * neg ); // top
489
490 // The edges are constructed so that the vertices
491 // are oriented clockwise for face[0].
492
493 typename Polyhedron::EdgeType* edge = &poly.mEdgeList[ 0 ];
494
495 for( U32 i = 0; i < 4; ++ i )
496 {
497 S32 n = ( i == 3 ) ? 0: i + 1;
498 S32 p = ( i == 0 ) ? 3: i - 1;
499
500 edge->vertex[ 0 ] = !invertNormals ? n : i;
501 edge->vertex[ 1 ] = !invertNormals ? i : n;
502 edge->face[ 0 ] = i;
503 edge->face[ 1 ] = 4;
504 edge ++;

Callers

nothing calls this directly

Calls 11

getRightVectorMethod · 0.80
getUpVectorMethod · 0.80
mulPMethod · 0.80
getNumPointsMethod · 0.45
getNumEdgesMethod · 0.45
getNumPlanesMethod · 0.45
len_xMethod · 0.45
getForwardVectorMethod · 0.45
len_yMethod · 0.45
len_zMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected