开发者

how can I retrieve the current position of the vertices after they have been transformed?

开发者 https://www.devze.com 2022-12-12 17:30 出处:网络
How can I retrieve the current position of the vertices after they have been transformed? I have the followi开发者_运维百科ng code....

How can I retrieve the current position of the vertices after they have been transformed? I have the followi开发者_运维百科ng code....

How can I get the position of the "modelVertices" after the transform has been applied?

I am really after the screen coordinates so I can tell if a vert has been clicked by the mouse.


glMatrixMode(GL_MODELVIEW);

// save model transform matrix
GLfloat currentModelMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, currentModelMatrix);

// clear the model transform matrix
glLoadIdentity();

// rotate the x and y axis of the model transform matrix
glRotatef(rotateX, 1.0f, 0.0f, 0.0f);
glRotatef(rotateY, 0.0f, 1.0f, 0.0f);

// reapply the previous transforms
glMultMatrixf(currentModelMatrix);

glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

// since each vertes is defined in 3D instead of 2D parameter one has been 
// upped from 2 to 3 to respect this change.
glVertexPointer(3, GL_FLOAT, 0, modelVertices);
glEnableClientState(GL_VERTEX_ARRAY);


GLU has the function gluProject() and gluUnProject():

http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml

If your platform doesn't have GLU you can always grab the code for MESA and see how it is implemented.


You could use the feedback buffer.

0

精彩评论

暂无评论...
验证码 换一张
取 消