| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 5 |  | 
|---|
| 6 |    Copyright (C) 2004 orx | 
|---|
| 7 |  | 
|---|
| 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |    it under the terms of the GNU General Public License as published by | 
|---|
| 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 |    any later version. | 
|---|
| 12 |  | 
|---|
| 13 |    ### File Specific | 
|---|
| 14 |    main-programmer: Patrick Boenzli | 
|---|
| 15 |    co-programmer: | 
|---|
| 16 | */ | 
|---|
| 17 |  | 
|---|
| 18 |  | 
|---|
| 19 | #include "projectile.h" | 
|---|
| 20 |  | 
|---|
| 21 | #include "world_entity.h" | 
|---|
| 22 | #include "weapon.h" | 
|---|
| 23 | #include "null_parent.h" | 
|---|
| 24 | #include "model.h" | 
|---|
| 25 | #include "vector.h" | 
|---|
| 26 |  | 
|---|
| 27 | using namespace std; | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 | /** | 
|---|
| 31 |  *  standard constructor | 
|---|
| 32 | */ | 
|---|
| 33 | Projectile::Projectile () : WorldEntity() | 
|---|
| 34 | { | 
|---|
| 35 |   this->setClassID(CL_PROJECTILE, "Projectile"); | 
|---|
| 36 |  | 
|---|
| 37 |   this->lifeCycle = 0.0; | 
|---|
| 38 |   this->lifeSpan = 0.75f; /* sec */ | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 |  | 
|---|
| 42 | /** | 
|---|
| 43 |  *  standard deconstructor | 
|---|
| 44 | */ | 
|---|
| 45 | Projectile::~Projectile () | 
|---|
| 46 | { | 
|---|
| 47 |   /* | 
|---|
| 48 |      do not delete the test projectModel, since it is pnode | 
|---|
| 49 |      and will be cleaned out by world | 
|---|
| 50 |   */ | 
|---|
| 51 |   //delete this->projectileModel; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 |  *  this sets the flight direction of the projectile | 
|---|
| 57 |  * @param directin in which to flight | 
|---|
| 58 |  | 
|---|
| 59 |    this function will calculate a vector out of this to be used in the | 
|---|
| 60 |    tick function | 
|---|
| 61 | */ | 
|---|
| 62 | void Projectile::setFlightDirection(const Quaternion& flightDirection) | 
|---|
| 63 | { | 
|---|
| 64 |   Vector v(1, 0, 0); | 
|---|
| 65 |   this->flightDirection = flightDirection.apply(v); | 
|---|
| 66 |   this->flightDirection.normalize(); | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | /** | 
|---|
| 70 |  *  sets the velocity vector to a spec speed | 
|---|
| 71 |  * @param velocity: vector of the velocity | 
|---|
| 72 | */ | 
|---|
| 73 | void Projectile::setVelocity(const Vector &velocity) | 
|---|
| 74 | { | 
|---|
| 75 |   Vector offsetVel = this->velocity = velocity; | 
|---|
| 76 |   offsetVel.normalize(); | 
|---|
| 77 |   this->velocity += (offsetVel * 50.0); | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | /** | 
|---|
| 81 |  * signal tick, time dependent things will be handled here | 
|---|
| 82 |  * @param time since last tick | 
|---|
| 83 | */ | 
|---|
| 84 | void Projectile::tick (float time) | 
|---|
| 85 | { | 
|---|
| 86 |   Vector v = this->velocity * (time); | 
|---|
| 87 |   this->shiftCoor(v); | 
|---|
| 88 |  | 
|---|
| 89 |   this->lifeCycle += time/this->lifeSpan; | 
|---|
| 90 |   if( this->lifeCycle >= 1) | 
|---|
| 91 |   { | 
|---|
| 92 |     PRINTF(5)("FINALIZE==========================\n"); | 
|---|
| 93 |     PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); | 
|---|
| 94 |     PRINTF(5)("FINALIZE===========================\n"); | 
|---|
| 95 |     this->finalize(); | 
|---|
| 96 |   } | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | /** | 
|---|
| 101 |  *  the function gets called, when the projectile is destroyed | 
|---|
| 102 | */ | 
|---|
| 103 | void Projectile::destroy () | 
|---|
| 104 | {} | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 | void Projectile::draw () | 
|---|
| 108 | { | 
|---|
| 109 |   glMatrixMode(GL_MODELVIEW); | 
|---|
| 110 |   glPushMatrix(); | 
|---|
| 111 |  | 
|---|
| 112 |   float matrix[4][4]; | 
|---|
| 113 |   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); | 
|---|
| 114 |   this->getAbsDir().matrix (matrix); | 
|---|
| 115 |   glMultMatrixf((float*)matrix); | 
|---|
| 116 |   this->model->draw(); | 
|---|
| 117 |  | 
|---|
| 118 |   glPopMatrix(); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|