| 795 | } |
| 796 | |
| 797 | bool 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 | |
| 835 | bool TerrainBlock::getNormalAndHeight( const Point2F &pos, Point3F *normal, F32 *height, bool normalize ) const |
| 836 | { |
no test coverage detected