Advertisement

Odd problem with time based rotation.

Started by January 21, 2005 07:39 PM
2 comments, last by Bad Maniac 19 years, 10 months ago
Zipped Example EXE I'm having the strangest problem. The code is based on the first few tutorials. The one I'm playing with at the moment is Tutorial 7, but I got rid of the keyboard and filtering stuff, I use bilinear and mip-mapping always, and no keyboard control. My problem is this: The delta time value looks correct in debugging in windowed mode, but the rotation speed changes depending on the size of the window, and in Full screen the rotation seem to run at aproximately the right speed, but it rotates the other way from in windowed. In Windowed it rotates counter clock-wise, and in full screen it rotates clock-wise. In full screen I also experience shearing and flickering horizontal lines across the cube while rotating, Looks like it can't quite handle the framerate, but I'm using double buffering as set up in the first few tutorials. Does anyone have any idea why it might be rotating clock-wise in full screen and counter clock-wise in windowed? The move_multiplier is a float that is 0.00something depending on framerate, and I know the function for calculating it works, because I use it in my 2D library and I've tested it very rigorously. the angles at the bottom of the code: zrot += 30.0f * move_multiplier; //Z Axis Rotation Denote degrees per second, and in FullScreen it looks about right. My Draw Scene code:
int DrawGLScene(GLvoid)					//Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	//Clear Screen And Depth Buffer
	glLoadIdentity();									//Reset The Current Matrix
	glTranslatef(0.0f,0.0f,-5.0f);						//Move Into The Screen 5 Units

	glRotatef(xrot,1.0f,0.0f,0.0f);						//Rotate On The X Axis
	glRotatef(yrot,0.0f,1.0f,0.0f);						//Rotate On The Y Axis
	glRotatef(zrot,0.0f,0.0f,1.0f);						//Rotate On The Z Axis

	glBindTexture(GL_TEXTURE_2D, texture[0]);				//Select Our Texture

	glBegin(GL_QUADS);
		//Front Face
		glNormal3f( 0.0f, 0.0f, 1.0f);								// Normal Pointing Towards Viewer
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	//Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	//Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	//Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	//Top Left Of The Texture and Quad
		//Back Face
		glNormal3f( 0.0f, 0.0f,-1.0f);								// Normal Pointing Away From Viewer
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	//Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	//Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	//Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	//Bottom Left Of The Texture and Quad
		//Top Face
		glNormal3f( 0.0f, 1.0f, 0.0f);								// Normal Pointing Up
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	//Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	//Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	//Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	//Top Right Of The Texture and Quad
		//Bottom Face
		glNormal3f( 0.0f,-1.0f, 0.0f);								// Normal Pointing Down
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	//Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	//Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	//Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	//Bottom Right Of The Texture and Quad
		//Right face
		glNormal3f( 1.0f, 0.0f, 0.0f);								// Normal Pointing Right
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	//Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	//Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	//Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	//Bottom Left Of The Texture and Quad
		//Left Face
		glNormal3f(-1.0f, 0.0f, 0.0f);								// Normal Pointing Left
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	//Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	//Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	//Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	//Top Left Of The Texture and Quad
	glEnd();

	//xrot+= 30.0f * move_multiplier;		//X Axis Rotation
	//yrot+= -30.0f * move_multiplier;		//Y Axis Rotation
	zrot += 30.0f * move_multiplier;		//Z Axis Rotation
	
	return TRUE;
}

JRA GameDev Website//Bad Maniac
Are you initializing your xrot, yrot and zrot to 0.0 when you define them?

Eg.

float xrot = 0.0;
Advertisement
Works fine for me except for some of the usual dual-head issues. The rotation speed/direction is constant except during a few frames after a mode switch when it's (presumably) restabilising itself.

Are you sure that the rotation speed doesn't stabilise over time?

Quote: Original post by Anonymous Poster
Are you initializing your xrot, yrot and zrot to 0.0 when you define them?
I doubt that's the problem, the object is only rotated on a single axis.
Quote: Original post by Anonymous PosterAre you initializing your xrot, yrot and zrot to 0.0 when you define them?
Yep, that wasn't the problem, the problem was a missing initialization row in my delta time code, I missed it in my copy/pasting >.<

Works fine now:
New EXE

But the fullscreen flickering is still there. How do you get rid of it without resorting to vsync?
JRA GameDev Website//Bad Maniac

This topic is closed to new replies.

Advertisement