Skip to main content
GameDev.net gamedev.net
🔒 Locked

3D camera vectors

Started by Zosimas Oct 9, 2010 at 8:45 PM 7 replies 1.5k views
Original Post
Zosimas
Zosimas
I made a 3d camera class like the one in: toymaker.info

and I read that thread too: Understanding 3D camera better

Now, the question is how am I going to extract the real Look, Up, and Right vectors from the final viewMatrix?

And I say real because the only vector that is set by the user is the Position vector and the other three vectors (Look, Up, Right) are calculated programmatically as unit vectors and not at the real world space[attention]
Molle85
Molle85
Take a look at how the D3DXMatrixLookAtLH/RH function works and it should become very clear how you can extract them.
Zosimas
Zosimas
The formula for D3DXMatrixLookAtLH is this:
zaxis = normal(At - Eye)xaxis = normal(cross(Up, zaxis))yaxis = cross(zaxis, xaxis)     xaxis.x           yaxis.x           zaxis.x          0 xaxis.y           yaxis.y           zaxis.y          0 xaxis.z           yaxis.z           zaxis.z          0-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  1

Now, this code returns a ViewMatrix. I want to do the reverse job.
How can I extract from this ViewMatrix the original Eye, At and Up vectors that I used to create it?
Zakwayda
Zakwayda
Quote:
Original post by Zosimas
The formula for D3DXMatrixLookAtLH is this:
zaxis = normal(At - Eye)xaxis = normal(cross(Up, zaxis))yaxis = cross(zaxis, xaxis)     xaxis.x           yaxis.x           zaxis.x          0 xaxis.y           yaxis.y           zaxis.y          0 xaxis.z           yaxis.z           zaxis.z          0-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  1

Now, this code returns a ViewMatrix. I want to do the reverse job.
How can I extract from this ViewMatrix the original Eye, At and Up vectors that I used to create it?
The vectors you're looking for can be found in the matrix shown above; they're the columns of the upper-left 3x3 portion of the matrix.

But, if you created the transform yourself from 'eye', 'at', and 'up' vectors, don't you already have these vectors?
Zosimas
Zosimas
No, I don't have these vectors. If you see my first comment it refers to a camera system at toymaker.info that uses only the position of the eye, and calculates Right, Look and Up vectors from the rotation. Of course these vectors are normalized and thats the problem!
I use this camera class in a project, and I want to get these three vectors for another reason in my project, but I can't!
Zakwayda
Zakwayda
Quote:
No, I don't have these vectors.
I can almost guarantee that you do.
Quote:
If you see my first comment it refers to a camera system at toymaker.info that uses only the position of the eye, and calculates Right, Look and Up vectors from the rotation.
Yes, I looked at the tutorial. As soon as the code listed in the section titled 'Roll rotation' has executed, you have the vectors you're looking for; they are the 'right', 'up', and 'look' vectors.
Quote:
Of course these vectors are normalized and thats the problem!
Why is that a problem? Direction vectors are *usually* normalized.
Quote:
I use this camera class in a project, and I want to get these three vectors for another reason in my project, but I can't!
Sure you can :) They're already available to you (as described above), plus, you can extract them from the view matrix as I described earlier (which is basically pointless, but you can certainly do it that way if you want).

There seems to be some misunderstanding somewhere, either on your part or on ours. If the above still doesn't answer your question, perhaps you could describe in more detail why you think the 'right', 'up', and 'forward' vectors aren't the vectors you're looking for.
Zosimas
Zosimas
Quote:
Quote:
Of course these vectors are normalized and thats the problem!
Why is that a problem? Direction vectors are *usually* normalized.


The problem is that I don't want a Direction vector but a Position vector.

Suposing that the LookAt vector that the viewMatrix returns came from this:
zaxis = normal(At - Eye)

do you think that this is going to solve my problem:
LookAtPosition = Eye + zaxis
???

Zakwayda
Zakwayda
You can't get the original 'at' point back, but yes, eye + zAxis will give you a valid 'at' point.

As for the 'eye' point (the camera position), you can get that be 'un-inverting' that part of the matrix (I can post some code for this if you need it).

That said, I am really curious as to why you need to do this. Why do you need to extract the eye, at, and up vectors from a view matrix that's already been constructed? What do you need them for?
Zosimas
Zosimas
Quote:

As for the 'eye' point (the camera position), you can get that be 'un-inverting' that part of the matrix (I can post some code for this if you need it).

I don't understand what you mean but fortunately the eye position is something that I don't have to extract because I have the original. If you mean something else please post the code.

Quote:
That said, I am really curious as to why you need to do this. Why do you need to extract the eye, at, and up vectors from a view matrix that's already been constructed? What do you need them for?


I'm using this camera class in my project to move in space and I also create a water effect in a plane. So, I have to construct the reflectionViewMatrix at every frame to render the scene to a texture as reflected.
To construct this reflectionViewMatrix I need the original Eye, LookAt, Up, Right vectors. I tried to use the extracted vectors from the viewMatrix but it doesn't work right. Conversely it works fine if I have the original vectors.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.