Changeset 9995 for code/branches/modularships/src/orxonox
- Timestamp:
- Mar 9, 2014, 9:01:44 PM (11 years ago)
- Location:
- code/branches/modularships/src/orxonox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/modularships/src/orxonox/Scene.cc
r9667 r9995 201 201 // Note: This is a global variable which we assign a static function. 202 202 // TODO: Check whether this (or anything about Bullet) works with multiple physics engine instances. 203 gContactAddedCallback = &Scene::c ollisionCallback;203 gContactAddedCallback = &Scene::customCollisionCallback; 204 204 } 205 205 else if (!wantPhysics && hasPhysics()) … … 358 358 return modified; 359 359 } 360 361 /* ADDED static*/ bool Scene::customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, 362 int index0, const btCollisionObject* colObj1, int partId1, int index1) 363 { 364 // get the WorldEntity pointers 365 SmartPtr<WorldEntity> object0 = static_cast<WorldEntity*>(colObj0->getUserPointer()); 366 SmartPtr<WorldEntity> object1 = static_cast<WorldEntity*>(colObj1->getUserPointer()); 367 368 // get the CollisionShape pointers 369 const btCollisionShape* cs0 = colObj0->getCollisionShape(); 370 const btCollisionShape* cs1 = colObj1->getCollisionShape(); 371 372 // false means that bullet will assume we didn't modify the contact 373 bool modified = false; 374 if (object0->isCollisionCallbackActive()) 375 modified |= object0->customCollidesAgainst(object1, cs0, cp); 376 if (object1->isCollisionCallbackActive()) 377 modified |= object1->customCollidesAgainst(object0, cs1, cp); 378 379 return modified; 380 } 360 381 } -
code/branches/modularships/src/orxonox/Scene.h
r9667 r9995 143 143 int index0, const btCollisionObject* colObj1, int partId1, int index1); 144 144 145 static bool customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0, 146 int index0, const btCollisionObject* colObj1, int partId1, int index1); 147 145 148 // Bullet objects 146 149 btDiscreteDynamicsWorld* physicalWorld_; -
code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc
r9667 r9995 87 87 } 88 88 89 bool MovableEntity::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 90 { 91 if (GameMode::isMaster() && enableCollisionDamage_) 92 { 93 Pawn* victim = orxonox_cast<Pawn*>(otherObject); 94 if (victim) 95 { 96 float damage = this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length(); 97 victim->customHit(0, contactPoint, ownCollisionShape, damage); 98 } 99 } 100 101 return false; 102 } 103 89 104 90 105 void MovableEntity::registerVariables() -
code/branches/modularships/src/orxonox/worldentities/MovableEntity.h
r9667 r9995 48 48 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 49 49 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 50 virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint); 50 51 51 52 using WorldEntity::setPosition; -
code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
r9667 r9995 375 375 */ 376 376 virtual inline bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 377 { return false; } /* With false, Bullet assumes no modification to the collision objects. */ 378 379 virtual inline bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) 377 380 { return false; } /* With false, Bullet assumes no modification to the collision objects. */ 378 381 -
code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
r9950 r9995 274 274 } 275 275 276 void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) 277 { 278 // Applies multiplier given by the DamageBoost Pickup. 279 if (originator) 280 damage *= originator->getDamageMultiplier(); 281 282 orxout() << "damage(): Custom collision detected on CS: " << cs << endl; 283 284 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 285 { 286 if (shielddamage >= this->getShieldHealth()) 287 { 288 this->setShieldHealth(0); 289 this->setHealth(this->health_ - (healthdamage + damage)); 290 } 291 else 292 { 293 this->setShieldHealth(this->shieldHealth_ - shielddamage); 294 295 // remove remaining shieldAbsorpton-Part of damage from shield 296 shielddamage = damage * this->shieldAbsorption_; 297 shielddamage = std::min(this->getShieldHealth(),shielddamage); 298 this->setShieldHealth(this->shieldHealth_ - shielddamage); 299 300 // set remaining damage to health 301 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); 302 } 303 304 this->lastHitOriginator_ = originator; 305 } 306 } 307 276 308 // TODO: Still valid? 277 309 /* HIT-Funktionen … … 288 320 } 289 321 322 void Pawn::customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) 323 { 324 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 325 { 326 this->customDamage(damage, healthdamage, shielddamage, originator, cs); 327 this->setVelocity(this->getVelocity() + force); 328 } 329 } 290 330 291 331 void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage) … … 294 334 { 295 335 this->damage(damage, healthdamage, shielddamage, originator); 336 337 if ( this->getController() ) 338 this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage? 339 } 340 } 341 342 void Pawn::customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage) 343 { 344 if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) ) 345 { 346 this->customDamage(damage, healthdamage, shielddamage, originator, cs); 296 347 297 348 if ( this->getController() ) -
code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
r9948 r9995 127 127 //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 128 128 virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 129 virtual void customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 129 130 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 131 virtual void customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 130 132 131 133 virtual void kill(); … … 197 199 //virtual void damage(float damage, Pawn* originator = 0); 198 200 virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL); 201 virtual void customDamage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL); 199 202 200 203 bool bAlive_;
Note: See TracChangeset
for help on using the changeset viewer.