• Advertisement
Sign in to follow this  

Non rotating Polygon

This topic is 4297 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

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?

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Oh. Great. Now I get the concept. But still, my second problem remains unresolved.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement