Advertisement

rotating sprites

Started by November 03, 2018 08:32 PM
9 comments, last by RoamBlade 6 years, 3 months ago

I am still working on rotating my bullet around my plane sprite I have made some progress. however when move the plane down the bullet is drawn toward the top middle of the screen. when I move the plane to the left the bullet is drawn toward the middle of the left of the screen. although the bullet does move in the same direction as the plane is facing, at least I have solved that problem.  I think the problem is in the glRotatef function. here is my code so far.


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

	if (rotate == 0.25f)
	{
		angle = 0.0f;
	}
	if (rotate == 0.75f)
	{
		angle = 180.0f;
	}
	if (rotate == 0.5f)
	{
		angle = 90.0f;
	}
	if (rotate == 0.0f)
	{
		angle = 270.0f;
	}

	glRotatef(angle, 0.0f, 0.0f, 1.0f);

	glTranslatef(0.0f, 0.0f + up, 0.0f);

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f, 0.0f, 0.0f);

	glVertex3f(0.0625f+horizontal, 0.0625f+vertical, 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-0.0625f+horizontal, 0.0625f+vertical, 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-0.0625f+horizontal, -0.0625f+vertical, 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(0.0625f+horizontal, -0.0625f+vertical, 0.0f);
	glEnd();

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

 

50 minutes ago, phil67rpg said:

I am still working on rotating my bullet around my plane sprite

Is this the same game you were working on for a college class?

Hello to all my stalkers.

Advertisement

no this is not homework, I switched my project on my college class.

I am thinking about going to put back in trigonometry functions into the glVertex functions, I think this will work better then the glRotatef functions.

I am going to use matrices to help solve my problem.


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

	if (rotate == 0.25f)
	{
		angle = PI / 2.0f;
	}
	if (rotate == 0.75f)
	{
		angle = (3.0f*PI) / 2.0f;
	}
	if (rotate == 0.5f)
	{
		angle = PI;
	}
	if (rotate == 0.0f)
	{
		angle = 0.0f;
	}

	glTranslatef(0.0f, 0.5f, 0.0f);

	float r = sqrt(pow(0.5f, 2) + pow(0.5f, 2));

	glBegin(GL_POLYGON);
	glTexCoord3f(0.0f, 0.0f, 0.0f);

	glVertex3f(0.0625f+cos(angle)*r*up+horizontal, 0.0625f+sin(angle)*r*up+vertical, 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-0.0625f+cos(angle)*r*up+horizontal, 0.0625f+sin(angle)*r*up+vertical, 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-0.0625f+cos(angle)*r*up+horizontal, -0.0625f+sin(angle)*r*up+vertical, 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(0.0625f+cos(angle)*r*up+horizontal, -0.0625f+sin(angle)*r*up+vertical, 0.0f);
	glEnd();

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

I have almost solved my problem, I have got my bullet to shoot up and down and left and right but I want it to rotate around the plane and shoot in the same direction that the plane is facing.

Advertisement

well like I said I have got the bullet sprite to shoot in up and down and left and right directions, all I want to do is rotate my bullets around my plane sprite so that they shoot in the same direction as my plane is facing. I have also did some research on this problem with google.

I will google some more and I will also stub out some more code.

This topic is closed to new replies.

Advertisement