Does anyone know how to rotate objects the same as in 3d cad programs, i.e. the axis that you rotate about alters as the 3d image you have is rotated.
i.e. say I have a 3d box, if I move right to left the box rotates around the vertical axis (of the current view, not the box) and up and down it rotates about the horizontal axis (of the view).
you need to “remember” your current transformation matrix in GLfloat mm[16]. you need to initialize mm as identity which is done in the first few lines. you do this ONCE at the beginning of the program.
in the second block you rotate your model around the x and z axis, multiply the current transformation matrix and put the result back into the transformation matrix.
in the third block you use the lookat-function and multiply the current transformation matrix.
you have to call the second and third block everytime you want to rotate your model.
in this example you look at the x-z-plane; if you want to look into another direction, you have to change the rotation axes in the glRotatef calls.