Sign in to follow this  
user88

[SlimDX/MDX] Plane.Transform

Recommended Posts

Hi. I still have problems with Plane.Transform when migrate my project from MDX to SlimDX. I have prepared some little Console Application. So, you can check my issue with spend short time. Just create Console Application in VS, add such references as SlimDX, Microsoft.DirectX and paste code represented below.
using System;

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("***** SlimDX's *****\n{0}", GetSlimDXTrspsInvVPPlane(0.41f, 0.0f, -40.0f, 40.0f,
                                                                              0.0f, 0.41f, -25.0f, 25.0f,
                                                                              0.0f, 0.0f, -147.08f, 146.09f,
                                                                              0.0f, 0.0f, -0.02f, 0.02f,
                                                                              0f, 0f, -1, -237));
            Console.WriteLine("\n\n\n***** MDX's *****\n{0} ", GetMDXTrspsInvVPPlane(0.41f, 0.0f, -40.0f, 40.0f,
                                                                              0.0f, 0.41f, -25.0f, 25.0f,
                                                                              0.0f, 0.0f, -147.08f, 146.09f,
                                                                              0.0f, 0.0f, -0.02f, 0.02f,
                                                                              0f, 0f, -1, -237));
        }

        private static string GetSlimDXTrspsInvVPPlane(float m11, float m12, float m13, float m14, 
            float m21, float m22, float m23, float m24, 
            float m31, float m32, float m33, float m34, 
            float m41, float m42, float m43, float m44, 
            float a, float b, float c, float d)
        {
            SlimDX.Matrix vp = new SlimDX.Matrix();
            vp.M11 = m11; vp.M12 = m12; vp.M13 = m13; vp.M14 = m14;
            vp.M21 = m21; vp.M22 = m22; vp.M23 = m23; vp.M24 = m24; 
            vp.M31 = m31; vp.M32 = m32; vp.M33 = m33; vp.M34 = m34; 
            vp.M41 = m41; vp.M42 = m42; vp.M43 = m43; vp.M44 = m44; 
            vp.Invert();
            SlimDX.Matrix trspsInvVP;
            SlimDX.Matrix.Transpose(ref vp, out trspsInvVP);
            SlimDX.Plane plane = new SlimDX.Plane(a, b, c, d);
            SlimDX.Plane trspsInvVPPlane;
            trspsInvVPPlane = SlimDX.Plane.Transform(plane, trspsInvVP);
            return String.Format("trspsInvVPPlane: {0};\n trspsInvVP: {1};\nvp:{2}", trspsInvVPPlane, trspsInvVP, vp);
        }

        private static string GetMDXTrspsInvVPPlane(float m11, float m12, float m13, float m14,
            float m21, float m22, float m23, float m24,
            float m31, float m32, float m33, float m34,
            float m41, float m42, float m43, float m44,
            float a, float b, float c, float d)
        {
            Microsoft.DirectX.Matrix vp = new Microsoft.DirectX.Matrix();
            vp.M11 = m11; vp.M12 = m12; vp.M13 = m13; vp.M14 = m14;
            vp.M21 = m21; vp.M22 = m22; vp.M23 = m23; vp.M24 = m24;
            vp.M31 = m31; vp.M32 = m32; vp.M33 = m33; vp.M34 = m34;
            vp.M41 = m41; vp.M42 = m42; vp.M43 = m43; vp.M44 = m44;
            vp.Invert();
            Microsoft.DirectX.Matrix trspsInvVP;
            trspsInvVP = Microsoft.DirectX.Matrix.TransposeMatrix(vp);
            Microsoft.DirectX.Plane plane = new Microsoft.DirectX.Plane(a, b, c, d);
            Microsoft.DirectX.Plane trspsInvVPPlane;
            trspsInvVPPlane = Microsoft.DirectX.Plane.Transform(plane, trspsInvVP);
            return String.Format("trspsInvVPPlane: {0};\n trspsInvVP: {1};\nvp:{2}", trspsInvVPPlane, trspsInvVP, vp);
        }
    }
}



If run application next result has been got:
***** SlimDX's ***** trspsInvVPPlane: Normal:X:0 Y:0 Z:151,822 D:-150,832; trspsInvVP: M11:2,439025 M12:0 M13:0 M14:0 M21:0 M22:2,439025 M23:0 M24:0 M31:0 M32:0 M33:-1,010092 M34:-1,010092 M41:-4878,076 M42:-3048,752 M43:7378,214 M44:7428,213 vp: M11:2,439025 M12:0 M13:0 M14:-4878,076 M21:0 M22:2,439025 M23:0 M24:-3048,752 M31:0 M32:0 M33:-1,010092 M34:7378,214 M41:0 M42:0 M43:-1,010092 M44:7428,213 ***** MDX's ***** trspsInvVPPlane: A: 1156104 B: 722554,3 C: -1748636 D: -1760486; trspsInvVP: M11: 2,439025 M12: 0 M13: 0 M14: 0 M21: 0 M22: 2,439025 M23: 0 M24: 0 M31: 0 M32: 0 M33: -1,010092 M34: -1,010092 M41: -4878,076 M42: -3048,752 M43: 7378,214 M44: 7428,213 vp: M11: 2,439025 M12: 0 M13: 0 M14: -4878,076 M21: 0 M22: 2,439025 M23: 0 M24: -3048,752 M31: 0 M32: 0 M33: -1,010092 M34: 7378,214 M41: 0 M42: 0 M43: -1,010092 M44: 7428,213
Why planes in both cases are different?? Please, [help]

Share this post


Link to post
Share on other sites
Interesting. After some digging I found out MDX uses DirectX D3DXTransformPlane and SlimDX doesn't (anymore).

I checked against the DirectX doc example and found out leaving the matrix as it is will give the correct result (according to this blog that's actually the solution).

So, if you don't invert and transpose for the SlimDX plane transformation call, what do you get ?

Share this post


Link to post
Share on other sites
Currently Plane.Transform mimics the behavior of the corresponding function in XNA. Regardless of whether that's a good idea or whether we should be mimicking D3DX instead, we can't be changing something like that now when many people may be relying on it.

We'll look into this more for SlimDX 2.0.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this