Changeset 10035 in orxonox.OLD for branches/playability/src/world_entities/projectiles
- Timestamp:
- Dec 9, 2006, 7:00:44 PM (18 years ago)
- Location:
- branches/playability/src/world_entities/projectiles
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/playability/src/world_entities/projectiles/projectile.cc
r10020 r10035 167 167 * @return normalized (new) direction vector 168 168 */ 169 Vector Projectile::newDirection(Vector curDirection, Vector estTargetDir, float angle) 170 { 171 float tmp = angleDeg ( curDirection, estTargetDir); 172 if (tmp == 0) { return curDirection; } 173 174 if( angle > tmp ) { angle = tmp; } 175 176 //Vector n = curDirection.cross(estTargetDir); 177 //Vector d = n.cross(curDirection); 178 Vector d = curDirection.cross(estTargetDir).cross(curDirection); 179 d.normalize(); 180 if( angle == 90) { return d; } 181 182 Vector newDir = curDirection + d * curDirection.len() * tan (angle); 183 newDir.normalize(); 184 return newDir; 185 } 169 // Vector Projectile::newDirection(Vector curDirection, Vector estTargetDir, float angle) 170 // { 171 // float tmp = angleDeg ( curDirection, estTargetDir); 172 // if ( unlikely(tmp == 0) ) { return curDirection; } 173 // 174 // if( fabsf(angle) > fabsf(tmp) ) { angle = tmp; } 175 // 176 // Vector d = curDirection.cross(estTargetDir).cross(curDirection); 177 // d.normalize(); 178 // if( unlikely( angle == 90)) { return d; } 179 // 180 // Vector newDir = curDirection + d * curDirection.len() * tan (angle); 181 // newDir.normalize(); 182 // return newDir; 183 // } 186 184 187 185 … … 192 190 void Projectile::tick (float dt) 193 191 { 194 float tti = 0; //!< time to impact 195 Vector estTargetDir = (this->target->getRelCoor() + this->target->getVelocity()); 196 this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * dt ) * this->velocity.len(); 197 Vector v = this->velocity * (dt); 198 this->shiftCoor(v); 192 /* 193 if (target != NULL){ 194 float tti = this->target->getRelCoor().len() / this->getVelocity().len(); 195 Vector estTargetDir = (this->target->getRelCoor() + this->target->getVelocity()) * tti; 196 this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * dt ) * this->velocity.len(); 197 Vector v = this->velocity * (dt); 198 this->shiftCoor(v); 199 }*/ 199 200 200 201 if (this->tickLifeCycle(dt)) -
branches/playability/src/world_entities/projectiles/projectile.h
r9969 r10035 62 62 inline float getElecDamage() { return this->elecDamage; }; 63 63 64 inline void setPhysDamage( float dmg) {this->physDamage = dmg; }; 65 inline void setElecDamage( float dmg) {this->elecDamage = dmg; }; 66 64 67 protected: 65 68 // energy … … 88 91 OrxSound::SoundBuffer engineBuffer; 89 92 90 virtual Vector newDirection(Vector curDirection, Vector estTargetDir, float angle);93 // virtual Vector newDirection(Vector curDirection, Vector estTargetDir, float angle); 91 94 }; 92 95 -
branches/playability/src/world_entities/projectiles/swarm_projectile.cc
r10004 r10035 37 37 { 38 38 39 this->loadModel("models/projectiles/orx-rocket.obj", 0.5); 39 /* this->loadModel("models/projectiles/orx-rocket.obj", 0.5);*/ 40 this->loadModel("models/projectiles/swarm_projectile.obj"); 40 41 this->loadExplosionSound("sound/explosions/explosion_4.wav"); 41 42 … … 45 46 this->lifeSpan = 2.0; 46 47 this->agility = 3.5; 47 this->maxVelocity = 1 50;48 this->maxVelocity = 100; 48 49 49 50 this->emitter = new DotEmitter(100, 5, M_2_PI); … … 141 142 } 142 143 144 145 146 /** 147 * this function gets called by tick to calculate the new flight direction 148 * @param curDirection direction vector 149 * @param estTargetDir target vector, pointing to where the target will be on hit 150 * @param angle = tick * turningSpeed 151 * @return (new) direction vector 152 */ 153 Vector SwarmProjectile::newDirection(Vector curDirection, Vector estTargetDir, float angle) 154 { 155 printf("recalculating direction\n"); 156 float tmp = angleDeg ( curDirection, estTargetDir); 157 if ( unlikely(tmp == 0) ) { return curDirection * maxVelocity / curDirection.len(); } 158 159 if( fabsf(angle) > fabsf(tmp) ) { angle = tmp; } 160 161 Vector d = curDirection.cross(estTargetDir).cross(curDirection); 162 d.normalize(); 163 if( unlikely( angle == 90)) { return d; } //avoid complication 164 165 Vector newDir = curDirection + d * curDirection.len() * tan (angle); 166 newDir.normalize(); 167 newDir *= curDirection.len(); 168 return newDir; 169 } 170 171 172 173 143 174 /** 144 175 * signal tick, time dependent things will be handled here … … 147 178 void SwarmProjectile::tick (float time) 148 179 { 149 180 /* 150 181 Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0); 151 182 … … 173 204 velocity *= maxVelocity/velocity.len(); 174 205 Vector v = this->velocity * (time); 175 this->shiftCoor(v); 206 this->shiftCoor(v);*/ 207 208 if (target != NULL){ 209 float tti = this->target->getRelCoor().len() / this->getVelocity().len(); 210 Vector estTargetDir = (this->target->getRelCoor() + this->target->getVelocity()) * tti; 211 this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * time ); 212 } 213 else 214 velocity *= maxVelocity / velocity.len(); // set speed to max 215 216 this->shiftCoor(velocity * time); 176 217 177 218 if(this->tickLifeCycle(time)) … … 208 249 this->getAbsDir().matrix (matrix); 209 250 glMultMatrixf((float*)matrix); 210 glScalef(2.0, 2.0, 2.0);251 //glScalef(2.0, 2.0, 2.0); 211 252 this->getModel()->draw(); 212 253 -
branches/playability/src/world_entities/projectiles/swarm_projectile.h
r10004 r10035 45 45 Vector correctionVector; 46 46 47 PNode* target; 48 47 49 WorldEntity* hitEntity; // FIXME TEMPORARY 50 51 Vector newDirection(Vector curDirection, Vector estTargetDir, float angle); 48 52 49 53 };
Note: See TracChangeset
for help on using the changeset viewer.