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

Method getSmoothNormal

Engine/source/terrain/terrData.cpp:797–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

795}
796
797bool TerrainBlock::getSmoothNormal( const Point2F &pos,
798 Point3F *normal,
799 bool normalize,
800 bool skipEmpty ) const
801{
802 PROFILE_SCOPE( TerrainBlock_getSmoothNormal );
803
804 F32 invSquareSize = 1.0f / mSquareSize;
805 F32 xp = pos.x * invSquareSize;
806 F32 yp = pos.y * invSquareSize;
807 S32 x = S32(xp);
808 S32 y = S32(yp);
809
810 const U32 blockMask = mFile->mSize - 1;
811
812 if ( x & ~blockMask || y & ~blockMask )
813 return false;
814
815 x &= blockMask;
816 y &= blockMask;
817
818 const TerrainSquare *sq = mFile->findSquare( 0, x, y );
819 if ( skipEmpty && sq->flags & TerrainSquare::Empty )
820 return false;
821
822 F32 h1 = fixedToFloat( mFile->getHeight( x + 1, y ) );
823 F32 h2 = fixedToFloat( mFile->getHeight( x, y + 1 ) );
824 F32 h3 = fixedToFloat( mFile->getHeight( x - 1, y ) );
825 F32 h4 = fixedToFloat( mFile->getHeight( x, y - 1 ) );
826
827 normal->set( h3 - h1, h4 - h2, mSquareSize * 2.0f );
828
829 if ( normalize )
830 normal->normalize();
831
832 return true;
833}
834
835bool TerrainBlock::getNormalAndHeight( const Point2F &pos, Point3F *normal, F32 *height, bool normalize ) const
836{

Callers 1

_updateVertexBufferMethod · 0.80

Calls 5

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

Tested by

no test coverage detected