plane game

posted in phil67rpg's Blog
Published September 26, 2018
Advertisement

well I have drawn two plane sprites and have them move around the screen using keys. one them can also shoot bullets, I have drawn an animated collision sprite

Next Entry 1945 game
1 likes 31 comments

Comments

kseh

Looking forward to reading about your progress on your blog. I hope to see some screenshots when you can.

September 26, 2018 03:36 PM
phil67rpg

https://imgur.com/a/TtLvTxX here is my screenshot

September 28, 2018 09:12 PM
Rutin

Did you manage to get bullets to shoot out from any angle of the plane?

September 28, 2018 09:26 PM
phil67rpg

well kind of, I am able to shoot bullets up and down left and right, I am unable to get the bullet to get drawn in front of the plane depending on what way the plane is heading.

September 28, 2018 09:36 PM
Rutin
1 hour ago, phil67rpg said:

well kind of, I am able to shoot bullets up and down left and right, I am unable to get the bullet to get drawn in front of the plane depending on what way the plane is heading.

Just off-set the position. You can set the draw position when the plane is 90 degree, then when you move the plane, adjust the drawing position for the bullets based on the x and y changes, and when the ship rotates you can rotate the draw position by using the plane's center.

September 29, 2018 12:06 AM
phil67rpg

I will work on it. can I post some code?

September 29, 2018 12:36 AM
Rutin

It's your blog. ;)  

September 29, 2018 01:50 AM
phil67rpg

here is the code for drawing my bullets


	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, texture[2]);

	glPushMatrix();

	if (angle == (3.0 * PI) / 2.0f)
	{
		space = -1.125f;
	}

	if (angle == PI / 2.0f)
	{
		space = 0.0f;
	}

	if (angle == PI)
	{
		space_two = 0.001f;
	}

	if (angle == 0.0f)
	{
		space_two = 0.0f;
	}

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

	glVertex3f(-5.0625f+cos(angle)*up+horizontal+space_two, 0.625f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-5.0625f + cos(angle)*up + horizontal + space_two, 0.5f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-4.9375f + cos(angle)*up + horizontal + space_two, 0.5f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(-4.9375f + cos(angle)*up + horizontal + space_two, 0.625f + sin(angle)*up + vertical + space, 0.0f);
	glEnd();
	
	glPopMatrix();

	glDisable(GL_TEXTURE_2D);

 

September 29, 2018 10:37 PM
Awoken

does the 'f' at the end of a number mean 'float'?

September 30, 2018 02:11 PM
EddieK
1 hour ago, Awoken said:

does the 'f' at the end of a number mean 'float'?

Yup

September 30, 2018 03:36 PM
Awoken
20 hours ago, phil67rpg said:

(angle == (3.0 * PI) / 2.0f)

if he's using an integer 3.0 and multiplying it by a float does the result equal a float or integer?

September 30, 2018 07:18 PM
EddieK
4 minutes ago, Awoken said:

if he's using an integer 3.0 and multiplying it by a float does the result equal a float or integer?

3.0 is actually a double-precision floating-point value (or just 'double'), so the result will either be equal to float or double (I'm not sure which one, to be exact), but certainly not an integer. :)

September 30, 2018 07:23 PM
phil67rpg
On ‎9‎/‎28‎/‎2018 at 5:06 PM, Rutin said:

Just off-set the position. You can set the draw position when the plane is 90 degree, then when you move the plane, adjust the drawing position for the bullets based on the x and y changes, and when the ship rotates you can rotate the draw position by using the plane's center.

can I get some input on my code, I have almost solved my problem I am still a little confused on rutins post.

September 30, 2018 09:14 PM
Rutin

Take this visual example.

The dark blue square is your ship, and the orange rectangle is the spawn point of your bullets.

image.png.aa3d125c403cf45a5fd9d5789276d250.png

Now if you  rotate both objects based on their own pivot point being their center, this will happen at 45 degrees:

image.png.e2ce69461ef981a67ed135f29378b2b9.png

What you want is to rotate both together to maintain proper position and rotation by changing the center for the orange rectangle. You do this by having the orange rectangle rotate on the center point of the blue square:

image.png.b605e688305694b5cc45737fcc309eff.png

I programmed a quick application to demo this.

Below you will see a GIF animation of both objects moving but rotating on their own centers.

rtexamplegif2.gif.2e490640d350ddb2d3b8412232164b46.gif

Now you'll see them moving but maintaining the position as you would need. I could essentially use the position and angle of the red rectangle transformation to spawn bullets at the correct spot and with the proper angle as needed.

rtexamplegif1.gif.493a1981607033dd4e466c598a217f50.gif

This should be enough to get your started.

October 01, 2018 01:07 AM
phil67rpg
37 minutes ago, Rutin said:

Now if you  rotate both objects based on their own pivot point being their center, this will happen at 45 degrees:

image.png.e2ce69461ef981a67ed135f29378b2b9.png

thanks for the visual, this is how my sprite is reacting, I


	glVertex3f(-5.0625f+cos(angle)*up+horizontal+space_two, 0.625f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(1.0f, 0.0f, 0.0f);

	glVertex3f(-5.0625f + cos(angle)*up + horizontal + space_two, 0.5f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(1.0f, 1.0f, 0.0f);

	glVertex3f(-4.9375f + cos(angle)*up + horizontal + space_two, 0.5f + sin(angle)*up + vertical + space, 0.0f);
	glTexCoord3f(0.0f, 1.0f, 0.0f);

	glVertex3f(-4.9375f + cos(angle)*up + horizontal + space_two, 0.625f + sin(angle)*up + vertical + space, 0.0f);

know what I want it to do which is rotate around the blue square.  in my code is where I am not rotating the sprite around its center, this is where I am having  a problem.

What you want is to rotate both together to maintain proper position and rotation by changing the center for the orange rectangle. You do this by having the orange rectangle rotate on the center point of the blue square:

image.png.b605e688305694b5cc45737fcc309eff.png

October 01, 2018 02:02 AM
Awoken

hmmm... @Rutin, what if @phil67rpg was to ...

Each time the player fires a bullet capture the planes position and normalize it. ( meaning if the x,y and z co-ordinates where all squared, summed and then rooted it'd be equal to 1.  

example, let's say the plane is at position glVertex3f( 5.0f , 0.0f , 0.0f ) the normalized vertex would be glVertex3f( 1.0f , 0.0f , 0.0f ).
Then you'll need to determine the ratio of 1.0f on screen and the width of your plane sprite.  But let's say the plane sprite is 4.0f tip to tip, then you'd want to multiply the normalized vertex by the half the width of the plane.
Add this new vertex, let's call it bullet position, to the position of the plane.

Then for each frame of action you'd just keep adding this same value to it's self over and over again and you should see the bullet fly along an angle.

@Rutin, what are you thinking?

October 04, 2018 11:12 PM
phil67rpg

I am taking a class in linear algebra we are working with vectors, the distance formula is what you are talking about, the magnitude of a vector is what you are referring to.

October 04, 2018 11:24 PM
Awoken

k perfect, I'm leading us astray in my previous post.  

Try the following:

have a normailized vector and call it... I don't know.. bulletRotation.
Each time you rotate the plane rotate the bulletRotation vector by the same amount.
when you fire your bullet use the bulletRotation vector as your reference.
You'll want to add the bulletRotation to the planes position so that it appears the bullet is offset from the plane.
Depending on how fast you want the bullet to travel you'll want to multiply bulletRotation by some amount.

 

October 05, 2018 12:28 AM
Rutin
12 minutes ago, Awoken said:

hmmm... @Rutin, what if @phil67rpg was to ...

Each time the player fires a bullet capture the planes position and normalize it. ( meaning if the x,y and z co-ordinates where all squared, summed and then rooted it'd be equal to 1.  

example, let's say the plane is at position glVertex3f( 5.0f , 0.0f , 0.0f ) the normalized vertex would be glVertex3f( 1.0f , 0.0f , 0.0f ).
Then you'll need to determine the ratio of 1.0f on screen and the width of your plane sprite.  But let's say the plane sprite is 4.0f tip to tip, then you'd want to multiply the normalized vertex by the half the width of the plane.
Add this new vertex, let's call it bullet position, to the position of the plane.

Then for each frame of action you'd just keep adding this same value to it's self over and over again and you should see the bullet fly along an angle.

@Rutin, what are you thinking?

@Awoken What I was trying to do was give an example through visual display in my blue square, and the orange rectangle example based on a pivot point. The animation I showed is made with actual game code showing the two in motion. The red rectangle would represent the bullet sprite position and acts as nothing more than a (x, y, and rotation) guide that would update as you moved your plane. I was trying to refrain from posting code in hopes that @phil67rpg could take this concept and code it as I don't feel people learn if they don't understand what is going on and we spoon feed code.

Releasing a shot is extremely simple if you have the guide as I show in my below example:

rtexamplegif3.gif.ab2718aad5a26674b5ba23583cf2b800.gif

@Awoken yes, you can normalize.

I don't have much time right now as I'm still at work with tight deadlines to meet.

Maybe this can be of some help @phil67rpg

I didn't check if the content is "good" so keep that in mind.

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/

http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/

October 05, 2018 12:39 AM
Awoken

ops sorry @phil67rpg, no more kinda-sorta-help from me ? 

October 05, 2018 12:41 AM
phil67rpg

I have to work on this problem.

October 05, 2018 02:18 AM
Rutin
17 minutes ago, phil67rpg said:

I have to work on this problem.

Did you have a chance to look at those links I posted?

October 05, 2018 02:36 AM
TraderJones
On 9/28/2018 at 5:12 PM, phil67rpg said:

https://imgur.com/a/TtLvTxX here is my screenshot

That doesnt look too bad. What did you use to develop this and how far along are you? 

October 05, 2018 05:16 AM
phil67rpg
17 hours ago, TraderJones said:

That doesnt look too bad. What did you use to develop this and how far along are you? 

I am using opengl c++ and soil, I have drawn two planes and have move around the screen using keys, I also have the first plane to shoot bullets, I am  working on rotating the bullets around my plane sprite so that they shoot from wherever the plane is facing. rutin has been a lot of help.

20 hours ago, Rutin said:

Did you have a chance to look at those links I posted? 

well rutin I am studying the linear algebra links you posted.

October 05, 2018 10:38 PM
phil67rpg

I have stubbed out some code to help me understand how to rotate a point.


#include <iostream>
#include <math.h>

using namespace std;

float angle = 0.0f, point_x = 0.0f, rotate_x = 0.0f, point_y = 0.0f, rotate_y = 0.0f;

int main()
{
	cout << "Point X: ";
	cin >> point_x;
	cout << endl;

	cout << "Point Y: ";
	cin >> point_y;
	cout << endl;

	cout << "Angle(radians): ";
	cin >> angle;
	cout << endl;

	rotate_x = point_x*cos(angle) - point_y*sin(angle);
	rotate_y = point_x*sin(angle) + point_y*cos(angle);

	cout << "Rotate X: " << rotate_x << endl;
	cout << "Rotate Y: " << rotate_y << endl;

	system("pause");
	return 0;
}

 

October 05, 2018 11:47 PM
phil67rpg

this is my stubbed out code that draws a circle, I am  doing this in order to understand more about rotations.


#include <iostream>
#include <math.h>
#include <glut.h>

using namespace std;

float angle = 0.0f, point_x = 1.0f, rotate_x = 0.0f, point_y = 0.0f, rotate_y = 0.0f;

float const PI = 3.1415925;

void RenderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0f, 1.0f, 1.0f);

	glBegin(GL_LINE_STRIP);
	glVertex3f(0.0f, 10.0f, 0.0f);
	glVertex3f(0.0f, -10.0f, 0.0f);
	glEnd();

	glBegin(GL_LINE_STRIP);
	glVertex3f(-10.0f, 0.0f, 0.0f);
	glVertex3f(10.0f, 0.0f, 0.0f);
	glEnd();
	
	glBegin(GL_POINTS);
	for (float angle = 0.0f; angle <= PI*2.0; angle += 0.001)
	{
		rotate_x = point_x*cos(angle) - point_y*sin(angle);
		rotate_y = point_x*sin(angle) + point_y*cos(angle);
		glVertex3f(rotate_x, rotate_y, 0.0f);
	}
	glEnd();
	
	glutSwapBuffers();
}

void SetupRC(void)
{
	glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 1.0f, -1.0f);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(500, 300);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Rotate");
	glutDisplayFunc(RenderScene);
	SetupRC();
	glutMainLoop();
	return 0;
}

 

October 07, 2018 02:51 AM
phil67rpg

well I have made some progress on my problem


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), 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), 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), 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), 0.0f);
	glEnd();

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

	glPopMatrix();

	glDisable(GL_TEXTURE_2D);
}

 

October 23, 2018 11:20 PM
phil67rpg

well rutin I am still stuck on my rotation problem.

October 27, 2018 07:12 PM
Rutin
2 hours ago, phil67rpg said:

well rutin I am still stuck on my rotation problem.

Can you please list all the materials you're using to learn openGL with? I know you're taking classes at school so there has to be some kind of course material you're using. Book, Teacher's workbooks, ect...

October 27, 2018 09:48 PM
phil67rpg

well I have read the opengl superbible 4th ed. I am also working on the opengl programming guide 7th ed.

October 27, 2018 09:55 PM
Rutin
28 minutes ago, phil67rpg said:

well I have read the opengl superbible 4th ed. I am also working on the opengl programming guide 7th ed.

Are you able to fully teach someone all the concepts you learned within those books without any trouble? Essentially you need to be at the stage where you understand the material enough to actually understand what is working, and why is it working, not that is just "works". Reading through the book from the front to back doesn't mean you understand it.

I'm thinking you're jumping too far ahead and haven't fully understood the rest of the material.

Also... OpenGL SuperBible: Comprehensive Tutorial and Reference (4th Edition) is from 2007.... Why the heck are you learning books that dated in school? OpenGL Superbible: Comprehensive Tutorial and Reference (7th Edition) was released already in 2015. The same with OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition) from 2009... It's not rated a good book in the present...

The first step is getting good materials that are at least up to date. Not all books are created equal as well, there are some that will confuse you more so than help. OpenGL SuperBible should've been enough alone to help you solve your main issues. I would suggest getting an up to date version and going through each part until you truly understand what is going on.

October 27, 2018 10:20 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

asteroids wars

2652 views

plane game

3401 views

rgg platformer

2033 views

win 32 pong

2514 views

bug invaders

2178 views

c# book

2465 views

c# bug invaders

2122 views

c# console snake game

23767 views
Advertisement