Failure to set Matrices

Problems building or running the engine, queries about how to use features etc.
Post Reply
mcmonkey
Gnoblar
Posts: 19
Joined: Fri Jan 09, 2015 6:12 am

Failure to set Matrices

Post by mcmonkey »

I'm attempting this code:

Code: Select all

        static void AdjustProjection(Vector3 eye, Vector3 target, Vector3 up)
        {
            SlimMath.Matrix pers = SlimMath.Matrix.PerspectiveFovLH(45, CameraViewport.ActualWidth / CameraViewport.ActualHeight, 1, 3000);
            SlimMath.Matrix view = SlimMath.Matrix.LookAtLH(new SlimMath.Vector3(eye.x, eye.y, eye.z),
                new SlimMath.Vector3(target.x, target.y, target.z),
                new SlimMath.Vector3(up.x, up.y, up.z));
            PlayerCamera.SetCustomProjectionMatrix(true, new Matrix4(pers.M11, pers.M12, pers.M13, pers.M14, pers.M21, pers.M22,
                pers.M23, pers.M24, pers.M31, pers.M32, pers.M33, pers.M34, pers.M41, pers.M42, pers.M43, pers.M44));
            PlayerCamera.SetCustomViewMatrix(true, new Matrix4(view.M11, view.M12, view.M13, view.M14, view.M21, view.M22,
                view.M23, view.M24, view.M31, view.M32, view.M33, view.M34, view.M41, view.M42, view.M43, view.M44));
            
            // Pure-OGRE code equiv:
/*
            PlayerCamera.FOVy = 45;
            PlayerCamera.AspectRatio = CameraViewport.ActualWidth / CameraViewport.ActualHeight;
            PlayerCamera.NearClipDistance = 1;
            PlayerCamera.FarClipDistance = 3000;
            //PlayerCamera.Position = eye;
            PlayerCamera.LookAt(target);
            // No equiv for 'up'
*/
        }
Unfortunately, this does not produce expected results - the whole world is shrunk down to a thin line. I'm using https://code.google.com/p/slimmath/ for the math (Since OGRE does not supply sufficient mathematical functions). What am I doing wrong?
Last edited by mcmonkey on Mon Jan 12, 2015 9:58 am, edited 1 time in total.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Failure to set Matrices

Post by Kojack »

SlimMath.Matrix.PerspectiveFovLH and SlimMath.Matrix.LookAtLH are both left handed coordinate system functions. Ogre requires right handed matrices. Try SlimMath.Matrix.PerspectiveFovRH and SlimMath.Matrix.LookAtRH instead.
mcmonkey
Gnoblar
Posts: 19
Joined: Fri Jan 09, 2015 6:12 am

Re: Failure to set Matrices

Post by mcmonkey »

It still results in:
Image
mcmonkey
Gnoblar
Posts: 19
Joined: Fri Jan 09, 2015 6:12 am

Re: Failure to set Matrices

Post by mcmonkey »

Still an active issue.

Something interesting I noticed:

Moving the camera (changing the position [eye] value) results in the view rotating and distorting.

So... that's interesting.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Failure to set Matrices

Post by Kojack »

Could you list the values inside of the matrices?
mcmonkey
Gnoblar
Posts: 19
Joined: Fri Jan 09, 2015 6:12 am

Re: Failure to set Matrices

Post by mcmonkey »

Right-Hand perspective
Image
Left-Hand perspective
Image

the view differences are different from slight camera rotation.

... I crashed the app trying to copy text from console, so screenshots!

That is via:

Code: Select all

            Console.WriteLine("PERSPECTIVE:");
            Console.WriteLine(pers.M11 + " " + pers.M12 + " " + pers.M13 + " " + pers.M14);
            Console.WriteLine(pers.M21 + " " + pers.M22 + " " + pers.M23 + " " + pers.M24);
            Console.WriteLine(pers.M31 + " " + pers.M32 + " " + pers.M33 + " " + pers.M34);
            Console.WriteLine(pers.M41 + " " + pers.M42 + " " + pers.M43 + " " + pers.M44);
            Console.WriteLine("VIEW:");
            Console.WriteLine(view.M11 + " " + view.M12 + " " + view.M13 + " " + view.M14);
            Console.WriteLine(view.M21 + " " + view.M22 + " " + view.M23 + " " + view.M24);
            Console.WriteLine(view.M31 + " " + view.M32 + " " + view.M33 + " " + view.M34);
            Console.WriteLine(view.M41 + " " + view.M42 + " " + view.M43 + " " + view.M44);
Post Reply