PDA

View Full Version : Screen Rotation



10-25-2002, 07:03 PM
I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

Many thanks

harsher
10-26-2002, 01:09 AM
Originally posted by Dave Smith:
I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

Many thanks

use gluOrtho to set the view to the origin or use translate

10-26-2002, 08:10 AM
Can you expand on this please


Thank you


Originally posted by harsher:
use gluOrtho to set the view to the origin or use translate

delic
10-26-2002, 11:40 AM
I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

I will reply back when I get it working..

Anyone post some help if you have done this..

Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

[This message has been edited by delic (edited 10-26-2002).]

[This message has been edited by delic (edited 10-26-2002).]

10-27-2002, 12:36 AM
I think this might be the solution. I will try to implement this

Thank you for the info. Will kep you posted.



Originally posted by delic:
I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

I will reply back when I get it working..

Anyone post some help if you have done this..

Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

[This message has been edited by delic (edited 10-26-2002).]

[This message has been edited by delic (edited 10-26-2002).]

10-28-2002, 12:55 AM
I have tried to use the GluLookat but it still does not work.

I have thought of using the GluUnproject to determine where the screenX and ScreenY transforms into the object 3D coordinates. But this requires that the transformation be done using incremental mode rather than absolute mode.



Originally posted by delic:
I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

I will reply back when I get it working..

Anyone post some help if you have done this..

Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

[This message has been edited by delic (edited 10-26-2002).]

[This message has been edited by delic (edited 10-26-2002).]

nexusone
10-28-2002, 06:30 AM
The order in which you translate/rotate make a big diffrence.


example 1:

glTranslatef( 0.0, 0.0, -1.0);
glRotatef( 15, 0.0, 1.0, 0.0);
Draw_sphere(); // effect on sphere is first rotated 15 degrees and then move to -1 on the y-axis.

example 2:
glRotatef(15, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, 1.0);
Draw_sphere(); // effect on sphere is first translated out to the -1 y-axis, then rotated 15 degrees. But now since all rotations take place from the openGL origin, the sphere is rotated as if it was in orbit around the origin. Which would be translated out -1, then moved in a arc 15 degrees.


Originally posted by Dave Smith:
I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

Many thanks

delic
10-28-2002, 08:51 AM
Dave Im not exactly sure if we were doing the same thing but I asccomplished what I was after.. In a nut shell you have to continually update your current screen upvector (y) and rgightvector (x)as you rotate around. I post the orientation code below:

void getAxes(GLfloat upvect[3],GLfloat rgtvect[3],GLfloat outvect[3] )
{
GLfloat curModmatrix[4][4],curProjmatrix[4][4];
glGetFloatv(GL_MODELVIEW_MATRIX,&curModmatrix[0][0]);
glGetFloatv(GL_PROJECTION_MATRIX,&curProjmatrix[0][0]);
GLfloat tempvect[3];

tempvect[0] = rgtvect[0];
tempvect[1] = rgtvect[1];
tempvect[2] = rgtvect[2];
rgtvect[0] = curModmatrix[0][0]*rgtvect[0] + curModmatrix[0][1]*rgtvect[1] + curModmatrix[0][2]*rgtvect[2];
rgtvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*rgtvect[1] + curModmatrix[1][2]*rgtvect[2];
rgtvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*rgtvect[2];
tempvect[0] = rgtvect[0];
tempvect[1] = rgtvect[1];
tempvect[2] = rgtvect[2];
rgtvect[0] = curProjmatrix[0][0]*rgtvect[0] + curProjmatrix[0][1]*rgtvect[1] + curProjmatrix[0][2]*rgtvect[2];
rgtvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*rgtvect[1] + curProjmatrix[1][2]*rgtvect[2];
rgtvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*rgtvect[2];


tempvect[0] = upvect[0];
tempvect[1] = upvect[1];
tempvect[2] = upvect[2];
upvect[0] = curModmatrix[0][0]*upvect[0] + curModmatrix[0][1]*upvect[1] + curModmatrix[0][2]*upvect[2];
upvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*upvect[1] + curModmatrix[1][2]*upvect[2];
upvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*upvect[2];
tempvect[0] = upvect[0];
tempvect[1] = upvect[1];
tempvect[2] = upvect[2];
upvect[0] = curProjmatrix[0][0]*upvect[0] + curProjmatrix[0][1]*upvect[1] + curProjmatrix[0][2]*upvect[2];
upvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*upvect[1] + curProjmatrix[1][2]*upvect[2];
upvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*upvect[2];


tempvect[0] = outvect[0];
tempvect[1] = outvect[1];
tempvect[2] = outvect[2];
outvect[0] = curModmatrix[0][0]*outvect[0] + curModmatrix[0][1]*outvect[1] + curModmatrix[0][2]*outvect[2];
outvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*outvect[1] + curModmatrix[1][2]*outvect[2];
outvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*outvect[2];
tempvect[0] = outvect[0];
tempvect[1] = outvect[1];
tempvect[2] = outvect[2];
outvect[0] = curProjmatrix[0][0]*outvect[0] + curProjmatrix[0][1]*outvect[1] + curProjmatrix[0][2]*outvect[2];
outvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*outvect[1] + curProjmatrix[1][2]*outvect[2];
outvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*outvect[2];
}

[This message has been edited by delic (edited 10-29-2002).]

10-30-2002, 12:13 AM
Many thanks for your help


Originally posted by delic:
Dave Im not exactly sure if we were doing the same thing but I asccomplished what I was after.. In a nut shell you have to continually update your current screen upvector (y) and rgightvector (x)as you rotate around. I post the orientation code below:

void getAxes(GLfloat upvect[3],GLfloat rgtvect[3],GLfloat outvect[3] )
{
GLfloat curModmatrix[4][4],curProjmatrix[4][4];
glGetFloatv(GL_MODELVIEW_MATRIX,&curModmatrix[0][0]);
glGetFloatv(GL_PROJECTION_MATRIX,&curProjmatrix[0][0]);
GLfloat tempvect[3];

tempvect[0] = rgtvect[0];
tempvect[1] = rgtvect[1];
tempvect[2] = rgtvect[2];
rgtvect[0] = curModmatrix[0][0]*rgtvect[0] + curModmatrix[0][1]*rgtvect[1] + curModmatrix[0][2]*rgtvect[2];
rgtvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*rgtvect[1] + curModmatrix[1][2]*rgtvect[2];
rgtvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*rgtvect[2];
tempvect[0] = rgtvect[0];
tempvect[1] = rgtvect[1];
tempvect[2] = rgtvect[2];
rgtvect[0] = curProjmatrix[0][0]*rgtvect[0] + curProjmatrix[0][1]*rgtvect[1] + curProjmatrix[0][2]*rgtvect[2];
rgtvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*rgtvect[1] + curProjmatrix[1][2]*rgtvect[2];
rgtvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*rgtvect[2];


tempvect[0] = upvect[0];
tempvect[1] = upvect[1];
tempvect[2] = upvect[2];
upvect[0] = curModmatrix[0][0]*upvect[0] + curModmatrix[0][1]*upvect[1] + curModmatrix[0][2]*upvect[2];
upvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*upvect[1] + curModmatrix[1][2]*upvect[2];
upvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*upvect[2];
tempvect[0] = upvect[0];
tempvect[1] = upvect[1];
tempvect[2] = upvect[2];
upvect[0] = curProjmatrix[0][0]*upvect[0] + curProjmatrix[0][1]*upvect[1] + curProjmatrix[0][2]*upvect[2];
upvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*upvect[1] + curProjmatrix[1][2]*upvect[2];
upvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*upvect[2];


tempvect[0] = outvect[0];
tempvect[1] = outvect[1];
tempvect[2] = outvect[2];
outvect[0] = curModmatrix[0][0]*outvect[0] + curModmatrix[0][1]*outvect[1] + curModmatrix[0][2]*outvect[2];
outvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*outvect[1] + curModmatrix[1][2]*outvect[2];
outvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*outvect[2];
tempvect[0] = outvect[0];
tempvect[1] = outvect[1];
tempvect[2] = outvect[2];
outvect[0] = curProjmatrix[0][0]*outvect[0] + curProjmatrix[0][1]*outvect[1] + curProjmatrix[0][2]*outvect[2];
outvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*outvect[1] + curProjmatrix[1][2]*outvect[2];
outvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*outvect[2];
}

[This message has been edited by delic (edited 10-29-2002).]