PDA

View Full Version : Track coordinates of a vertex after glRotatef()



2door
04-12-2011, 11:36 AM
Hello, I am new here and to OpenGL. I am in the process of making a 3D rig. The idea is to have bones that are connected and respond to rotations. The rig will have no rotation constraints, just position constraints (meaning that a bone's origin depends on its parent').

That said, the only problem I have is with using the glRotatef function. I want to pass a point through that function's transformation and have it rotated. Here is the code:

glPushMatrix();
glRotatef(2* acos(bone->rotation.s) * 180 / 3.1415f, bone->rotation.v.x,bone->rotation.v.z,-bone->rotation.v.y);

glBegin(GL_TRIANGLES);
glColor4ub(255,0,0,155);
glVertex3f(0,0,0);
glVertex3f(0.15,-0.15,0.3);
glVertex3f(-0.15,-0.15,0.3);

glVertex3f(0,0,0);
glVertex3f(0.15,0.15,0.3);
glVertex3f(-0.15,0.15,0.3);

glVertex3f(0,0, bone->length);
glVertex3f(0.15,0.15,0.3);
glVertex3f(0.15,-0.15,0.3);

glVertex3f(0,0, bone->length);
glVertex3f(-0.15,-0.15,0.3);
glVertex3f(-0.15,0.15,0.3);

glColor4ub(200,200,200,155);
glVertex3f(0,0,0);
glVertex3f(0.15,0.15,0.3);
glVertex3f(0.15,-0.15,0.3);

glVertex3f(0,0,0);
glVertex3f(-0.15,-0.15,0.3);
glVertex3f(-0.15,0.15,0.3);

glVertex3f(0,0, bone->length);
glVertex3f(0.15,-0.15,0.3);
glVertex3f(-0.15,-0.15,0.3);

glVertex3f(0,0, bone->length); // << how to track its modified coordinate at the end of this method.
glVertex3f(0.15,0.15,0.3);
glVertex3f(-0.15,0.15,0.3);

glEnd();
glPopMatrix();

I would like to know the glVertex3f (or some other point object) coordinate after the transformation.

- Thanks a bunch :)