Thanks Dan,
Makes sense, but that doesn’t fix my problem. Perhaps I didn’t explain it well…here it is again:
void draw_scene ()
{
glPushMatrix();
do_transformations();
draw_thing();
glPopMatrix();
}
/---------------------------------------------------------------------/
void do_transformations()
{
do_translation();
do_rotation();
do_scaling();
}
/--------------------------------------------------------------------/
void do_trasnlation()
{
glTranslatef (x_trans, y_trans, 0.0); //don’t have code with me, but I think this is correct
}
/--------------------------------------------------------------------/
void do_rotation()
{
glMultMatrixf (trackball_matrix);
glrotatef (x_angle, 1.0, 0.0, 0.0);
glrotatef (y_angle, 0.0, 1.0, 0.0);
glrotatef (z_angle, 0.0, 0.0, 1.0);
glutPostReDisplay();
}
/--------------------------------------------------------------------/
void do_scaling()
{
glScalef (…)
}
/-------------------------------------------------------------------/
void draw_thing()
{
glWiredPot…
}
so this is the basic code, much of it was given to us since we just started opengl a 2 weeks ago. Translation had already been coded. Now Rotation works, somewhat, but not quite right. All movements are controlled by keyboard and mouse. So if I hit x and move mouse when left button is pressed, object moves in x direction and so on. so an x-y-z rotation actually consists of 3 separate movements.
hit x -> move mouse -> let go mouse button
hit y -> move mouse -> let go mouse button
hit z -> move mouse -> let go mouse button
the problem is obvious when I do an x-y-x rotation. 1st object moves around x-axis, then y-axis, but the 3rd rotation is around the OLD x-axis, not the rotated x-axis. This is not all, if I do a z-x-z rotation things get more complicated as now the z-axis actually does get rotated. In fact, in the do_rtation() function, the last glRotate* call (in other words, the one 1st applied to model view matrix) does get rotated. I came with a solution as following
void do_rotation()
{
glMultMatrixf (trackball_matrix); // ignore this, makes no difference
glPushMatrix();
glLoadMatrixf (old_matrix); //note that old_matrix must be init or else screw up
glrotatef (x_angle, 1.0, 0.0, 0.0);
glrotatef (y_angle, 0.0, 1.0, 0.0);
glrotatef (z_angle, 0.0, 0.0, 1.0);
glGetFloatv (GL_MODELVIEW_MATRIX, old_matrix);
glPopMatrix();
glMultMatrixf (old_matrix);
}
well, there was an initial problem of the object appearing with half the scale…a glScalef (2.0,2.0,2.0) did fix this.
and now the coordinates are actually hooked to the object. all rotation (specially xyx and zxz) worked fine, but now translation didn’t work at all (scaling does). I used a similar code to fix translation (figured I was discarding the translation matrix effect). Now there is a new problem, translation occurs in the “direction” of the axis. so if I rotate the x-axis up, then doing an x-traslation moves the object in y direction. if y axis is in z direction, object moves in z-direction (back & forth and hence appears scaled as the z-axis goes into the screen)…argh…
I’ve been playing with this for the past 4 days…other things I have tried was to do a rotation like following
glrotatef (x_angle, x , y, z); // where x, y, z are the appropiate vectors rotated
I figured I could rotate the (1,0,0) vector by multiplying it by the model view matrix (and the other vectors likewise)…results were very unpredictable, the object would start acting on its own, speeding up and slowing down at times…
See if you can help me, I think I’m trying the wrong things…the problem is that, I’ve seen sample code from last year (ppl who’ve gotten full marks) and their code behaves just like mine…but the sample solution our prof (uh, yes, this is THE COOLEST 4th year comp sci course…he he he) gave us is correct.
Help me out ppl,
Much appreciated,
Reza