| 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 |    \brief standard constructor | 
|---|
| 32 | */ | 
|---|
| 33 | Projectile::Projectile (Weapon* weapon) : WorldEntity() | 
|---|
| 34 | { | 
|---|
| 35 |   this->setClassID(CL_PROJECTILE, "Projectile"); | 
|---|
| 36 |  | 
|---|
| 37 |   this->weapon = weapon; | 
|---|
| 38 |   this->flightDirection = NULL; | 
|---|
| 39 |   this->currentLifeTime = 0.0f; | 
|---|
| 40 |   this->ttl = 0.75f; /* sec */ | 
|---|
| 41 |   this->speed = 2.0f; | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | /** | 
|---|
| 46 |    \brief standard deconstructor | 
|---|
| 47 | */ | 
|---|
| 48 | Projectile::~Projectile () | 
|---|
| 49 | { | 
|---|
| 50 |   /* | 
|---|
| 51 |      do not delete the test projectModel, since it is pnode | 
|---|
| 52 |      and will be cleaned out by world | 
|---|
| 53 |   */ | 
|---|
| 54 |   //delete this->projectileModel; | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | /** | 
|---|
| 59 |    \brief this sets the flight direction of the projectile | 
|---|
| 60 |    \param directin in which to flight | 
|---|
| 61 |  | 
|---|
| 62 |    this function will calculate a vector out of this to be used in the | 
|---|
| 63 |    tick function | 
|---|
| 64 | */ | 
|---|
| 65 | void Projectile::setFlightDirection(Quaternion flightDirection) | 
|---|
| 66 | { | 
|---|
| 67 |   if( this->flightDirection == NULL) | 
|---|
| 68 |     this->flightDirection = new Vector(); | 
|---|
| 69 |   Vector v(1, 0, 0); | 
|---|
| 70 |   *this->flightDirection = flightDirection.apply(v); | 
|---|
| 71 |   this->flightDirection->normalize(); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 |  | 
|---|
| 75 | /** | 
|---|
| 76 |    \brief this sets the time to life of the projectile | 
|---|
| 77 |    \param ttl in second | 
|---|
| 78 |  | 
|---|
| 79 |    after this life time, the projectile will garbage collect itself | 
|---|
| 80 | */ | 
|---|
| 81 | void Projectile::setTTL(float ttl) | 
|---|
| 82 | { | 
|---|
| 83 |   this->ttl = ttl; | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 | /** | 
|---|
| 88 |    \brief sets the speed of the projectile | 
|---|
| 89 | */ | 
|---|
| 90 | void Projectile::setSpeed(float speed) | 
|---|
| 91 | { | 
|---|
| 92 |   this->speed = speed * 3; /* fix speed settings */ | 
|---|
| 93 |   PRINTF(4)("Projectile::setting speed to: %f\n", this->speed); | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | /** | 
|---|
| 98 |    \brief sets the velocity vector to a spec speed | 
|---|
| 99 |    \param velocity: vector of the velocity | 
|---|
| 100 | */ | 
|---|
| 101 | void Projectile::setVelocity(const Vector &velocity) | 
|---|
| 102 | { | 
|---|
| 103 |   this->offsetVel = this->velocity = velocity; | 
|---|
| 104 |   this->offsetVel.normalize(); | 
|---|
| 105 |   this->velocity += (this->offsetVel * 50.0); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 |    \brief signal tick, time dependent things will be handled here | 
|---|
| 111 |    \param time since last tick | 
|---|
| 112 | */ | 
|---|
| 113 | void Projectile::tick (float time) | 
|---|
| 114 | { | 
|---|
| 115 |   Vector v = this->velocity * (time); | 
|---|
| 116 |   this->shiftCoor(v); | 
|---|
| 117 |  | 
|---|
| 118 |   this->currentLifeTime += time; | 
|---|
| 119 |   if( this->ttl < this->currentLifeTime) | 
|---|
| 120 |     { | 
|---|
| 121 |       PRINTF(5)("FINALIZE==========================\n"); | 
|---|
| 122 |       PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl); | 
|---|
| 123 |       PRINTF(5)("FINALIZE===========================\n"); | 
|---|
| 124 |       this->finalize(); | 
|---|
| 125 |       this->currentLifeTime = 0.0f; | 
|---|
| 126 |     } | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | /** | 
|---|
| 130 |    \brief the projectile gets hit by another entity | 
|---|
| 131 |    \param the other entity | 
|---|
| 132 |    \param place where it is hit | 
|---|
| 133 | */ | 
|---|
| 134 | void Projectile::hit (WorldEntity* entity, Vector* place) | 
|---|
| 135 | {} | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | /** | 
|---|
| 139 |    \brief the function gets called, when the projectile is destroyed | 
|---|
| 140 | */ | 
|---|
| 141 | void Projectile::destroy () | 
|---|
| 142 | {} | 
|---|
| 143 |  | 
|---|
| 144 |  | 
|---|
| 145 | void Projectile::draw () | 
|---|
| 146 | { | 
|---|
| 147 |   glMatrixMode(GL_MODELVIEW); | 
|---|
| 148 |   glPushMatrix(); | 
|---|
| 149 |  | 
|---|
| 150 |   float matrix[4][4]; | 
|---|
| 151 |   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); | 
|---|
| 152 |   this->getAbsDir().matrix (matrix); | 
|---|
| 153 |   glMultMatrixf((float*)matrix); | 
|---|
| 154 |   this->model->draw(); | 
|---|
| 155 |  | 
|---|
| 156 |   glPopMatrix(); | 
|---|
| 157 | } | 
|---|
| 158 |  | 
|---|