
Rotate with Mouse Movement
Hi!
I have a problem. I want to rotate an object with mouse-movement. It''s working, but just with the X-, and Y-axe. so if I move my mouse to the left or right, the object rotates the Y-axe, and so on...
but i also want to rotate the Z-axe. I got no idea. this is a part (2 functions) of my current code:
1.
void TFrMain::MyResize(float aspect, float dimmax, float sf, float sx, float sy)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(!ortho) gluPerspective(pangle, aspect, 0.1, 10000.0);
if(ortho) glOrtho((-dimmax/sf)*sx,(dimmax/sf)*sx, (-dimmax/sf)*sy, (dimmax/sf)*sy, -10000, 10000);
}
2.
...
..
.
wm = FrMain->ClientWidth;
hm = FrMain->ClientHeight;
glViewport(0,0,wm,hm); /* Establish viewing area to cover entire window. */
if(WindowResize||SystemStart) MyResize(aspect, dimmax, sf, sx, sy);
if(readyToDraw) {
readyToDraw = false; // neuer Durchlauf hat begonnen
if(WindowResize == false||SystemStart == false)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
gluLookAt(keylr, keyud, dimz, // hier stehe ich
0, 0, 0, // hier schaue ich hin
0, 1, 0); // dieser Vektor zeigt senkrecht nach oben
glPushMatrix();
glTranslatef(xslide/pfa, yslide/pfa,-(2*dimz));
glScalef(yzoom/sdiv, yzoom/sdiv, yzoom/sdiv);
glPointSize(pointsize); //Punktdicke
glRotatef(anglex, 1, 0, 0);
glRotatef(angley, 0, 1, 0);
Label1->Caption = anglex;
Label2->Caption = angley;
/*Objekte einlesen / zeichnen*/
DrawScene();
CrissCross(dimmax, yzoom/sdiv);
glPopMatrix();
readyToDraw = true;
} // Durchlauf beendet
...
..
.
I''m from germany, so don''t care about the comments
Do you have any idea?
Thx
Laird

sorry, but that doesn''t help me. the tutorial uses a camera class, which i can''t involve into my project. i need to do it just with OpenGl, I guess I have to use gluLookAt and glRotate, but I have no idea how :-)
but thanks for now...
but thanks for now...
Read the NeHe tutorials, and you will learn what glRotate, glTranslate, and gluLookAt do...
Hi!
It doesn''t work yet. I tried a lot, but nochthing works. This is my last code:
if(mbRotation)
{
glPushMatrix();
glTranslatef(0, 0,-(2*dimz+(keyz/pfa)));
glGetFloatv(GL_MODELVIEW_MATRIX, _m1);
glTranslatef(xslide/pfa, yslide/pfa, 0);
glScalef(yzoom/sdiv, yzoom/sdiv, yzoom/sdiv);
glPointSize(pointsize); //Punktdicke
glLoadIdentity();
glRotatef(anglex, 1, 0, 0);
glRotatef(angley, 0, 1, 0);
//ModelTransform();
mbRotation = false;
// Apply the current transforms
glMultMatrixf( _m1 );
// And keep the modified transform matrix
glGetFloatv( GL_MODELVIEW_MATRIX, _m1 );
glPopMatrix();
}
_m1 is the array [16]. why does this code not work? it rotates wrong. It''s the same problem...
I hope you could help me? Thanks for now...
Laird
It doesn''t work yet. I tried a lot, but nochthing works. This is my last code:
if(mbRotation)
{
glPushMatrix();
glTranslatef(0, 0,-(2*dimz+(keyz/pfa)));
glGetFloatv(GL_MODELVIEW_MATRIX, _m1);
glTranslatef(xslide/pfa, yslide/pfa, 0);
glScalef(yzoom/sdiv, yzoom/sdiv, yzoom/sdiv);
glPointSize(pointsize); //Punktdicke
glLoadIdentity();
glRotatef(anglex, 1, 0, 0);
glRotatef(angley, 0, 1, 0);
//ModelTransform();
mbRotation = false;
// Apply the current transforms
glMultMatrixf( _m1 );
// And keep the modified transform matrix
glGetFloatv( GL_MODELVIEW_MATRIX, _m1 );
glPopMatrix();
}
_m1 is the array [16]. why does this code not work? it rotates wrong. It''s the same problem...
I hope you could help me? Thanks for now...
Laird
I don't know... where's the difficult thing? Please tell me something, I am surely misunderstanding the question and your replies!
You cannot get input for three axes from mouse becouse mouse movements are **bidimensional**. You usually move the mouse on a plane, don't you?
There are two ways to do what you want:
1- Rotation to one axis is replicated to the other. Bad, in my opinion.
2- You usually rotate on X,Y. If left mouse button is pressed, you rotate in Z,Y, or something like this.
This is not GL related, not tutorial related... this is **real world related**. I guess there are no tutorials on the net which explains to you how to rotate around three axis with just two inputs.
Does someone have a three-dimensional mouse? It sould be sphere-like,I know for sure they exist!
EDIT: already forgot additions. Whoops!
[edited by - Krohm on May 26, 2003 3:02:31 PM]
You cannot get input for three axes from mouse becouse mouse movements are **bidimensional**. You usually move the mouse on a plane, don't you?
There are two ways to do what you want:
1- Rotation to one axis is replicated to the other. Bad, in my opinion.
2- You usually rotate on X,Y. If left mouse button is pressed, you rotate in Z,Y, or something like this.
This is not GL related, not tutorial related... this is **real world related**. I guess there are no tutorials on the net which explains to you how to rotate around three axis with just two inputs.
Does someone have a three-dimensional mouse? It sould be sphere-like,I know for sure they exist!
EDIT: already forgot additions. Whoops!
[edited by - Krohm on May 26, 2003 3:02:31 PM]
Previously "Krohm"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement