• Advertisement
Sign in to follow this  

shooting bullets

This topic is 1678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}
}

 

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites





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?

Share this post


Link to post
Share on other sites

 





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.

Share this post


Link to post
Share on other sites


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

Share this post


Link to post
Share on other sites

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)

Edited by SimonForsman

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement