Sign in to follow this  

Simple Matrix Question

This topic is 4196 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 looked this up but I wanted to double check with you guys: The camera position in object space is the 4th column of the modelview matrix. is that correct? If not... what is?

Share this post


Link to post
Share on other sites
Quote:
Original post by AtmaWeapon
I looked this up but I wanted to double check with you guys:

The camera position in object space is the 4th column of the modelview matrix.

is that correct? If not... what is?
Since you mention 'modelview' I'm assuming OpenGL here. In any case the answer is no, that's not correct. The 4th column does contain the translation for the modelview matrix, but it's not the camera position.

The first reason for this is that the modelview matrix may contain any number of concatenated transforms, usually only one of which is related to the camera position. In general, there's no way to extract the camera position from the modelview matrix unless you know exactly what individual transforms went into it and in what order.

The second reason is that even if the modelview matrix is known to only contain the view transform, it's actually inverted relative to the 'actual' camera position and orientation. It is possible though to extract the camera position from a view-only modelview matrix (just not directly).

[Edit: I see now you asked about the camera position 'in object space'. Depending on what you mean by this, my above answer may not be completely relevant.]

Share this post


Link to post
Share on other sites
Thanks a bunch. I'm using OpenGL and yes it is the camera position in object space. But in the end, all I really need is the camera vector. Isn't this just the inverse model view matrix multiplied by the vertex position?

In other words in my shader I would have mul(invModelView, vertexPos)

Share this post


Link to post
Share on other sites
Quote:
Original post by AtmaWeapon
But in the end, all I really need is the camera vector. Isn't this just the inverse model view matrix multiplied by the vertex position?

In that case, the first reason in jyk's reply is totally relevant, and the answer to your question is no. In your case, you must pass two matrices (model and view, or model-view and view, or model-view and camera) separately to the shader. But why do you need to know the camera's position in the shader?

Share this post


Link to post
Share on other sites
Quote:

In that case, the first reason in jyk's reply is totally relevant, and the answer to your question is no. In your case, you must pass two matrices (model and view, or model-view and view, or model-view and camera) separately to the shader. But why do you need to know the camera's position in the shader?


The camera vector is the view vector. This needed for many things from reflections, phong shading, etc. So why do I need seperate model-view and view matrices. Could elaborate more what you mean. Isn't model view just mul(model, view)

Share this post


Link to post
Share on other sites

This topic is 4196 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this