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

Method buildConvex

Engine/source/terrain/terrCollision.cpp:346–472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344//----------------------------------------------------------------------------
345
346void TerrainBlock::buildConvex(const Box3F& box,Convex* convex)
347{
348 PROFILE_SCOPE( TerrainBlock_buildConvex );
349
350 mTerrainConvexList.collectGarbage();
351
352 // First check to see if the query misses the
353 // terrain elevation range.
354 const Point3F &terrainPos = getPosition();
355 if ( box.maxExtents.z - terrainPos.z < -TerrainThickness ||
356 box.minExtents.z - terrainPos.z > fixedToFloat( mFile->getMaxHeight() ) )
357 return;
358
359 // Transform the bounding sphere into the object's coord space. Note that this
360 // not really optimal.
361 Box3F osBox = box;
362 mWorldToObj.mul(osBox);
363 AssertWarn(mObjScale == Point3F(1, 1, 1), "Error, handle the scale transform on the terrain");
364
365 S32 xStart = (S32)mFloor( osBox.minExtents.x / mSquareSize );
366 S32 xEnd = (S32)mCeil ( osBox.maxExtents.x / mSquareSize );
367 S32 yStart = (S32)mFloor( osBox.minExtents.y / mSquareSize );
368 S32 yEnd = (S32)mCeil ( osBox.maxExtents.y / mSquareSize );
369 S32 xExt = xEnd - xStart;
370 if (xExt > MaxExtent)
371 xExt = MaxExtent;
372
373 U16 heightMax = floatToFixed(osBox.maxExtents.z);
374 U16 heightMin = (osBox.minExtents.z < 0)? 0: floatToFixed(osBox.minExtents.z);
375
376 const U32 BlockMask = mFile->mSize - 1;
377
378 for ( S32 y = yStart; y < yEnd; y++ )
379 {
380 S32 yi = y & BlockMask;
381
382 //
383 for ( S32 x = xStart; x < xEnd; x++ )
384 {
385 S32 xi = x & BlockMask;
386
387 const TerrainSquare *sq = mFile->findSquare( 0, xi, yi );
388
389 if ( x != xi || y != yi )
390 continue;
391
392 // holes only in the primary terrain block
393 if ( ( ( sq->flags & TerrainSquare::Empty ) && x == xi && y == yi ) ||
394 sq->minHeight > heightMax ||
395 sq->maxHeight < heightMin )
396 continue;
397
398 U32 sid = (x << 16) + (y & ((1 << 16) - 1));
399 Convex *cc = 0;
400
401 // See if the square already exists as part of the working set.
402 CollisionWorkingList& wl = convex->getWorkingList();
403 for (CollisionWorkingList* itr = wl.wLink.mNext; itr != &wl; itr = itr->wLink.mNext)

Callers

nothing calls this directly

Calls 15

getPositionFunction · 0.85
fixedToFloatFunction · 0.85
mFloorFunction · 0.85
mCeilFunction · 0.85
floatToFixedFunction · 0.85
collectGarbageMethod · 0.80
findSquareMethod · 0.80
addToWorkingListMethod · 0.80
getLayerIndexMethod · 0.80
Point3FClass · 0.50
mCrossFunction · 0.50
mDotFunction · 0.50

Tested by

no test coverage detected