Advertisement
Guest User

Untitled

a guest
Jul 6th, 2012
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. class Bullet{
  2.  
  3. public:
  4.     Vector3 currentPosition;
  5.     Vector3 currentVelocity;
  6.  
  7.     bool moving;
  8.     bool fired;
  9.     bool reloaded;
  10.  
  11.     void render(double timeStep){
  12.         if(!fired) //We don't want anything to happen if bullet isn't fired yet
  13.             return;
  14.    
  15.         if(moving){ //We only want to calculate the new position if the bullet is moving
  16.             currentPosition += currentVelocity * timeStep;
  17.             /* set currentVelocity with respect to air friction, gravity and magic */
  18.        
  19.             if(currentPosition.z <= 0.0){ //If the z-coordinate is 0 or less (= if it hit the ground)
  20.                 currentPosition.z = 0;
  21.                 moving = false; //We want it to stop moving
  22.             }
  23.         }
  24.    
  25.         //Draw
  26.         glBegin(GL_TRIANGLE)
  27.         glTranslate(currentPosition.x, currentPosition.y, currentPosition.z);
  28.         DrawCube();
  29.         glEnd();
  30.     }
  31.  
  32.     //Constructor only sets everything to 0.
  33.     Bullet()
  34.         :    currentPosition(0,0,0),
  35.             currentVelocity(0,0,0)
  36.             moving(false),
  37.             fired(false),
  38.             reloaded(false),
  39.     {}
  40. };
  41.  
  42. Bullet g_bullet;
  43.  
  44. void main(){
  45.     g_bullet.currentVelocity = Vector3(5,0,1); //Starting velocity
  46. }
  47.  
  48. void Render()
  49. {
  50.  
  51.     g_bullet.render( 0.01 ); //Bullet travels 0.01 time units every frame.
  52.  
  53.     glutSwapBuffers();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement