1945 game

posted in phil67rpg's Blog
Published October 27, 2018
Advertisement

I am still working on my 1945 plane game. I am stuck on how to rotate the bullet sprite around the plane sprite. I am using trig. functions and some linear algebra which is what I am taking in college classes. here is the code I am using.


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

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

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

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

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

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

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

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

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

 

Previous Entry plane game
Next Entry 1943 Plane Game
1 likes 16 comments

Comments

phil67rpg

here is my latest screen shot https://imgur.com/a/ZxDFA5Y

October 27, 2018 10:04 PM
phil67rpg

I am having a scoping problem.


	case 119:
		if (rotate == 0.875f)
		{
			vertical -= 0.25f;
			horizontal += 0.25f;
		}

		if (rotate == 0.625f)
		{
			vertical -= 0.25f;
			horizontal -= 0.25f;
		}
		if (rotate == 0.125f)
		{
			vertical += 0.25f;
			horizontal += 0.25f;
		}
		if (rotate == 0.375f)
		{
			vertical += 0.25f;
			horizontal -= 0.25f;
		}
		if (rotate == 0.75f)
		{
			angle = 270.0f;
			vertical -= 0.25f;
		}
		if (rotate == 0.25f)
		{
			angle = 90.0f;
			vertical += 0.25f;
		}

		if (rotate == 0.5f)
		{
			angle = 180.0f;
			horizontal -= 0.25f;
		}
		if (rotate == 0.0f)
		{
			angle = 0.001f;
			horizontal += 0.25f;
		}

		if (vertical >= 9.5f)
		{
			vertical = 9.5f;
		}
		if (vertical <= -9.5f)
		{
			vertical = -9.5f;
		}

		if (horizontal <= -4.5f)
		{
			horizontal = -4.5f;
		}
		if (horizontal >= 14.5f)
		{
			horizontal = 14.5f;
		}
		break;

I am trying to get the angle variable to be recognized in the drawbullet_one function.


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

//	glPushMatrix();

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

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

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

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

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

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

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

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

//	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

here is the drawing code

October 27, 2018 10:43 PM
phil67rpg

can I get some help on my scoping problem.

October 28, 2018 09:46 PM
Rutin
18 minutes ago, phil67rpg said:

can I get some help on my scoping problem.

Where is the function or class that declares and sets your angle variable? I don't see it here... All I see is your if statement which sets the angle, but no indication where it's declared.

October 28, 2018 10:04 PM
phil67rpg

well I declare it at the top as a global variable, yes I know I should not use global variables, I set it to 0.0f.

October 28, 2018 10:08 PM
Rutin

If angle is a global variable then you wouldn't have any issue with scope. You said you have a scope issue as you're trying to recognize it under drawbullet_one().

Post your error message from Visual Studio.

October 28, 2018 10:19 PM
phil67rpg

I don't get an error from VS but I am trying to get it to be recognized in drawbullet_one

October 29, 2018 02:10 AM
Rutin
50 minutes ago, phil67rpg said:

I don't get an error from VS but I am trying to get it to be recognized in drawbullet_one

I know I keep spinning the same record, but please do yourself a favor and go back and review C++ with a good book like C++ Primer 5th Edition, then start up on openGL with baby steps with a more recent book.

I'm only saying this because if you're setting angle as a global variable, and you're asking how to use it within another function, that is a big warning sign... If the variable is global it can be called anywhere within the same .cpp file, otherwise if you're including classes, then you can either pass a copy or reference of the variable into the class's function. I wont get into 'extern' for globals...

There is no way you don't know this considering you've been at this for 14 years now... You already know how to recognize it in drawbullet_one()... Either type angle, or pass it through the function if it's outside of file scope. I'm in disbelief that you're asking this type of question...

October 29, 2018 02:59 AM
phil67rpg

well I am not  a good programmer but I am doing this just for fun.

October 29, 2018 05:38 PM
phil67rpg

ok I will  put the glPush/glPop back in. I will also put the up variable in glTranslate and get rid of the trailing glTranslate.

October 29, 2018 08:40 PM
phil67rpg

here is my adjusted code.


void drawbullet_one()
{
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

	glTranslatef(-5.0f, 0.5f + up, 0.0f);

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

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

	glVertex3f(0.0625f, 0.0625f, 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-0.0625f, 0.0625f, 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-0.0625f, -0.0625f, 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(0.0625f, -0.0625f, 0.0f);
	glEnd();

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

 

October 29, 2018 08:58 PM
unbird

Remote debugging with a unresponsive debugger is so much fun.

October 30, 2018 06:56 AM
phil67rpg

fleabay do you have any more input

October 31, 2018 08:45 PM
Awoken

Hi @phil67rpg, I don't know if this is sacrilege, but ever consider using a different language?  Any reason you're sticking to c++?

November 02, 2018 12:50 AM
phil67rpg

well I use c++ because I used it in school and have read several books on it.

November 02, 2018 01:46 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

asteroids wars

2708 views

plane game

3453 views

rgg platformer

2087 views

win 32 pong

2569 views

bug invaders

2238 views

c# book

2517 views

c# bug invaders

2174 views

c# console snake game

23967 views
Advertisement