Hi,
I have a 3d model into the scene. With a simple code called when the user presses Key_Left or Right I decrement / increment a flot variable:
void ItemDialogClass::Xpos_dec()
{
GlWindowClass->Model [ ChoosedModel ].x -= 0.1f;
Xpos_label->setText ( QString("%1").arg ( GlWindowClass->Model [ ChoosedModel ].x ) );
GlWindowClass->updateGL();
}
void ItemDialogClass::Xpos_inc()
{
GlWindowClass->Model [ ChoosedModel ].x += 0.1f;
Xpos_label->setText ( QString("%1").arg ( GlWindowClass->Model [ ChoosedModel ].x ) );
GlWindowClass->updateGL();
}
and this is the OpenGL drawing routine:
void GLWidget::paintGL()
{
switch (mode)
{
case Normal:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
CameraLook();
for ( std::map< unsigned int , string >::iterator i= GlWindowClass->DisplayList.begin(); i != GlWindowClass->DisplayList.end(); i++)
{
unsigned int index = i->first;
glPushMatrix();
glTranslatef ( Model[ index-1 ].x , Model[ index-1 ].y , Model[ index-1 ].z );
glScalef ( Model[ index-1 ].sx , Model[ index-1 ].sy , Model[ index-1 ].sz );
glCallList ( index );
glPopMatrix();
printf ("%d\t%f\t%f\t%f\n" , index-1, Model[index-1].x , Model[index-1].y , Model[ index-1 ].z);
}
break;
case Select:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
CameraLook();
break;
}
}
but the result is not a simple translation, while I move the model it rotates as soon as it reaches the border left or border right of the window. Do I need some maths ?