BEPUphysics.CollisionShapes.TerrainShape.GetNormal C# (CSharp) Method

GetNormal() public method

Gets the world space normal at the given indices.
public GetNormal ( int i, int j, AffineTransform &transform, Vector3 &normal ) : void
i int Index in the first dimension.
j int Index in the second dimension.
transform BEPUutilities.AffineTransform Transform to apply to the terrain while computing the normal.
normal Vector3 World space normal at the given indices.
return void
        public void GetNormal(int i, int j, ref AffineTransform transform, out Vector3 normal)
        {
            Vector3 top;
            Vector3 bottom;
            Vector3 right;
            Vector3 left;

            if (i <= 0)
                i = 0;
            else if (i >= heights.GetLength(0))
                i = heights.GetLength(0) - 1;
            if (j <= 0)
                j = 0;
            else if (j >= heights.GetLength(1))
                j = heights.GetLength(1) - 1;

            GetPosition(i, Math.Min(j + 1, heights.GetLength(1) - 1), ref transform, out top);
            GetPosition(i, Math.Max(j - 1, 0), ref transform, out bottom);
            GetPosition(Math.Min(i + 1, heights.GetLength(0) - 1), j, ref transform, out right);
            GetPosition(Math.Max(i - 1, 0), j, ref transform, out left);

            Vector3 temp;
            Vector3.Subtract(ref top, ref bottom, out temp);
            Vector3.Subtract(ref right, ref left, out normal);
            Vector3.Cross(ref temp, ref normal, out normal);

            normal.Normalize();
        }