Jump to content
  • Advertisement
Sign in to follow this  
3delite

D3DXMatrixLookAtLH alternative

This topic is 2542 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

I was trying to build my Direct3D9 app with the new Delphi XE2 for x64 and got a crash at the D3DXMatrixLookAtLH line saying that a floating point division by zero occured. It is strange becouse in Win32 build mode everything is working fine.

So I decided to replace the D3DXMatrixLookAtLH routine with my own, found some links that helped, but I couldn't figure it all out. Can anybody help with this?

The original code:



       EyePointVector := D3DXVector3(300, -290 ,-723);
        LookAtPointVector := D3DXVector3(300, -290, 0.0);
        UpVector := D3DXVector3(0.0, 1.0, 0.0);
        D3DXMatrixLookAtLH(ViewMatrix, EyePointVector, LookAtPointVector, UpVector);


Tryed achieving the same with:



        EyePointVector := D3DXVector3(300, -290 ,-723);
        LookAtPointVector := D3DXVector3(300, -290, 0.0);
        UpVector := D3DXVector3(0.0, 1.0, 0.0);
        RightVector := D3DXVector3(1.0, 0.0, 0.0);

        viewMatrix._11 := RightVector.x; viewMatrix._12 := UpVector.x; viewMatrix._13 := LookAtPointVector.x; viewMatrix._14 := 0.0;
        viewMatrix._21 := RightVector.y; viewMatrix._22 := UpVector.y; viewMatrix._23 := LookAtPointVector.y; viewMatrix._24 := 0.0;
        viewMatrix._31 := RightVector.z; viewMatrix._32 := UpVector.z; viewMatrix._33 := LookAtPointVector.z; viewMatrix._34 := 0.0;
        viewMatrix._41 := - D3DXVec3Dot(EyePointVector, RightVector);
        viewMatrix._42 := - D3DXVec3Dot(EyePointVector, UpVector);
        viewMatrix._43 := - D3DXVec3Dot(EyePointVector, LookAtPointVector);
        viewMatrix._44 := 1.0;



But the 3D space is deformed.

Share this post


Link to post
Share on other sites
Advertisement
Hi,
you either found some badly misleading links or you didn't understand it properly. The matrix is built differently, it is a bit more complicated. Check the documentation to find out how to build it manually:
http://msdn.microsof...v=vs.85%29.aspx

You definitely cannot have large numbers (like 300 in your case) in the top-left 3x3 submatrix, it consists of 3 normalized (unit-lenght) vectors.

Share this post


Link to post
Share on other sites

Hi,
you either found some badly misleading links or you didn't understand it properly. The matrix is built differently, it is a bit more complicated. Check the documentation to find out how to build it manually:
http://msdn.microsof...v=vs.85%29.aspx

You definitely cannot have large numbers (like 300 in your case) in the top-left 3x3 submatrix, it consists of 3 normalized (unit-lenght) vectors.


Thanx a lot!!! Got it working!!!


The code that works:

EyePointVector := D3DXVector3(300, -290 ,-723);
LookAtPointVector := D3DXVector3(300, -290, 0.0);
UpVector := D3DXVector3(0.0, 1.0, 0.0);
//D3DXMatrixLookAtLH(ViewMatrix, EyePointVector, LookAtPointVector, UpVector);

RightVector := D3DXVector3(1.0, 0.0, 0.0);

D3DXVec3Subtract(ZAxis, LookAtPointVector, EyePointVector);
D3DXVec3Normalize(ZAxis, ZAxis);

D3DXVec3Cross(XAxis, UpVector, ZAxis);
D3DXVec3Normalize(XAxis, XAxis);

D3DXVec3Cross(YAxis, ZAxis, XAxis);

viewMatrix._11 := XAxis.x; viewMatrix._12 := YAxis.x; viewMatrix._13 := ZAxis.x; viewMatrix._14 := 0.0;
viewMatrix._21 := XAxis.y; viewMatrix._22 := YAxis.y; viewMatrix._23 := ZAxis.y; viewMatrix._24 := 0.0;
viewMatrix._31 := XAxis.z; viewMatrix._32 := YAxis.z; viewMatrix._33 := ZAxis.z; viewMatrix._34 := 0.0;

viewMatrix._41 := - D3DXVec3Dot( XAxis, EyePointVector );
viewMatrix._42 := - D3DXVec3Dot( YAxis, EyePointVector );
viewMatrix._43 := - D3DXVec3Dot( ZAxis, EyePointVector );
viewMatrix._44 := 1.0;


Couldn't get this without your help! Thanx!  :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!