Jump to content

  • Log In with Google      Sign In   
  • Create Account


Work out the view matrix for direct3d off max


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
16 replies to this topic

#1 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 18 February 2013 - 11:43 PM

    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



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 12334

Like
0Likes
Like

Posted 18 February 2013 - 11:47 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 19 February 2013 - 01:42 AM

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....

Attached Thumbnails

  • wayout.png
  • way off.png

Edited by lucky6969b, 19 February 2013 - 01:51 AM.


#4 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 19 February 2013 - 10:09 AM

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

#5 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 19 February 2013 - 10:33 PM

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


Edited by lucky6969b, 19 February 2013 - 10:38 PM.


#6 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 20 February 2013 - 08:53 AM

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

#7 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 20 February 2013 - 02:43 PM

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

Thanks

Jack



#8 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 20 February 2013 - 03:33 PM

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

#9 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 20 February 2013 - 11:38 PM

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


Edited by lucky6969b, 20 February 2013 - 11:43 PM.


#10 Seabolt   Members   -  Reputation: 632

Like
1Likes
Like

Posted 21 February 2013 - 09:07 AM

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

#11 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 21 February 2013 - 09:32 PM

So I want to express your ideas in my own terms for my own reference.

I need to rotate the mesh in max with an angle of positive 90 degrees in the X-axis.

Then at load time, depending on whether I use OpenGL or DirectX, I rotate the mesh -180 degrees in the Z-axis, and if I use DirectX in this case

The cameras can stay fine, no need to be changed in the scene. Then the output of rendering in my application will be the same as the scene I see in max.

I should check the left-coordinate system check box in pandasoft. I can set a mesh to a location such as D3DXVECTOR3(10,10,0) and it sits on the ground level. Please let me know if there is anything missing.

Thanks seabolt, you have been great help

Jack



#12 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 21 February 2013 - 10:08 PM

That sounds good! 

Good luck!


Perception is when one imagination clashes with another

#13 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 22 February 2013 - 03:08 AM

ehhhh! the meshes are rendered correcly, my very last problem being is that the z-axis is still pointing up.

My apologizes, I have skipped the rotation of Z axis at load time, rather, I did a 90 degrees flip in the X and -180 degrees in Z.

It looks really strange in the viewport in 3ds max. But I don't really mind. But I am not accustomed to Z-axis pointing up.

sad.png

Thanks

Jack


Edited by lucky6969b, 22 February 2013 - 03:08 AM.


#14 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 22 February 2013 - 09:59 AM

Yeah the company I work for also has z-up coordinate systems. it drives me insane when I have to do math, and then it doesn't work because I forgot that z is up, not y haha.

Good luck though!


Perception is when one imagination clashes with another

#15 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 23 February 2013 - 04:43 AM

It has been a great pain attempting to convert it to y-up, been trying out for 3 consecutive days without results.

Thanks

Jack



#16 Seabolt   Members   -  Reputation: 632

Like
0Likes
Like

Posted 23 February 2013 - 04:12 PM

If your matrices are still z up, did the rotations not work? That last comment sounded like it was working.


Perception is when one imagination clashes with another

#17 lucky6969b   Members   -  Reputation: 542

Like
0Likes
Like

Posted 23 February 2013 - 09:58 PM

[del]


Edited by lucky6969b, 23 February 2013 - 10:31 PM.





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.



PARTNERS