i got a question regarding multiple objects drawn using push/ pop stack.something similar to this.
开发者_开发技巧
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(x,y,z);
glRotate(r,1,0,0);
glTranslate(-x,-y,-z);
for (i=0 to 20) objects
glpushMatrix();
draw_object()
glpopMatrix();
end
each object is a unit circle with its own transformation. In such a case how does ray picking work. How should i keep track of center point of the object to calculate ray intersection. i really appreciate any help.
You can get the current matrix for the each object:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(x,y,z);
glRotate(r,1,0,0);
glTranslate(-x,-y,-z);
for (i=0 to 20) objects
glpushMatrix();
... some matrix transformations specific for the object
... and get the final matrix and store it to object member
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&object->modelMatrix);
draw_object()
glpopMatrix();
When doing ray intersection just multiply the object matrix with local center point coordinate to get it in absolute space where ray is defined.
精彩评论