shoosh
shoosh

Reputation: 78914

OpenGL: Multiple user vector by modelview matrix?

Is there a way to make OpenGL transform a general vector I give it with the current modelview matrix and get the result back?

The obvious way is to query the modelview matrix and do the multiplication myself but I am almost sure there should be a way to make OpenGL do this for me.

Upvotes: 7

Views: 6056

Answers (4)

luke
luke

Reputation: 14788

The reason why opengl probably won't just do this for you is because the calculation isn't part of the rendering pipeline. and opengl (for the most part) only performs calculations during the display loop. So it doesn't make sense to provide these kind of synchronous interfaces.

Upvotes: -1

Maurice Gilden
Maurice Gilden

Reputation: 1954

It's probably best to do the transformations on the CPU side. The only other way I can think of is to use EXT_transform_feedback plus a vertex shader that does only the modelview transformations.

Upvotes: 0

Judge Maygarden
Judge Maygarden

Reputation: 27583

It is best to do the calculation outside of OpenGL. The Matrix and Quaternions FAQ is a good resource for learning how to perform the calculations if you do not know already. You fetch the 4x4 model-view matrix as follows

float modelview[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);

Upvotes: 4

Marco M.
Marco M.

Reputation: 252

You are right, you have to get the modelview matrix and transform the vector yourself.

For a confirm, see this link at paragraph 9.120.

Upvotes: 5

Related Questions