Problem with rotation

Started by
1 comment, last by alex_r 18 years, 9 months ago
hey all sorry, I got a bit of a problem here and I can't work out why its just doing it. In my map editor I have decided to add rotation to the primitives. The thing is I am not too sure how to do what I want to do- basically I want to the primitives to rotate on themselves, spin if you will, on the same spot. I don't want them to go round the entire axis. Here is my render code for the world view of the editor:


			glTranslatef(0.0,0.0,-1.0);
	
			glScalef(Scalar[0],Scalar[0],Scalar[0]);

			glRotatef(Geo[Index].RotX,1.0,0.0,0.0);		// Rotate on the X
			glRotatef(Geo[Index].RotY,0.0,1.0,0.0);		// Rotate on the Y
			glRotatef(Geo[Index].RotZ,0.0,0.0,1.0);		// Rotate on the Z
	
	 
	glPolygonMode(GL_FRONT_AND_BACK, aeRenderOptions);
	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDtop]);
	glBegin(GL_QUADS);							
		glTexCoord2f(1.0f, 1.0f); glVertex3f( resX,		resY,		resZ	);			// Top Right Of The Quad (Top)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( OffSetX,	resY,		resZ	);					// Top Left Of The Quad (Top)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( OffSetX,	resY,		OffSetZ	);					// Bottom Left Of The Quad (Top)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( resX,		resY,		OffSetZ	);				// Bottom Right Of The Quad (Top)
	glEnd();
		
	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDbottom]);
	glBegin(GL_QUADS);	
		glTexCoord2f(1.0f, 1.0f); glVertex3f( resX,		OffSetY,	resZ	);					// Top Right Of The Quad (Bottom)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( OffSetX,	OffSetY,	resZ	);						// Top Left Of The Quad (Bottom)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( OffSetX,	OffSetY,	OffSetZ	);							// Bottom Left Of The Quad (Bottom)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( resX,		OffSetY,	OffSetZ	);						// Bottom Right Of The Quad (Bottom)
	glEnd();


	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDfront]);	
	glBegin(GL_QUADS);							
		glTexCoord2f(1.0f, 1.0f); glVertex3f( resX,		resY,		OffSetZ	);				// Top Right Of The Quad (Front)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( OffSetX,	resY,		OffSetZ	);					// Top Left Of The Quad (Front)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( OffSetX,	OffSetY,	OffSetZ	);							// Bottom Left Of The Quad (Front)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( resX,		OffSetY,	OffSetZ	);						// Bottom Right Of The Quad (Front)
	glEnd();

	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDback]);
	glBegin(GL_QUADS);		
		glTexCoord2f(1.0f, 1.0f); glVertex3f( resX,		resY,		resZ	);				// Top Right Of The Quad (Back)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( OffSetX,	resY,		resZ	);					// Top Left Of The Quad (Back)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( OffSetX,	OffSetY,	resZ	);						// Bottom Left Of The Quad (Back)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( resX,		OffSetY,	resZ	);					// Bottom Right Of The Quad (Back)
	glEnd();

	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDleft]);
	glBegin(GL_QUADS);	
		glTexCoord2f(1.0f, 1.0f); glVertex3f( OffSetX,	resY,		resZ	);				// Top Right Of The Quad (Left)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( OffSetX,	resY,		OffSetZ	);						// Top Left Of The Quad (Left)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( OffSetX,	OffSetY,	OffSetZ	);							// Bottom Left Of The Quad (Left)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( OffSetX,	OffSetY,	resZ	);						// Bottom Right Of The Quad (Left)
	glEnd();

	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDright]);
	glBegin(GL_QUADS);	
		glTexCoord2f(1.0f, 1.0f); glVertex3f( resX,		resY,		resZ	);			// Top Right Of The Quad (Right)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( resX,		resY,		OffSetZ	);				// Top Left Of The Quad (Right)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( resX,		OffSetY,	OffSetZ	);						// Bottom Left Of The Quad (Right)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( resX,		OffSetY,	resZ	);					// Bottom Right Of The Quad (Right)	
	glEnd();


If that helps. Cliffs: -The primitives rotate on the entire axis so they go on a long walk around 3D space -I need the primitives to spin on themselves so they are in the same spot just at a different angle -Is this possible? Thanks (Big Time)
Advertisement
It seems that you are drawing the items on the spot.

What you'll want to do is draw the items in the origin and translate them to the spot.

Adjusting your code you'd get:

			glTranslatef(position.x, position.y, position.z);			glTranslatef(0.0,0.0,-1.0);				glScalef(Scalar[0],Scalar[0],Scalar[0]);			glRotatef(Geo[Index].RotX,1.0,0.0,0.0);		// Rotate on the X			glRotatef(Geo[Index].RotY,0.0,1.0,0.0);		// Rotate on the Y			glRotatef(Geo[Index].RotZ,0.0,0.0,1.0);		// Rotate on the Z			// Render your stuff here, but at the origin


That should do what you want.
I don't know if is that what you like... But, look this topic... (Last post)

http://www.gamedev.net/community/forums/topic.asp?topic_id=308952

This topic is closed to new replies.

Advertisement