[Orxonox-commit 5332] r9995 - in code/branches/modularships: data/levels src/modules/weapons/projectiles src/orxonox src/orxonox/worldentities src/orxonox/worldentities/pawns

noep at orxonox.net noep at orxonox.net
Sun Mar 9 21:01:45 CET 2014


Author: noep
Date: 2014-03-09 21:01:44 +0100 (Sun, 09 Mar 2014)
New Revision: 9995

Modified:
   code/branches/modularships/data/levels/emptyLevel.oxw
   code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc
   code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h
   code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc
   code/branches/modularships/src/modules/weapons/projectiles/Projectile.h
   code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc
   code/branches/modularships/src/modules/weapons/projectiles/Rocket.h
   code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc
   code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h
   code/branches/modularships/src/orxonox/Scene.cc
   code/branches/modularships/src/orxonox/Scene.h
   code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc
   code/branches/modularships/src/orxonox/worldentities/MovableEntity.h
   code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
   code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
   code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
Log:
Modified collision-detecting-process, such that collisions can be traced back to single child-CollisionShapes of Compound-CollisionShapes

Modified: code/branches/modularships/data/levels/emptyLevel.oxw
===================================================================
--- code/branches/modularships/data/levels/emptyLevel.oxw	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/data/levels/emptyLevel.oxw	2014-03-09 20:01:44 UTC (rev 9995)
@@ -31,6 +31,32 @@
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
     
+    <MovableEntity position="0,0,0" collisionType=dynamic scale=1 linearDamping=0.8 angularDamping=0  collisiondamage=0.005 enablecollisiondamage=true>
+    <attached> 
+        <Model position="0,0,0" mesh="cube.mesh" scale3D="40,40,40" /> 
+        <StaticEntity position="0,90,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
+            <attached> 
+                <Model position="0,0,0" mesh="cube.mesh" scale3D="30,30,30" /> 
+            </attached> 
+            <collisionShapes> 
+                <BoxCollisionShape position="0,0,0" halfExtents="30,30,30" /> 
+            </collisionShapes> 
+        </StaticEntity>
+    </attached> 
+    <collisionShapes> 
+        <BoxCollisionShape position="0,0,0" halfExtents="40,40,40" /> 
+    </collisionShapes> 
+    </MovableEntity>
+    
+    <Pawn health=30 position="0,-50,0" direction="0,-1,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
+        <attached>
+            <Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
+        </attached>
+        <collisionShapes>
+            <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
+        </collisionShapes>
+    </Pawn>
+    
   </Scene>
 </Level>
 

Modified: code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -140,6 +140,69 @@
         return false;
     }
 
+    bool BasicProjectile::customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
+        {
+            if (!this->bDestroy_ && GameMode::isMaster())
+            {
+                if (otherObject == this->getShooter()) // Prevents you from shooting yourself
+                    return false;
+
+                this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
+                                        // The projectile is destroyed by its tick()-function (in the following tick).
+
+                Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL
+
+                WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
+                assert(entity); // The projectile must not be a WorldEntity.
+
+                // If visual effects after destruction cause problems, put this block below the effects code block
+                if (victim)
+                {
+                    victim->customHit(this->getShooter(), contactPoint, cs, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
+                    victim->startReloadCountdown();
+                }
+
+                // Visual effects for being hit, depending on whether the shield is hit or not
+                if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed.
+                {
+                    // Damping and explosion effect is only played if the victim is no Pawn (see cast above)
+                    // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health
+                    if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f)))
+                    {
+                        {
+                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
+                            effect->setPosition(entity->getPosition());
+                            effect->setOrientation(entity->getOrientation());
+                            effect->setDestroyAfterLife(true);
+                            effect->setSource("Orxonox/explosion3");
+                            effect->setLifetime(2.0f);
+                        }
+                        // Second effect with same condition
+                        {
+                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
+                            effect->setPosition(entity->getPosition());
+                            effect->setOrientation(entity->getOrientation());
+                            effect->setDestroyAfterLife(true);
+                            effect->setSource("Orxonox/smoke4");
+                            effect->setLifetime(3.0f);
+                        }
+                    }
+
+                    // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
+                    if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f)
+                    {
+                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
+                        effect->setDestroyAfterLife(true);
+                        effect->setSource("Orxonox/Shield");
+                        effect->setLifetime(0.5f);
+                        victim->attach(effect);
+                    }
+                }
+                return true;
+            }
+            return false;
+        }
+
     /**
     @brief
         Check whether the projectile needs to be destroyed and destroys it if so.

Modified: code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -119,6 +119,7 @@
 
         protected:
             bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint);
+            bool customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
             void destroyCheck(void);
 
         private:

Modified: code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -92,4 +92,9 @@
         return this->processCollision(otherObject, contactPoint);
     }
 
+    bool Projectile::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
+    {
+        return this->customProcessCollision(otherObject, contactPoint, cs);
+    }
+
 }

Modified: code/branches/modularships/src/modules/weapons/projectiles/Projectile.h
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/Projectile.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/Projectile.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -64,6 +64,7 @@
 
             virtual void tick(float dt);
             virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
+            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
 
         private:
             float lifetime_; //!< The time the projectile exists.

Modified: code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -195,6 +195,11 @@
         return this->processCollision(otherObject, contactPoint);
     }
 
+    bool Rocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
+    {
+        return this->customProcessCollision(otherObject, contactPoint, cs);
+    }
+
     /**
     @brief
         Destroys the Rocket and stops the sound,

Modified: code/branches/modularships/src/modules/weapons/projectiles/Rocket.h
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/Rocket.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/Rocket.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -64,6 +64,7 @@
             virtual void tick(float dt); //!< Defines which actions the Rocket has to take in each tick.
 
             virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
+            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
             virtual void destroyObject(void);
             void destructionEffect();
 

Modified: code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -176,6 +176,11 @@
         return this->processCollision(otherObject, contactPoint);
     }
 
+    bool SimpleRocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
+    {
+        return this->customProcessCollision(otherObject, contactPoint, cs);
+    }
+
     /**
     @brief
         Rotates the SimpleRocket around the y-axis by the amount specified by the first component of the input 2-dim vector.

Modified: code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h
===================================================================
--- code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -64,6 +64,7 @@
             virtual void tick(float dt);
 
             virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
+            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
 
             void disableFire(); //!< Method to disable the fire and stop all acceleration
 

Modified: code/branches/modularships/src/orxonox/Scene.cc
===================================================================
--- code/branches/modularships/src/orxonox/Scene.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/Scene.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -200,7 +200,7 @@
             // also set the collision callback variable.
             // Note: This is a global variable which we assign a static function.
             // TODO: Check whether this (or anything about Bullet) works with multiple physics engine instances.
-            gContactAddedCallback = &Scene::collisionCallback;
+            gContactAddedCallback = &Scene::customCollisionCallback;
         }
         else if (!wantPhysics && hasPhysics())
         {
@@ -357,4 +357,25 @@
 
         return modified;
     }
+
+    /* ADDED static*/ bool Scene::customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,
+                                             int index0, const btCollisionObject* colObj1, int partId1, int index1)
+    {
+        // get the WorldEntity pointers
+        SmartPtr<WorldEntity> object0 = static_cast<WorldEntity*>(colObj0->getUserPointer());
+        SmartPtr<WorldEntity> object1 = static_cast<WorldEntity*>(colObj1->getUserPointer());
+
+        // get the CollisionShape pointers
+        const btCollisionShape* cs0 = colObj0->getCollisionShape();
+        const btCollisionShape* cs1 = colObj1->getCollisionShape();
+
+        // false means that bullet will assume we didn't modify the contact
+        bool modified = false;
+        if (object0->isCollisionCallbackActive())
+            modified |= object0->customCollidesAgainst(object1, cs0, cp);
+        if (object1->isCollisionCallbackActive())
+            modified |= object1->customCollidesAgainst(object0, cs1, cp);
+
+        return modified;
+    }
 }

Modified: code/branches/modularships/src/orxonox/Scene.h
===================================================================
--- code/branches/modularships/src/orxonox/Scene.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/Scene.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -142,6 +142,9 @@
             static bool collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,
                                           int index0, const btCollisionObject* colObj1, int partId1, int index1);
 
+            static bool customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,
+                                                      int index0, const btCollisionObject* colObj1, int partId1, int index1);
+
             // Bullet objects
             btDiscreteDynamicsWorld*             physicalWorld_;
             bt32BitAxisSweep3*                   broadphase_;

Modified: code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -86,7 +86,22 @@
         return false;
     }
 
+    bool MovableEntity::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+    {
+        if (GameMode::isMaster() && enableCollisionDamage_)
+        {
+            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
+            if (victim)
+            {
+                float damage = this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length();
+                victim->customHit(0, contactPoint, ownCollisionShape, damage);
+            }
+        }
 
+        return false;
+    }
+
+
     void MovableEntity::registerVariables()
     {
         registerVariable(this->linearVelocity_,        VariableDirection::ToClient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));

Modified: code/branches/modularships/src/orxonox/worldentities/MovableEntity.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/MovableEntity.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/worldentities/MovableEntity.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -47,6 +47,7 @@
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
+            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
 
             using WorldEntity::setPosition;
             using WorldEntity::setOrientation;

Modified: code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -376,6 +376,9 @@
             virtual inline bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
                 { return false; } /* With false, Bullet assumes no modification to the collision objects. */
 
+            virtual inline bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+                { return false; } /* With false, Bullet assumes no modification to the collision objects. */
+
             //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
             inline void enableCollisionCallback()
                 { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	2014-03-09 20:01:44 UTC (rev 9995)
@@ -273,6 +273,38 @@
         }
     }
 
+    void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
+    {
+        // Applies multiplier given by the DamageBoost Pickup.
+        if (originator)
+            damage *= originator->getDamageMultiplier();
+
+        orxout() << "damage(): Custom collision detected on CS: " << cs << endl;
+
+        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
+        {
+            if (shielddamage >= this->getShieldHealth())
+            {
+                this->setShieldHealth(0);
+                this->setHealth(this->health_ - (healthdamage + damage));
+            }
+            else
+            {
+                this->setShieldHealth(this->shieldHealth_ - shielddamage);
+
+                // remove remaining shieldAbsorpton-Part of damage from shield
+                shielddamage = damage * this->shieldAbsorption_;
+                shielddamage = std::min(this->getShieldHealth(),shielddamage);
+                this->setShieldHealth(this->shieldHealth_ - shielddamage);
+
+                // set remaining damage to health
+                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
+            }
+
+            this->lastHitOriginator_ = originator;
+        }
+    }
+
 // TODO: Still valid?
 /* HIT-Funktionen
     Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
@@ -287,6 +319,14 @@
         }
     }
 
+    void Pawn::customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
+    {
+        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
+        {
+            this->customDamage(damage, healthdamage, shielddamage, originator, cs);
+            this->setVelocity(this->getVelocity() + force);
+        }
+    }
 
     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
     {
@@ -299,7 +339,18 @@
         }
     }
 
+    void Pawn::customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
+    {
+        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
+        {
+            this->customDamage(damage, healthdamage, shielddamage, originator, cs);
 
+            if ( this->getController() )
+                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
+        }
+    }
+
+
     void Pawn::kill()
     {
         this->damage(this->health_);

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	2014-03-06 13:38:47 UTC (rev 9994)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	2014-03-09 20:01:44 UTC (rev 9995)
@@ -126,7 +126,9 @@
             //virtual void hit(Pawn* originator, const Vector3& force, float damage);
             //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
             virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
+            virtual void customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
+            virtual void customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
 
             virtual void kill();
 
@@ -196,6 +198,7 @@
 
             //virtual void damage(float damage, Pawn* originator = 0);
             virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL);
+            virtual void customDamage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
 
             bool bAlive_;
 




More information about the Orxonox-commit mailing list