Skip to main content
GameDev.net gamedev.net
🔒 Locked

shooting bullets

Started by phil67rpg Jun 16, 2013 at 8:09 PM 6 replies 3.6k views
Original Post
phil67rpg
phil67rpg

I am working on a asteroids game. I am able to move the spaceship up and down and left and right. I just want it to shoot bullets using the space bar.

here is the code for the shooting bullets function.


void bullet()
{
glPointSize(2.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,up,0.0f);
glEnd();
up+=0.1f;
if(up >= 10.0f)
{
up=0.5f;
}
}
SimonForsman
SimonForsman

why do you have rendering code in your bullet function ?

you want to spawn a bullet with an initial position just in front of the ship and a velocity vector pointing in the direction the ship is facing, then you'll just update and render the bullet like any other gameobject.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
phil67rpg
phil67rpg







Posted Today, 03:39 PM


why do you have rendering code in your bullet function

should I have the rendering code in my main rendering function?

SimonForsman
SimonForsman




Posted Today, 03:39 PM


why do you have rendering code in your bullet function

should I have the rendering code in my main rendering function?

if the main rendering function renders the ships and asteroids then yes, it should render your bullets as well.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
phil67rpg
phil67rpg




if the main rendering function renders the ships and asteroids then yes, it should render your bullets as well.

hey I did the above and it worked, thanks

phil67rpg
phil67rpg

is there anyway to rotate an object without using the glRotatef function?

phil67rpg
phil67rpg

well I figured out how to rotate an object properly. I am actually getting this programming stuff using opengl and c++.

SimonForsman
SimonForsman

is there anyway to rotate an object without using the glRotatef function?

Yes, you can create a transformation matrix manually. (Rotatef is really just a shorthand function for creating and applying a rotation matrix to the current matrix (the one at the top of the stack). you can push and pop matrices to/from the stack using glpushmatrix/popmatrix and resetting the top matrix using glLoadIdentity(), or load your own matrix to the top of the stack using glLoadMatrix.

The only thing you should never do(unless you got a very low number of vertices in which case software transformation might be faster than creating the matrix, but then it most likely doesn't matter what you do anyway) is modify the vertex positions directly, each vertex is transformed using the transformation and projection matrices by the hardware (and it has to do that anyway)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.