[3573] | 1 | |
---|
| 2 | |
---|
[4597] | 3 | /* |
---|
[3573] | 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 |
---|
[4597] | 15 | co-programmer: |
---|
[3573] | 16 | */ |
---|
[5357] | 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3573] | 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 | |
---|
[4941] | 27 | #include "garbage_collector.h" |
---|
| 28 | |
---|
[3573] | 29 | using namespace std; |
---|
| 30 | |
---|
| 31 | |
---|
[3578] | 32 | /** |
---|
[4836] | 33 | * standard constructor |
---|
[3578] | 34 | */ |
---|
[4932] | 35 | Projectile::Projectile () : WorldEntity() |
---|
[3573] | 36 | { |
---|
[4322] | 37 | this->setClassID(CL_PROJECTILE, "Projectile"); |
---|
[4597] | 38 | |
---|
[4890] | 39 | this->lifeCycle = 0.0; |
---|
[5063] | 40 | this->lifeSpan = 1.0f; /* sec */ |
---|
[4979] | 41 | |
---|
| 42 | this->remove(); |
---|
[3573] | 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
[3578] | 46 | /** |
---|
[4836] | 47 | * standard deconstructor |
---|
[3578] | 48 | */ |
---|
[4597] | 49 | Projectile::~Projectile () |
---|
[3573] | 50 | { |
---|
[4597] | 51 | /* |
---|
| 52 | do not delete the test projectModel, since it is pnode |
---|
| 53 | and will be cleaned out by world |
---|
[3629] | 54 | */ |
---|
| 55 | //delete this->projectileModel; |
---|
[3573] | 56 | } |
---|
| 57 | |
---|
[3578] | 58 | |
---|
[4948] | 59 | void Projectile::setEnergies(float energyMin, float energyMax) |
---|
| 60 | { |
---|
| 61 | this->energyMin = energyMin; |
---|
| 62 | if (energyMax <= energyMin) |
---|
| 63 | { |
---|
| 64 | this->bChargeable = false; |
---|
| 65 | this->energyMax = energyMin; |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | this->bChargeable = true; |
---|
| 70 | this->energyMax = energyMax; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | |
---|
[3578] | 75 | /** |
---|
[4836] | 76 | * this sets the flight direction of the projectile |
---|
| 77 | * @param directin in which to flight |
---|
[3632] | 78 | |
---|
| 79 | this function will calculate a vector out of this to be used in the |
---|
| 80 | tick function |
---|
| 81 | */ |
---|
[4927] | 82 | void Projectile::setFlightDirection(const Quaternion& flightDirection) |
---|
[3632] | 83 | { |
---|
| 84 | Vector v(1, 0, 0); |
---|
[4890] | 85 | this->flightDirection = flightDirection.apply(v); |
---|
| 86 | this->flightDirection.normalize(); |
---|
[3632] | 87 | } |
---|
| 88 | |
---|
| 89 | /** |
---|
[4836] | 90 | * sets the velocity vector to a spec speed |
---|
| 91 | * @param velocity: vector of the velocity |
---|
[4464] | 92 | */ |
---|
| 93 | void Projectile::setVelocity(const Vector &velocity) |
---|
| 94 | { |
---|
[4955] | 95 | //Vector offsetVel = |
---|
| 96 | this->velocity = velocity; |
---|
| 97 | // offsetVel.normalize(); |
---|
| 98 | //this->velocity += (offsetVel * 50.0); |
---|
[4464] | 99 | } |
---|
| 100 | |
---|
| 101 | /** |
---|
[4927] | 102 | * signal tick, time dependent things will be handled here |
---|
[4836] | 103 | * @param time since last tick |
---|
[3578] | 104 | */ |
---|
[4597] | 105 | void Projectile::tick (float time) |
---|
[3632] | 106 | { |
---|
[4464] | 107 | Vector v = this->velocity * (time); |
---|
[3686] | 108 | this->shiftCoor(v); |
---|
[3683] | 109 | |
---|
[4890] | 110 | this->lifeCycle += time/this->lifeSpan; |
---|
| 111 | if( this->lifeCycle >= 1) |
---|
| 112 | { |
---|
| 113 | PRINTF(5)("FINALIZE==========================\n"); |
---|
| 114 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
| 115 | PRINTF(5)("FINALIZE===========================\n"); |
---|
[4941] | 116 | //this->finalize(); |
---|
| 117 | GarbageCollector::getInstance()->collect(this); |
---|
[4890] | 118 | } |
---|
[3632] | 119 | } |
---|
[3573] | 120 | |
---|
| 121 | |
---|
[3578] | 122 | /** |
---|
[4836] | 123 | * the function gets called, when the projectile is destroyed |
---|
[3578] | 124 | */ |
---|
[4597] | 125 | void Projectile::destroy () |
---|
[3574] | 126 | {} |
---|
[3573] | 127 | |
---|
| 128 | |
---|
[4597] | 129 | void Projectile::draw () |
---|
[3573] | 130 | { |
---|
| 131 | glMatrixMode(GL_MODELVIEW); |
---|
| 132 | glPushMatrix(); |
---|
[3574] | 133 | |
---|
[4597] | 134 | float matrix[4][4]; |
---|
[3573] | 135 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 136 | this->getAbsDir().matrix (matrix); |
---|
[4597] | 137 | glMultMatrixf((float*)matrix); |
---|
[3672] | 138 | this->model->draw(); |
---|
[3573] | 139 | |
---|
| 140 | glPopMatrix(); |
---|
| 141 | } |
---|
| 142 | |
---|