Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pivot point rotation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Suresh_bd   Members   -  Reputation: 100

Like
0Likes
Like

Posted 09 May 2010 - 07:10 PM

Hi, I am using OpenGL for visualization purpose. Here I am using quaternion for Eye matrix computation. I am planning to extend the rotation for selected pivot point. I used the existing logic, move the model to origin and then apply the rotation matrix and finaly move back to the original position. I am not getting the proper result. The following are code that I used { /* Clear the buffer */ glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); /* Set draw mode Orthographic */ float lhsToRhsMirror[16] = { 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 0.0 , -1.0 , 0.0 , 0.0 , 0.0 , 0.0 , 1.0 }; glMatrixMode ( GL_MODELVIEW ); glLoadIdentity (); glMatrixMode ( GL_PROJECTION ); glLoadIdentity (); glOrtho ( -xdist , xdist , -refDist, refDist, nearP , farP ); glMultMatrixf ( lhsToRhsMirror ); /* Translate the model to origin */ double darrTrgCrds[3]; /* Model original center */ double darrSelPivotPt[3]; /* Selected pivot point */ /* Translate the model in negative direction from original center to selected point */ glTranslated(-(darrTrgCrds[0] - darrSelPivotPt[0]), -(darrTrgCrds[1] - darrSelPivotPt[1]), -(darrTrgCrds[2] - darrSelPivotPt[2])); /* apply model view matrix, prepared using Right direction, up direction, sight direction and eye position */ double darrEye[3]; /* Eye position, usually half of the bounding box diagonal distance along sight direction */ E[ 0] = T[0]; E[ 1] = T[4]; Right direction from quatrenion E[ 2] = T[8]; E[ 3] = 0.0; E[ 4] = T[1]; E[ 5] = T[5]; Up direction from quatrenion E[ 6] = T[9]; E[ 7] = 0.0; E[ 8] = T[2]; E[ 9] = T[6]; sight direction from quatrenion E[10] = T[10]; E[11] = 0.0; E[12] = -T[0]* darrEye[0] - T[1]* darrEye[1] - T[ 2]* darrEye[2]; E[13] = -T[4]* darrEye[0] - T[5]* darrEye[1] - T[ 6]* darrEye[2]; E[14] = -T[8]* darrEye[0] - T[9]* darrEye[1] - T[10]* darrEye[2]; E[15] = 1.0; /* Multiply the prepared model view matirx */ glMatrixMode ( GL_MODELVIEW ); glLoadIdentity (); glMultMatrixd ( E ); /* Move back to the original origin, model center */ glTranslated((darrTrgCrds[0] - darrSelPivotPt[0]), (darrTrgCrds[1] - darrSelPivotPt[1]), (darrTrgCrds[2] - darrSelPivotPt[2])); /* Draw actual content */ Could any one help me to locate the proplem Thanks

Sponsor:

#2 zer0sum   Members   -  Reputation: 100

Like
0Likes
Like

Posted 11 May 2010 - 02:32 PM

There is a lot of code here that is funky to read. Try using the code tag which is [ code ] paste stuff [ /code ] to give us more readable code.

Generally, to rotate around a point, all you need to do is glTranslatef to the pivot point, do your glRotatef(angle,x, y, z), then undo your glTranslatef back to your drawing position, draw the item, then translate back to the pivot point, do a glRotatef(-angle,x,y,z), and then finally translate back to drawing point.

Ya dig?

#3 scgames   Members   -  Reputation: 1969

Like
0Likes
Like

Posted 11 May 2010 - 04:10 PM

Quote:
Original post by zer0sum
Try using the code tag which is [ code ] paste stuff [ /code ] to give us more readable code
[source][/source] would probably be better ('source' gives you a nice scrollable code box with syntax highlighting, while 'code', I believe, only preserves whitespace and gives you a monospace font).

#4 Suresh_bd   Members   -  Reputation: 100

Like
0Likes
Like

Posted 11 May 2010 - 05:56 PM

Sorry for posted code.

Basically I am preparing modelview matrix to view the model. To prepare a matrix, I am using eye position, right, sight and up direction.

When I use this matrix, it is always rotating about the screen center, but I palnning to rotate about specific center.

To do that, In my code, before applying the matrix, I have translated the model using "glTranslated" to specific point, then apply the matrix and then bring it back to the original position.

firts time, It is rotating about the center, but model is moving form its original position. Second time onwards, it is not working based on given specific point.

Is the way am I following is correct?.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS