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