PDA

View Full Version : Getting normal after rotation?



07-10-2002, 10:48 PM
Hi,

how do I determine the normal of a plane/rectangle after glRotatef?

Lets say I have a rectangle with a normal-vector of (0,0,1). Now I perform a glRotatef(55,0,1,0). How do I get the "new" normal? Are there any Ogl functions or do I have some mathematics??

Greets, Heiko

Gavin
07-11-2002, 01:18 AM
Hmmm, OpenGL doesn;t have functions that return those results if thats what your asking. But it does sort out all the normal stuff for you (or can rather). Do ytou explicityly need the normal for some othjer calculations? Well anyway I can think of a way of doing it, its simple, but a little long winded, I am sure that there are simpler ways by converting the rot into a matrix

07-11-2002, 02:24 AM
Well, yes I need it for other things... *g I have a rectangle displaying a person and I want that person to move into its "looking-direction"... and because that person always looks (just imagine a photograph pasted as a texture) into the direction of the normalvector i need to calculate this...

coredump
07-11-2002, 03:38 AM
to find the normal you need 3 points on the plane (p0, p1, p2). use these points to make 2 vectors: v0 = (p1 - p0); v1 = (p2 - p0); and your normal is defined as: v0 X v1 (cross product). as for after the rotation, try multiplying the normal by the modelview matrix.

b

[This message has been edited by coredump (edited 07-11-2002).]

07-11-2002, 05:19 AM
Use this:
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated(Center of Rotation);

glRotated(rotationx,1,0,0);
glRotated(rotationy,0,1,0);
glRotated(rotationz,0,0,1);
glTranslated(-Center of Rotation);

DrawYourScene (You keep your usual coordinates of everything)

glPopMatrix();

It works=)