Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bullet{
- public:
- Vector3 currentPosition;
- Vector3 currentVelocity;
- bool moving;
- bool fired;
- bool reloaded;
- void render(double timeStep){
- if(!fired) //We don't want anything to happen if bullet isn't fired yet
- return;
- if(moving){ //We only want to calculate the new position if the bullet is moving
- currentPosition += currentVelocity * timeStep;
- /* set currentVelocity with respect to air friction, gravity and magic */
- if(currentPosition.z <= 0.0){ //If the z-coordinate is 0 or less (= if it hit the ground)
- currentPosition.z = 0;
- moving = false; //We want it to stop moving
- }
- }
- //Draw
- glBegin(GL_TRIANGLE)
- glTranslate(currentPosition.x, currentPosition.y, currentPosition.z);
- DrawCube();
- glEnd();
- }
- //Constructor only sets everything to 0.
- Bullet()
- : currentPosition(0,0,0),
- currentVelocity(0,0,0)
- moving(false),
- fired(false),
- reloaded(false),
- {}
- };
- Bullet g_bullet;
- void main(){
- g_bullet.currentVelocity = Vector3(5,0,1); //Starting velocity
- }
- void Render()
- {
- g_bullet.render( 0.01 ); //Bullet travels 0.01 time units every frame.
- glutSwapBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement