Jump to content

Image of the Day

Everything is fine. 

#screenshotsaturday #indiedev #gamedev https://t.co/98BAKUInyo
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.

Sign up now

Trying to convert a 3ds max camera to direct3d

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 lucky6969b   Members   


Posted 12 March 2013 - 11:35 PM

The Direct3D coordinate system is left-handed. And If I have a camera looking down, the up vector is pointing out of the scene, the right vector is somehow pointing to the left, and the lookat vector is downward. I can get the last one using D3DXVec3Cross(); However, I don't understand how the 3ds max cameras work, they are supposed to be

1) up vector still pointing out.

2) right vector pointing right

3) lookat vector pointing toward me (out of the scene).

Which vector(s) represent up, right and lookat for Max? How do I convert a Max camera to a Direct3D camera without matrix decomposition? It seems like if I multiply the transformation given by Max at runtime by

[1 0 0]

[0 0 1]

[1 0 0]

I will get a mirror effect. My goal is still to have Y-up in my application instead of Z-up in the max application. I understand max, opengl and direct3d all use different coordinate systems. How do I convert them handily? Thanks Jack

Edited by lucky6969b, 13 March 2013 - 12:40 AM.

#2 RobTheBloke   Members   


Posted 13 March 2013 - 01:21 PM

Which vector(s) represent up, right and lookat for Max?

It's just a world transform matrix you get from INode->getNodeTM().
You can simply pre & post multiply this by a scaling matrix, with -1 as the scale in the Z axis. i.e.

CamLH = ScaleMinusOneZ * CamRH * ScaleMinusOneZ;

Worrying about lookat vectors is superfluous. Just use the matrices, rather than extracting lookat vectors from the matrices, before pumping them back into matrices.

If you have the camera data as a world space position + quaternion, you can do:


void convertPosQuatHandedness(Vec3& p, Quat& q)


   p.z = -p.z;
   q.z = -q.z;
   q.w = -q.w;


#3 lucky6969b   Members   


Posted 20 March 2013 - 01:50 AM

Sorry, Rob, I followed your instructions but getting nothing out of it.

But there is some misleading information out on the net which is contradictory

One is to multiply the INode->GetNodeTM() by

[1 0 0]

[0 0 1]

[0 1 0]

and the other one is

[1 0 0]

[0 0 1]

[0-1 0]


Anyways here is my code now

                        D3DXMATRIX matD3D;
                        matD3D.m[1][1] = 0;
                        matD3D.m[1][2] = 1;
                        matD3D.m[2][1] = -1; or 1;
                        matD3D.m[2][2] = 0;

                        D3DXMATRIX viewMat;
                        viewMat = matD3D * maxViewMat;


where matViewMat is INode->GetNodeTM();

And matD3D is used to flip the yz axis


Here is another major reference I have found on the net



Any help is greatly appreciated!



#4 lucky6969b   Members   


Posted 21 March 2013 - 09:11 PM

There are some disprepancies between my max camera and direct3d cameras

I followed this thread




    Matrix3 atm = node->GetNodeTM(ip->GetTime(), 0);// 4x3 matrix
                        Matrix3 targetTM;
                        node->GetTargetTM(ip->GetTime(), targetTM);

                        MRow *row1 = atm.GetAddr();
                        Point3 position;
                        position.x = row1[3][0];
                        position.y = row1[3][2];
                        position.z = row1[3][1];

                       Matrix3 rotation(atm);



                        MRow *row2 = rotation.GetAddr();

                            // row 2

                        Point3 temp2(row2[1][0], row2[1][1], row2[1][2]);


                        // put row 3 to row 2

                        row2[1][0] = row2[2][0]; // 1,0

                        row2[1][1] = row2[2][1]; // 1,1

                        row2[1][2] = row2[2][2]; // 1,2

                        // put row 2 to row 3

                        row2[2][0] = temp2.x; //2,0

                        row2[2][1] = temp2.y; //2,1

                        row2[2][2] = temp2.z; //2,2



                        // column vector 2

                        Point3 temp(row2[0][1], row2[1][1], row2[2][1]);

                        // put column 3 into column 2

                        Point3 col2;

                        col2.x = rotation.GetRow(0)[2]; // 0,1

                        col2.y = rotation.GetRow(1)[2];

                        col2.z = rotation.GetRow(2)[2];

                        rotation.SetColumn(1, col2);


                        // put column 2 into column 3

                        Point3 col3;

                        col3.x = temp.x; // 0,2

                        col3.y = temp.y;

                        col3.z = temp.z;

                        rotation.SetColumn(2, col3);





                            int ki, kj;

                         for (ki = 0; ki < 4; ki++) {

                            for (kj = 0; kj < 3; kj++) {

                                d3dViewXform.m[ki][kj] = row2[ki][kj];




                        // Assign the fourth column (perspective terms)

                         d3dViewXform.m[0][3] = d3dViewXform.m[1][3] = d3dViewXform.m[2][3] = 0.0f;


                        d3dViewXform.m[3][0] = position.x;

                        d3dViewXform.m[3][1] = position.y;

                        d3dViewXform.m[3][2] = position.z;

                        d3dViewXform.m[3][3] = 1.0f;


                        float fov_rh = cam->GetFOV(ip->GetTime(), FOREVER);






                        float aspectRatio = ip->GetRendImageAspect();

                        float fov_lh = aspectRatio / fov_rh;

                        // Change it to vertical 3d mathematic book

                        float e = 1 / tanf( fov_lh /  2 );

                        // vertical fov

                        float fov_vert = 2 * atanf(aspectRatio/e);


                        float nearClip = cam->GetClipDist(ip->GetTime(), CAM_HITHER_CLIP, FOREVER);

                        float farClip = cam->GetClipDist(ip->GetTime(), CAM_YON_CLIP, FOREVER);



                        D3DXMATRIX d3dProjXform;

                        D3DXMatrixPerspectiveFovLH(&d3dProjXform, fov_vert, aspectRatio, nearClip, farClip);

I tried to swap row2 and row3 and followed by swapping column2 and column3, what beneath it is the projection matrix calculation method.


Image compared


rendered camera1.jpg



direct3d camera.jpg


Any ideas?


Edited by lucky6969b, 22 March 2013 - 01:00 AM.

#5 RobTheBloke   Members   


Posted 23 March 2013 - 11:31 AM

Handling Z up / Y up is not an issue - stop trying to correct it.. It's just a rotation of 90 degrees around X. Set Y or Z up in the max preferences, and/or rotate the objects by 90 degrees to fix that. Matrix handedness needs to be corrected for as i showed above. If you just pump the matrices from max into directx (without correction), you'll be looking at a model that has been mirrored through the XY plane.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.