Sign in to follow this  
MotionCoil

Problem with rotation

Recommended Posts

MotionCoil    464
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)

Share this post


Link to post
Share on other sites
rick_appleton    864
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.

Share this post


Link to post
Share on other sites
alex_r    112
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this