Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

UnknownPlayer

The view matrix and "Up"

This topic is 5646 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

I''ve got a simple third person camera working using D3DXMatrixLookAtLH and some quaternion rotations to calculate the movements of the camera position, and it works very well. However, when I have it attached to an object rotating forward or backwards on the x-axis (pitching) at some point the camera causes all objects to flip upside down. Now I''m guessing this is to do with the fact I don''t presently alter what the Up vector is. The problem is, I''m not sure how I should alter it - ideally it would be rotated through the same rotations so that Up is always relative to the player''s object (its in space so this would be convenient), but when I apply the camera quaternion rotation to the Up vector, all I get is objects flipping out all over the place very quickly. So, can anyone give me some advice here? Ideally I''d like to know more about what exactly the Up vector does, but also any hints on my specific problem are appreciated. ##UnknownPlayer##

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Hi. The up vector is 90 degrees up from the foward vector, and there is also a right vector which is 90 degrees right of the foward vector. You have to cross multiply the vectors to recalculate the up and right, but seeing as they are based on matrix maths, you just need to multiply 2 of them to get the third one.
vb code:

''get other variables like right vector
''right = foward * up
''foward = right * up
''up = foward * right

ryan@pcsoftware.co.nz

Share this post


Link to post
Share on other sites
i assume it works just like glulookat (never used it in dx, a matrix camera felt more comfortable).

what you specify as up doesnt really matter. if your camera cant roll you can use either 0,1,0 or 0,-1,0.. might screw up if you look exactly 90deg up/down though. up is meant to be the cameras up. imagine your head and look down at the floor, now your up-vector would be 0,0,1 . but as i said, if your cam wont roll, use 0,1,0 for orientiations between 270 and 90 deg (with 0 being straight ahead) and 0,-1,0 for 90 to 270

Share this post


Link to post
Share on other sites
Well, I can basically guarantee my camera will roll - (another thing I was going to ask) so in this case what should my Up vector be? I imagine I need to make it something that points off in the direction of the roll.

##UnknownPlayer##

Share this post


Link to post
Share on other sites
in that case: save yourself the trouble and headache and use a matrix, just in case you later decide that your cam needs more than just following an object. store 2 angles and a distance to the object, then set the cam matrix to the matrix for the object your following, rotate around y and x, translate backwards and that should be it.

Share this post


Link to post
Share on other sites
Hmm...ok I'll give that a shot - hope it works because then I can get on to some content (this was one of the last things I wanted to do engine-wise).

But I do have a question - isn't 'translate backwards' somewhat more difficult to do then say since its gotta be relative to the objects forward?

##UnknownPlayer##

[edited by - UnknownPlayer on January 31, 2003 9:09:31 PM]

Share this post


Link to post
Share on other sites
why should it? instead of translating it -x units along (0,0,1) you translate it -x units along its local z-axis (which is the first three elements of the third line of its matrix).

Share this post


Link to post
Share on other sites
So my code would essentially be a thing of ratios i.e. -x gets broken up into x, y, z components for the local z-axis? I''ll gonna give it a shot (plenty about matrix maths I don''t already know).

Share this post


Link to post
Share on other sites
I think I''m doing something similar to what you are. What I have is two static vectors, vDir and vUp, that I transform every frame by the change in Theta (roll) and phi (pitch).


D3DXMatrixRotationAxis (&mTrans, &vDir, dTheta);
D3DXVec3Transform (&vRes, &vUp, &mTrans);
vUp.x = vRes.x; vUp.y = vRes.y; vUp.z = vRes.z;
D3DXVec3Cross (&vRight, &vDir, &vUp);
// vRight = -vRight;
D3DXMatrixRotationAxis (&mTrans, &vRight, dPhi);
D3DXVec3Transform (&vRes, &vDir, &mTrans);
vDir.x = vRes.x; vDir.y = vRes.y; vDir.z = vRes.z;
D3DXVec3Transform (&vRes, &vUp, &mTrans);
vUp.x = vRes.x; vUp.y = vRes.y; vUp.z = vRes.z;
D3DXVec3Cross (&vRight, &vDir, &vUp);

// Create View Matrix
vAt = vPos - (vDir * 20.0f);
D3DXMatrixLookAtLH (&mView, &vAt, &vPos, &vUp);


-Zims

Share this post


Link to post
Share on other sites

  • 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!