Sign in to follow this  

Moving left and right without rotating

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if you can't debug that yourself, then we'll have to see more code my man : ) cus nothing there has to do with rotation, the window edges, or the model.



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
if you can't debug that yourself, then we'll have to see more code my man : ) cus nothing there has to do with rotation, the window edges, or the model.


Are you sure Mr ? I pasted the code who increases / decreases the x value of the model selected and pasted the opengl drawing commands who draw the model selected at the position x, ,y ,z. What else do you need ? Also on the newsgroup have replied me wihout pasting the code !

Bye,

Share this post


Link to post
Share on other sites

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this