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

Method getNormalAndHeight

Engine/source/terrain/terrData.cpp:835–899  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

833}
834
835bool TerrainBlock::getNormalAndHeight( const Point2F &pos, Point3F *normal, F32 *height, bool normalize ) const
836{
837 PROFILE_SCOPE( TerrainBlock_getNormalAndHeight );
838
839 F32 invSquareSize = 1.0f / mSquareSize;
840 F32 xp = pos.x * invSquareSize;
841 F32 yp = pos.y * invSquareSize;
842 S32 x = S32(xp);
843 S32 y = S32(yp);
844 xp -= (F32)x;
845 yp -= (F32)y;
846
847 const U32 blockMask = mFile->mSize - 1;
848
849 if ( x & ~blockMask || y & ~blockMask )
850 return false;
851
852 x &= blockMask;
853 y &= blockMask;
854
855 const TerrainSquare *sq = mFile->findSquare( 0, x, y );
856 if ( sq->flags & TerrainSquare::Empty )
857 return false;
858
859 F32 zBottomLeft = fixedToFloat( mFile->getHeight(x, y) );
860 F32 zBottomRight = fixedToFloat( mFile->getHeight(x + 1, y) );
861 F32 zTopLeft = fixedToFloat( mFile->getHeight(x, y + 1) );
862 F32 zTopRight = fixedToFloat( mFile->getHeight(x + 1, y + 1) );
863
864 if ( sq->flags & TerrainSquare::Split45 )
865 {
866 if (xp>yp)
867 {
868 // bottom half
869 normal->set(zBottomLeft-zBottomRight, zBottomRight-zTopRight, mSquareSize);
870 *height = zBottomLeft + xp * (zBottomRight-zBottomLeft) + yp * (zTopRight-zBottomRight);
871 }
872 else
873 {
874 // top half
875 normal->set(zTopLeft-zTopRight, zBottomLeft-zTopLeft, mSquareSize);
876 *height = zBottomLeft + xp * (zTopRight-zTopLeft) + yp * (zTopLeft-zBottomLeft);
877 }
878 }
879 else
880 {
881 if (1.0f-xp>yp)
882 {
883 // bottom half
884 normal->set(zBottomLeft-zBottomRight, zBottomLeft-zTopLeft, mSquareSize);
885 *height = zBottomRight + (1.0f-xp) * (zBottomLeft-zBottomRight) + yp * (zTopLeft-zBottomLeft);
886 }
887 else
888 {
889 // top half
890 normal->set(zTopLeft-zTopRight, zBottomRight-zTopRight, mSquareSize);
891 *height = zBottomRight + (1.0f-xp) * (zTopLeft-zTopRight) + yp * (zTopRight-zBottomRight);
892 }

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected