Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2014, 9:01:44 PM (11 years ago)
Author:
noep
Message:

Modified collision-detecting-process, such that collisions can be traced back to single child-CollisionShapes of Compound-CollisionShapes

Location:
code/branches/modularships
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/data/levels/emptyLevel.oxw

    r9415 r9995  
    3232    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
    3333   
     34    <MovableEntity position="0,0,0" collisionType=dynamic scale=1 linearDamping=0.8 angularDamping=0  collisiondamage=0.005 enablecollisiondamage=true>
     35    <attached>
     36        <Model position="0,0,0" mesh="cube.mesh" scale3D="40,40,40" />
     37        <StaticEntity position="0,90,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
     38            <attached>
     39                <Model position="0,0,0" mesh="cube.mesh" scale3D="30,30,30" />
     40            </attached>
     41            <collisionShapes>
     42                <BoxCollisionShape position="0,0,0" halfExtents="30,30,30" />
     43            </collisionShapes>
     44        </StaticEntity>
     45    </attached>
     46    <collisionShapes>
     47        <BoxCollisionShape position="0,0,0" halfExtents="40,40,40" />
     48    </collisionShapes>
     49    </MovableEntity>
     50   
     51    <Pawn health=30 position="0,-50,0" direction="0,-1,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
     52        <attached>
     53            <Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
     54        </attached>
     55        <collisionShapes>
     56            <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
     57        </collisionShapes>
     58    </Pawn>
     59   
    3460  </Scene>
    3561</Level>
  • code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc

    r9667 r9995  
    141141    }
    142142
     143    bool BasicProjectile::customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
     144        {
     145            if (!this->bDestroy_ && GameMode::isMaster())
     146            {
     147                if (otherObject == this->getShooter()) // Prevents you from shooting yourself
     148                    return false;
     149
     150                this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
     151                                        // The projectile is destroyed by its tick()-function (in the following tick).
     152
     153                Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL
     154
     155                WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
     156                assert(entity); // The projectile must not be a WorldEntity.
     157
     158                // If visual effects after destruction cause problems, put this block below the effects code block
     159                if (victim)
     160                {
     161                    victim->customHit(this->getShooter(), contactPoint, cs, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
     162                    victim->startReloadCountdown();
     163                }
     164
     165                // Visual effects for being hit, depending on whether the shield is hit or not
     166                if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed.
     167                {
     168                    // Damping and explosion effect is only played if the victim is no Pawn (see cast above)
     169                    // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health
     170                    if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f)))
     171                    {
     172                        {
     173                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     174                            effect->setPosition(entity->getPosition());
     175                            effect->setOrientation(entity->getOrientation());
     176                            effect->setDestroyAfterLife(true);
     177                            effect->setSource("Orxonox/explosion3");
     178                            effect->setLifetime(2.0f);
     179                        }
     180                        // Second effect with same condition
     181                        {
     182                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     183                            effect->setPosition(entity->getPosition());
     184                            effect->setOrientation(entity->getOrientation());
     185                            effect->setDestroyAfterLife(true);
     186                            effect->setSource("Orxonox/smoke4");
     187                            effect->setLifetime(3.0f);
     188                        }
     189                    }
     190
     191                    // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
     192                    if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f)
     193                    {
     194                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     195                        effect->setDestroyAfterLife(true);
     196                        effect->setSource("Orxonox/Shield");
     197                        effect->setLifetime(0.5f);
     198                        victim->attach(effect);
     199                    }
     200                }
     201                return true;
     202            }
     203            return false;
     204        }
     205
    143206    /**
    144207    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h

    r9667 r9995  
    120120        protected:
    121121            bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     122            bool customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
    122123            void destroyCheck(void);
    123124
  • code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc

    r9667 r9995  
    9393    }
    9494
     95    bool Projectile::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     96    {
     97        return this->customProcessCollision(otherObject, contactPoint, cs);
     98    }
     99
    95100}
  • code/branches/modularships/src/modules/weapons/projectiles/Projectile.h

    r9667 r9995  
    6565            virtual void tick(float dt);
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768
    6869        private:
  • code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc

    r9667 r9995  
    196196    }
    197197
     198    bool Rocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     199    {
     200        return this->customProcessCollision(otherObject, contactPoint, cs);
     201    }
     202
    198203    /**
    199204    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/Rocket.h

    r9667 r9995  
    6565
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768            virtual void destroyObject(void);
    6869            void destructionEffect();
  • code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc

    r9667 r9995  
    177177    }
    178178
     179    bool SimpleRocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     180    {
     181        return this->customProcessCollision(otherObject, contactPoint, cs);
     182    }
     183
    179184    /**
    180185    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h

    r9667 r9995  
    6565
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768
    6869            void disableFire(); //!< Method to disable the fire and stop all acceleration
  • code/branches/modularships/src/orxonox/Scene.cc

    r9667 r9995  
    201201            // Note: This is a global variable which we assign a static function.
    202202            // TODO: Check whether this (or anything about Bullet) works with multiple physics engine instances.
    203             gContactAddedCallback = &Scene::collisionCallback;
     203            gContactAddedCallback = &Scene::customCollisionCallback;
    204204        }
    205205        else if (!wantPhysics && hasPhysics())
     
    358358        return modified;
    359359    }
     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    }
    360381}
  • code/branches/modularships/src/orxonox/Scene.h

    r9667 r9995  
    143143                                          int index0, const btCollisionObject* colObj1, int partId1, int index1);
    144144
     145            static bool customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,
     146                                                      int index0, const btCollisionObject* colObj1, int partId1, int index1);
     147
    145148            // Bullet objects
    146149            btDiscreteDynamicsWorld*             physicalWorld_;
  • code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc

    r9667 r9995  
    8787    }
    8888
     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
    89104
    90105    void MovableEntity::registerVariables()
  • code/branches/modularships/src/orxonox/worldentities/MovableEntity.h

    r9667 r9995  
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4949            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     50            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    5051
    5152            using WorldEntity::setPosition;
  • code/branches/modularships/src/orxonox/worldentities/WorldEntity.h

    r9667 r9995  
    375375            */
    376376            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)
    377380                { return false; } /* With false, Bullet assumes no modification to the collision objects. */
    378381
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc

    r9950 r9995  
    274274    }
    275275
     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
    276308// TODO: Still valid?
    277309/* HIT-Funktionen
     
    288320    }
    289321
     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    }
    290330
    291331    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
     
    294334        {
    295335            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);
    296347
    297348            if ( this->getController() )
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r9948 r9995  
    127127            //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
    128128            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);
    129130            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);
    130132
    131133            virtual void kill();
     
    197199            //virtual void damage(float damage, Pawn* originator = 0);
    198200            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);
    199202
    200203            bool bAlive_;
Note: See TracChangeset for help on using the changeset viewer.