Sign in to follow this  
vivekd

Non rotating Polygon

Recommended Posts

vivekd    128
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
Gorax    202
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
vivekd    128
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this