Advertisement

Moving left and right without rotating

Started by September 14, 2004 04:58 AM
2 comments, last by Washu 20 years, 2 months ago
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 ?
ColossusCpsed,a Linux OpenGL 3D scene editorhttp://cpsed.sourceforge.net
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.



Advertisement
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,
Cross post: Moving left and right without rotating

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This topic is closed to new replies.

Advertisement