Advertisement

changing rotation center with mouse click

Started by July 14, 2004 04:47 PM
2 comments, last by vincoof 20 years, 4 months ago
Hi there,, I already posted about this on graphics programming forum, but did not get the replies for an answer. So I'm posting here again.. I use gluUnproject and glReadPixel to get depth component for the mouse click. (the click has to be on the object). And I use arcball rotation control, and have transformation matrix that accumulates all the transformations done on the object, which would be multiplied to the modelview matrix before drawing anything. After implementing changing the rotation center, I get my object to get the correct rotation center with a mouse click, but my object changes its position. The reason is I change the transformation matrix for mouse dragging (rotation control) and I do TR(-T)<translate, rotate, translate back> to get final matrix to be multiplied to the modelview matrix. Unless my transform matrix is identity, I figured the object will be moved to different location with different rotation center. But would there exist someways that would solve this problem? So changing rotation would not change object or camera to move to different location. Thanks!!
What do you do for rendering the object ?
Do you call something like that :
glTranslate(-x,-y,-z);glRotate(angle,rx,ry,rz);glTranslate(+x,+y,+z);/* render object ... doesn't look good */


Or do you call something like :
glTranslate(-x,-y,-z);glRotate(angle,rx,ry,rz);/* render object ... looks good */glTranslate(+x,+y,+z);/* render something else, doesn't look good because not in the right place */
Advertisement
Rather than calling gl functions, I just multiply them into one matrix and glMultMatrix with the final one.
This is my rotation dragging code:

if(manip_mode == ROTATE){
TVec4 curr_quat;
ball->mouse_click(last_mouse_pos[0], last_mouse_pos[1]);
ball->mouse_drag(x, y, &curr_quat);
curr_rot.MakeHRot(curr_quat);

TMat4 temp_xf = *curr_xf;

TMat4 tran1(vl_one);
translate_mat(&tran1, rot_center);
TMat4 tran2(vl_one);
TVec3 temp = rot_center * (-1.0f);
translate_mat(&tran2, temp);

#1-> *curr_xf = tran1 * curr_rot * tran2 * temp_xf;
#2-> //*curr_xf = temp_xf * tran1 * curr_rot * tran2;

Fl::redraw();

In here, I use row order matrix so my final matrix which is curr_xf is changed like in #1, or #2. I know #1 is the correct order of multiplying the final matrix, but if I change a rotation center after rotating object, it doesn't move correctly. However, if I do like #2, it moves right, but arcball rotation becoems wrong.
Have any idea?? thx~!!!

p.s. tran1 is translation matrix with positive rotation center. And tran2 is same except negative rotation center translation matrix.
Your equation seems correct. You just want to rotate around a fixed rotation center, isn't it ? No translation ? No scale ?

Then I'm not sure what behaviour you are describing, but it looks correct to me. When the rotation center is far from the object, then obviously you have the feeling that the object moves.

This topic is closed to new replies.

Advertisement