Jump to content

  • Log In with Google      Sign In   
  • Create Account


shooting bullets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 June 2013 - 02:09 PM

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

 



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6041

Like
0Likes
Like

Posted 16 June 2013 - 04:39 PM

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.


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!

#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 June 2013 - 04:41 PM





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?



#4 SimonForsman   Crossbones+   -  Reputation: 6041

Like
0Likes
Like

Posted 16 June 2013 - 04:53 PM

 





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.


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!

#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 June 2013 - 06:43 PM


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



#6 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 June 2013 - 07:35 PM

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



#7 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 June 2013 - 08:31 PM

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



#8 SimonForsman   Crossbones+   -  Reputation: 6041

Like
0Likes
Like

Posted 18 June 2013 - 12:59 AM

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, 18 June 2013 - 01:00 AM.

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS