rotate a sprite

Started by
14 comments, last by Alberth 3 years, 9 months ago

thanks for the like, but I am unsure of how to proceed further however I get three rectangles of 0 45 and 90 degree angles.

Advertisement

Perhaps try to display a rotated car?

Now you have coordinates of the vertices to use on your car sprite for a given rotation. (The bottom sheet with the car is your car sprite, the top sheet with the hole is the rectangle that OpenGL paints.) You tell OpenGL to always paint the car in the same area in the world, but you change which pixels go where by giving OpenGL a rotated area of the car sprite.

The coordinates do need a small amount of extra work though, sprite coordinates cannot be negative as that's outside the sprite.

as a work around I have displayed rotated cars around the curve where a car is drawn each 15 degrees, all I want to do is erase them after I have drawn them so it looks like the car rotates around the curve smoothly

@Alberth well I took fleabays advice and have cleared the whole screen with glClear(GLCOLORBUFFERBIT); and draw with swapbuffers function. I have got my game to move the car up to the left curve and then turn the corner however my code keeps turning the car to the left over and over again, also the track turns on and off several times. here is my updated code.

void renderScene()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glPushMatrix();
	drawTrack();
	drawSlotcar();
	glPushMatrix();
	if (up >= 70.0f)
	{
	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurve();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurveone();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurvetwo();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurvethree();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurvefour();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurvefive();
	glutSwapBuffers();

	glClear(GL_COLOR_BUFFER_BIT);
	drawSlotcarcurvesix();
	glutSwapBuffers();
	}
	drawTrack();
	drawSlotcar();
	glPopMatrix();
	glPopMatrix();
	glutSwapBuffers();
}

Sorry, but I have no idea what that code is doing. I am not a glut user, but assuming the functions do what their name says, I am guessing as follows:

Fleabay suggested to draw everything from scratch and swap buffers every frame.

You however seem to [[clear screen, draw a little bit and then swap]] lots of times within one frame. I don't know why you are doing that, but how are you supposed to see the entire track if you clear screen, draw one curve, and swap about 8 times in a single render?

As for your rotated car, you just call lots of “drawSlotcar**” functions here, so these are likely wrong I think.

This topic is closed to new replies.

Advertisement