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

Method getNormalHeightMaterial

Engine/source/terrain/terrData.cpp:902–972  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

900
901
902bool TerrainBlock::getNormalHeightMaterial( const Point2F &pos,
903 Point3F *normal,
904 F32 *height,
905 StringTableEntry &matName ) const
906{
907 PROFILE_SCOPE( TerrainBlock_getNormalHeightMaterial );
908
909 F32 invSquareSize = 1.0f / mSquareSize;
910 F32 xp = pos.x * invSquareSize;
911 F32 yp = pos.y * invSquareSize;
912 S32 x = S32(xp);
913 S32 y = S32(yp);
914 S32 xm = S32(mFloor( xp + 0.5f ));
915 S32 ym = S32(mFloor( yp + 0.5f ));
916 xp -= (F32)x;
917 yp -= (F32)y;
918
919 const U32 blockMask = mFile->mSize - 1;
920
921 if ( x & ~blockMask || y & ~blockMask )
922 return false;
923
924 x &= blockMask;
925 y &= blockMask;
926
927 const TerrainSquare *sq = mFile->findSquare( 0, x, y );
928 if ( sq->flags & TerrainSquare::Empty )
929 return false;
930
931 F32 zBottomLeft = fixedToFloat( mFile->getHeight(x, y) );
932 F32 zBottomRight = fixedToFloat( mFile->getHeight(x + 1, y) );
933 F32 zTopLeft = fixedToFloat( mFile->getHeight(x, y + 1) );
934 F32 zTopRight = fixedToFloat( mFile->getHeight(x + 1, y + 1) );
935
936 matName = mFile->getMaterialName( xm, ym );
937
938 if ( sq->flags & TerrainSquare::Split45 )
939 {
940 if (xp>yp)
941 {
942 // bottom half
943 normal->set(zBottomLeft-zBottomRight, zBottomRight-zTopRight, mSquareSize);
944 *height = zBottomLeft + xp * (zBottomRight-zBottomLeft) + yp * (zTopRight-zBottomRight);
945 }
946 else
947 {
948 // top half
949 normal->set(zTopLeft-zTopRight, zBottomLeft-zTopLeft, mSquareSize);
950 *height = zBottomLeft + xp * (zTopRight-zTopLeft) + yp * (zTopLeft-zBottomLeft);
951 }
952 }
953 else
954 {
955 if (1.0f-xp>yp)
956 {
957 // bottom half
958 normal->set(zBottomLeft-zBottomRight, zBottomLeft-zTopLeft, mSquareSize);
959 *height = zBottomRight + (1.0f-xp) * (zBottomLeft-zBottomRight) + yp * (zTopLeft-zBottomLeft);

Callers 1

_generateCellMethod · 0.80

Calls 7

mFloorFunction · 0.85
fixedToFloatFunction · 0.85
findSquareMethod · 0.80
getHeightMethod · 0.45
getMaterialNameMethod · 0.45
setMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected