Example #1
0
        public static Vector2 ComputeTexCoord <T>(this T vertex, Vector3 trileSize) where T : ILitVertex, ITexturedVertex
        {
            FaceOrientation orientation = FezMath.OrientationFromDirection(vertex.Normal);
            Vector2         vector2;

            switch (orientation)
            {
            case FaceOrientation.Left:
                vector2 = new Vector2(0.375f, 0.0f);
                break;

            case FaceOrientation.Back:
                vector2 = new Vector2(0.375f, 0.0f);
                break;

            case FaceOrientation.Right:
                vector2 = new Vector2(0.25f, 0.0f);
                break;

            case FaceOrientation.Top:
                vector2 = new Vector2(0.5f, 0.0f);
                break;

            case FaceOrientation.Front:
                vector2 = Vector2.Zero;
                break;

            default:
                vector2 = new Vector2(0.625f, 0.0f);
                break;
            }
            Vector3 b    = ((Vector3.One - FezMath.Abs(vertex.Normal)) * vertex.Position / trileSize * 2f + vertex.Normal) / 2f + new Vector3(0.5f);
            float   num1 = FezMath.Dot(FezMath.RightVector(FezMath.AsViewpoint(orientation)), b);
            float   num2 = FezMath.Dot(FezMath.UpVector(FezMath.AsViewpoint(orientation)), b);

            if (orientation != FaceOrientation.Top)
            {
                num2 = 1f - num2;
            }
            return(new Vector2(vector2.X + num1 / 8f, vector2.Y + num2));
        }