Work out the view matrix for direct3d off max

Started by
15 comments, last by lucky6969b 11 years, 1 month ago


    CameraObject *cam = (CameraObject*) node->EvalWorldState(ip->GetTime()).obj;
            
                        Matrix3 atm = node->GetObjectTM(ip->GetTime(), 0);// 4x3 matrix
                        Matrix3 targetTM;
                        node->GetTargetTM(ip->GetTime(), targetTM);
         
                        Matrix3 matD3D;
                        Point3 p1 (1.0f, 0.0f, 0.0f);
                        Point3 p2 (0.0f, 0.0f, 1.0f);
                        Point3 p3 (0.0f, 1.0f, 0.0f);
                        Point3 p4 (0.0f, 0.0f, 0.0f);
     
                          matD3D.SetRow(0, p1);
                          matD3D.SetRow(1, p2);
                          matD3D.SetRow(2, p3);
                          matD3D.SetRow(3, p4);

                        atm = atm * matD3D;
                          targetTM = targetTM * matD3D;

                        
                        int ki, kj;
                        MRow *pcvm = atm.GetAddr();        
                        for (ki = 0; ki < 4; ki++) {
                            for (kj = 0; kj < 3; kj++) {
                                d3dViewXform.m[ki][kj] = pcvm[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][3] = 1.0f;

                        
                        for (ki = 0; ki < 4; ki++) {
                            d3dViewXform.m[ki][2] *= -1.0f;
                       }

There must be something wrong that I can't tell.

Maybe orthogonal and perspective problem.. Any ideas?

Thanks

Jack

Advertisement

Why don’t you explain what the desired result is compared with the actual result? A screenshot may be useful if it is an incorrect image.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Hello, Spiro, nice to see you again.

I have checked the result against IGameExporter

And found that the last negation part should not be there. Hence


    CameraObject *cam = (CameraObject*) node->EvalWorldState(ip->GetTime()).obj;
            
                        Matrix3 atm = node->GetObjectTM(ip->GetTime(), 0);// 4x3 matrix
                        Matrix3 targetTM;
                        node->GetTargetTM(ip->GetTime(), targetTM);
         
                        Matrix3 matD3D;
                        Point3 p1 (1.0f, 0.0f, 0.0f);
                        Point3 p2 (0.0f, 0.0f, 1.0f);
                        Point3 p3 (0.0f, 1.0f, 0.0f);
                        Point3 p4 (0.0f, 0.0f, 0.0f);
     
                          matD3D.SetRow(0, p1);
                          matD3D.SetRow(1, p2);
                          matD3D.SetRow(2, p3);
                          matD3D.SetRow(3, p4);

                        atm = atm * matD3D;
                          targetTM = targetTM * matD3D;

                        
                        int ki, kj;
                        MRow *pcvm = atm.GetAddr();        
                        for (ki = 0; ki < 4; ki++) {
                            for (kj = 0; kj < 3; kj++) {
                                d3dViewXform.m[ki][kj] = pcvm[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][3] = 1.0f;

It seems like I have to negate the rotations in each axis and concatenate it to the translation matrix to get the final view matrix....

I'm still not entirely sure what you're trying to do with that camera, but it looks like you're trying to write a camera perspective projection matrix and it's not turning out right.

If that's the case, then MSDN has the formula you can use to create a pespective matrix: Note LH means left handed, and RH means right handed, so make sure you use the appropriate one from your coordinate space.

Perception is when one imagination clashes with another

Hey guys,

http://www.gamedev.net/topic/638823-exporting-from-pandasoft-and-3ds-max/

It seems like if I'd use the camera conversion method in this post, I'll get a left-handed coordinate based camera.

But I didn't check the left-handed coordinate option in pandasoft, therefore the mesh should be right-handed.

Right, got that displayed correctly though. But the y-z axis is flipped.

Because when I specify D3DXVECTOR3(10,10,0); the mesh reach the ground level.

I think it should be *better* or more consistent to convert to the left-hand. Any ideas I could solve my problem?

Thanks

Jack

Depending on the software that you export from, it may be a 'z' up coordinate system. You'll just need to rotate the matrix until it matches your coordinate system.

Perception is when one imagination clashes with another

3ds max. I'd like to know the way of doing this. This may be the chance of success.

Thanks

Jack

If you rotate 90 degrees about the x, you'll have the matrix be 'y' up. Then you have to rotate by 180 if your handedness is off.

Perception is when one imagination clashes with another

The thing is do I rotate the mesh along with the cameras. If I do so, the cameras matrices change too.

But I will see silly renders in max while the cameras are not aligned correctly with the scene.

BTW, are we talking about rotating +90 degrees in the X axis and then -180 degrees in the Z-axis? Just to make sure it is correct.

Thanks

Jack

The final rotation depends on your handedness. And you only need to do the rotation once at load time, to get the model into the same coordinate space as the rest of your scene and your camera. So your camera should be fine.

Perception is when one imagination clashes with another

This topic is closed to new replies.

Advertisement