Ok, I tried doing what was suggested and negated the pivot point, then translated the coord system to it, rotated, and then restored the pivot and translated again. Then I translate to the object’s pivot-relative position. But it doesn’t do what it’s supposed to
Here’s my code;
/* Draw an object */
glLoadIdentity();
/* Negate pivot point. */
object.pivot[x] = -object.pivot[x];
object.pivot[y] = -object.pivot[y];
object.pivot[z] = -object.pivot[z];
/* Move to inverse pivot */
glTranslatef(object.pivot[x],object.pivot[y],object.pivot[z]);
/* Rotate coordinate system */
glRotatef(object.angle,object.axis[x],object.axis[y],object.axis[z]);
/* Undo changes to pivot point */
object.pivot[x] = -object.pivot[x];
object.pivot[y] = -object.pivot[y];
object.pivot[z] = -object.pivot[z];
/* Move to regular pivot point */
glTranslatef(object.pivot[x],object.pivot[y],object.pivot[z]);
/* Get pivot-relative position coordinates */
temp[x] = object.pivot[x] - object.pos[x];
temp[y] = object.pivot[y] - object.pos[y];
temp[z] = object.pivot[z] - object.pos[z];
/* Position rotated object */
glTranslatef(temp[x],temp[y],temp[z]);
draw_object();
Note that:
object.pivot = {5.0, 0.0, 100.0}
object.pos = {0.0, 0.0, 100.0}
So pivot - pos = {5.0, 0.0, 0.0}, which is where I position the object at so its position is relative to the pivot point.
However, the object appears at position {5.0, 0.0, 0.0}
I want it to be positioned at {0.0, 0.0, 100.0}, then rotate around {5.0, 0.0, 100.0}.
I can’t translate the vertices of objects relative to a pivot point before transformation, because the pivot point is to be dynamic in my program. (for physics) It would just be very slow looping through all the vertices in the scene and applying a translation to them every time the pivot point is changed, which is probably every frame. T&L does a better job.