Non rotating Polygon

Started by
3 comments, last by vivekd 17 years, 11 months ago
Is there any direct means by which I can have the Polygon facing always towards the user, despite applying any rotation to it? I am having a big scene rendered. Using my mouse and keys I should be able to rotate the scene. Currently I do that by aplying glRotate() to the entire scene, using 3 different glRotate() calls (one for x-axis, one for y-axis and one for z-axis). I have some polyongs in this scene. When I rotate the scene, I want the polygons facing towards the user. Is there any provision for this to be done?
Advertisement
What you need to do is apply your rotations as you normally would, then when you want to render the front-facing polygons, copy the modelview matrix, reset the x and y rotation parts of the matrix to the ones you'd find in the identity matrix, load that matrix, and render the polygons as needed. In code:

  glPushMatrix();  GLfloat matrix[16];  glGetFloatv(GL_MODELVIEW_MATRIX,matrix);  matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f;//x  matrix[4] = 0.0f; matrix[5] = 1.0f; matrix[6] = 0.0f;//y  glLoadMatrixf(matrix);    //render them here    glPopMatrix();
Wonderful. Thanks Gorax. I tried it. It worked very close to what was desired. But I had a doubt. The matrix you've given is:
matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f;//x
matrix[4] = 0.0f; matrix[5] = 1.0f; matrix[6] = 0.0f;//y

I can't see see the 4th index, i.e. matrix[3]. Is it supposed to be:
matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f;//x
matrix[3] = 0.0f; matrix[4] = 1.0f; matrix[5] = 0.0f;//y

Moreover, it works fine when I rotate it horizontally. But when taken an upper view of the scene, the polygons fail to face the user.
Gorax gave you the right matrix there. remember it is a 4x4 matrix, not a 3x3!
Oh. Great. Now I get the concept. But still, my second problem remains unresolved.

This topic is closed to new replies.

Advertisement