Apply rotation to a single vertex

I have an object that rotates around it's origin. I want to be able to apply the rotation to a single vertex to figure out what the new vertex is.

Basically, I pick a vertex that is connected to another object that could be anywhere in the object, and want to find out where to move it in order for them to be connected at that same spot again after the rotation.

I understand matrix math, but either I'm doing it wrong or I am ... doing it really wrong.

Let me just use an example...

in my modelchain class, there is a vertex called jointVertex, which is a vertex that could be located anywhere on the object, depending on where it's connected to it's parent. I also have variables called xRot, yRot, and zRot which are the angles which the object should be rotated.

When I draw it, I call glRotatef and draw it. Obviously, this just rotates it around the origin and it detaches itself from the parent at that vertex. I need to take this vertex, jointVertex, and perform a calculation on it based on how much the object was rotated in order to find out where that vertex is after the rotation. Then I can translate the object to a place where the jointVertex is in it's original location and the model is essential "hanging" from that vertex after the rotation.

LongJumper Wrote:I understand matrix math, but either I'm doing it wrong or I am ... doing it really wrong.

Let me just use an example...

in my modelchain class, there is a vertex called jointVertex, which is a vertex that could be located anywhere on the object, depending on where it's connected to it's parent. I also have variables called xRot, yRot, and zRot which are the angles which the object should be rotated.

When I draw it, I call glRotatef and draw it. Obviously, this just rotates it around the origin and it detaches itself from the parent at that vertex. I need to take this vertex, jointVertex, and perform a calculation on it based on how much the object was rotated in order to find out where that vertex is after the rotation. Then I can translate the object to a place where the jointVertex is in it's original location and the model is essential "hanging" from that vertex after the rotation.

Ah, now thats not too bad...

Code:

glTranslatef(-center_vertex.x, -center_vertex.y, -center_vertex.z);//Move object so that vertex you want to rotate about is at 0, 0, 0...
glRotatef();//perform rotation
glTranslatef( center_vertex.x, center_vertex.y, center_vertex.z);//Return object to original position

I have a figure I created in poser, broken up into important limbs(at least important to what I am doing). Now, when I load it in with your obj loader, I call a function I created called DropToGround, which basically puts the center point of every single limb at 0,0,0. Here is where I do my rotations, so that they are properly rotated around their origin instead of the circle that Poser creates.

So now, if I translate back to it's original position(which I have retained), the object is rotated properly, but it is not connected to the body as it should be. In order to account for this, when the object is loaded and attached to a parent(say, left shoulder to the torso), it finds every single vertex that the torso and left shoulder share. These are my shared vertices.

In order to keep the person "together", I've selected one of the shared vertices to be the joint vertex. This joint vertex is where the two objects always touch, and they are picked in a way to prevent skewing. As an example, the thigh and calf connect behind the knee, so that when I bend it and reconnect the two objects, I can draw extra triangle strips to draw the knee, while the back of the knee is just a straight connection.

The problem is this, however, when I rotate my object about it's origin, the joint vertex has obviously been moved a small amount. Example, if I rotated -45 degrees, the joint vertex of the left shoulder, which is on the left edge of the left shoulder, the joint vertex would be moved up and to the right some. ( Here is bicep before rotation: - , here is bicep after rotation: \ )

What I need to find is where the joint vertex has been moved after rotation, because then I can simply take the difference of where the joint vertex is on the torso that the left shoulder is supposed to append to and the new location of the joint vertex on the arm, and translate it to that new position.

What I was thinking was, there was some way to apply the rotation matrix to a single vertex in order to find it's new coordinates.

and I assume that instead of sending the vertex to the OpenGL pipeline, you want to just figure out where it's going to be transformed to. You can get the matrix with glGetDoublev(GL_MODELVIEW_MATRIX, your matrix). So it'd be something like this:

These are some code snippets from my transformation matrix library. It allows you to perform axis angle rotations just like opengl. I've left the other types of tranforms (translate, rotate) out since they are trivial to implement, however the matrices in this code are transposed from how opengl stores them; so if you want to multiply the modelview matrix with one you generate from this code for some odd reason, remember to transpose it first.

But anyways, now that its working there is potential for lots of optimisation there. For example, a full 4x4 matrix multiply by the identity matrix is a silly thing to do if all you'll ever be doing is a single rotation with no other transformations.