Skip to main content
GameDev.net gamedev.net
🔒 Locked

glTranslatef

Started by Mat1515 Mar 1, 2004 at 3:00 PM 3 replies 350+ views
Original Post
Mat1515
Mat1515
Hey now that i have my camera class working with help from www.gametutorials.net translatef is not working correctly to draw primatives now They are always drawn starting at 0,0,0. How can i fix this? It's not in the code but after the right wall im looking to reset the matrix then translate 50 units to the right then start drawing the new wall there! but it doesn't work NEW CODE TO DEBUG!!!
void RenderScene()
{
	//every.1 = 1 foot

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//clear buffer

	glLoadIdentity();//reset model view matrix



		gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,	
			  g_Camera.m_vView.x,	  g_Camera.m_vView.y,	  g_Camera.m_vView.z,	
			  g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);

		
		glBegin(GL_QUADS);

		//***TRACK WALLS***//

			
				//LEFT WALL

		glTranslatef(-50.0f,0.0f,0.0f);
			glVertex3f(-0.25f,-1.0f,0.0f);//bottom left

			glVertex3f(-0.25f,1.0f,0.0f);
			glVertex3f(0.25f,1.0f,0.0f);	
		    glVertex3f(0.25f,-1.0f,0.0f);

			glVertex3f(0.25f,-1.0f,0.0f);//bottomleft

			glVertex3f(0.25f,1.0f,0.0f);
			glVertex3f(0.25f,1.0f,-500.0f);
		    glVertex3f(0.25f,-1.0f,-500.0f);

			glVertex3f(0.25f,-1.0f,-500.0f);
			glVertex3f(0.25f,1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,-500.0f);	
			glVertex3f(-0.25f,-1.0f,-500.0f);

			glVertex3f(-0.25f,-1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,0.0f);
			glVertex3f(-0.25f,-1.0f,0.0f);

//WHY DOES THIS ONE SHOW UP IN THE SAME GODAMN SPOT!!!

glTranslatef(100.0f,0.0f,0.0f);
			glVertex3f(-0.25f,-1.0f,0.0f);//bottom left

			glVertex3f(-0.25f,1.0f,0.0f);
			glVertex3f(0.25f,1.0f,0.0f);	
		    glVertex3f(0.25f,-1.0f,0.0f);

			glVertex3f(0.25f,-1.0f,0.0f);//bottomleft

			glVertex3f(0.25f,1.0f,0.0f);
			glVertex3f(0.25f,1.0f,-500.0f);
		    glVertex3f(0.25f,-1.0f,-500.0f);

			glVertex3f(0.25f,-1.0f,-500.0f);
			glVertex3f(0.25f,1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,-500.0f);	
			glVertex3f(-0.25f,-1.0f,-500.0f);

			glVertex3f(-0.25f,-1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,-500.0f);
			glVertex3f(-0.25f,1.0f,0.0f);
			glVertex3f(-0.25f,-1.0f,0.0f);



		//***TRACK WALLS END***/

		glEnd();
	
}
[edited by - Mat1515 on March 1, 2004 4:01:37 PM] [edited by - Mat1515 on March 1, 2004 7:57:38 PM]
Ut o not me again:) lol
SuperDuck
SuperDuck

It would have been better if u would have actually written the translatef in ur code and put it out for debugging.

....anyways, one common mistake people make is that they put the translatef after drawing the scene. OpenGL works from the bottom and goes up, meaning it first draws the object and then translates it, keep that in mind when drawing. Similar is the case when u use rotatef ...if rotatef comes before translatef in the code, it first translates the object and then rotates it with respect to the origin, giving unwanted results.

In case I am directing the wrong problem in the above paragraph, looking into the push and pop option, where u separate out certain translations, rotations etc affecting a part of the scene not to apply on the rest of the scene.

And I still get the feeling that either I''m directing the wrong problem or making no sense :S

SuperDuck
=========
We are all like a duck ... it looks calm and cool above the water; but underneath, its tiny feet are peddling hard to stay afloat. Me? I''''m just another duck in the pond!!!
SuperDuck=========We are all like a duck ... it looks calm and cool above the water; but underneath, its tiny feet are peddling hard to stay afloat. Me? I''m just another duck in the pond!!!
Trienco
Trienco
besides translate not working at this position: when you say "reset" the matrix, dont say youre using loadidentity?

about opengl being backwards: why are people still forcing their global point of view on local transformations? sure, the result is the same, but i doubt opengl is doing anything backwards. once you rotate the local coordinate system is rotated, when you translate you do so along the NEW axes. also: after opengl draws something it cant be moved around.

am i the only one finding it harmful to complicate a simple thing by telling people that everything is happening the other way round?
f@dzhttp://festini.device-zero.de
y2kiah
y2kiah
OpenGL concatenates matrix operations as they are called, but the pipeline is designed to do matrix multiplication from the right, not the left. This is why the apparent order of operations is backwards with OpenGL. Basically the last glRotate or glTranslate or glScale (etc.) called before drawing anything is the first matrix operation actually performed.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.