Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 1, 2009, 7:34:44 PM (16 years ago)
Author:
rgrieder
Message:
  • Added WorldEntityCollisionShape to clarify when a CompoundCollisionShape belongs to a WE.
  • Also fixed problems with the synchronisation of the CollisionShape hierarchy.
Location:
code/branches/presentation/src/orxonox/objects/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc

    r2540 r2562  
    4242
    4343#include "objects/Scene.h"
     44#include "objects/collisionshapes/WorldEntityCollisionShape.h"
    4445
    4546namespace orxonox
     
    5758        All the default values are being set here.
    5859    */
    59     WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), collisionShape_(0)
     60    WorldEntity::WorldEntity(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
    6061    {
    6162        RegisterObject(WorldEntity);
     
    7475
    7576        // Default behaviour does not include physics
    76         // Note: CompoundCollisionShape is a Synchronisable, but must not be synchronised.
    77         //       All objects will get attached on the client anyway, so we don't need synchronisation.
    78         this->collisionShape_.setWorldEntityParent(this);
    7977        this->physicalBody_   = 0;
    8078        this->bPhysicsActive_ = false;
    8179        this->bPhysicsActiveSynchronised_    = false;
    8280        this->bPhysicsActiveBeforeAttaching_ = false;
     81        this->collisionShape_ = new WorldEntityCollisionShape(this);
    8382        this->collisionType_             = None;
    8483        this->collisionTypeSynchronised_ = None;
     
    115114                delete this->physicalBody_;
    116115            }
     116            delete this->collisionShape_;
    117117
    118118            this->node_->detachAllObjects();
     
    291291        this->children_.insert(object);
    292292
    293         this->attachCollisionShape(&object->collisionShape_);
     293        this->attachCollisionShape(object->collisionShape_);
    294294        // mass
    295295        this->childrenMass_ += object->getMass();
     
    345345
    346346        // apply transform to collision shape
    347         this->collisionShape_.setPosition(this->getPosition());
    348         this->collisionShape_.setOrientation(this->getOrientation());
     347        this->collisionShape_->setPosition(this->getPosition());
     348        this->collisionShape_->setOrientation(this->getOrientation());
    349349        // TODO: Scale
    350350       
     
    365365
    366366        // collision shapes
    367         this->detachCollisionShape(&object->collisionShape_);
     367        this->detachCollisionShape(object->collisionShape_);
    368368
    369369        // mass
     
    390390
    391391        // reset orientation of the collisionShape (cannot be set within a WE usually)
    392         this->collisionShape_.setPosition(Vector3::ZERO);
    393         this->collisionShape_.setOrientation(Quaternion::IDENTITY);
     392        this->collisionShape_->setPosition(Vector3::ZERO);
     393        this->collisionShape_->setOrientation(Quaternion::IDENTITY);
    394394        // TODO: Scale
    395395
     
    451451    void WorldEntity::attachCollisionShape(CollisionShape* shape)
    452452    {
    453         this->collisionShape_.attach(shape);
     453        this->collisionShape_->attach(shape);
    454454        // Note: this->collisionShape_ already notifies us of any changes.
    455455    }
     
    458458    void WorldEntity::detachCollisionShape(CollisionShape* shape)
    459459    {
    460         this->collisionShape_.detach(shape);
     460        // Note: The collision shapes may not be detached with this function!
     461        this->collisionShape_->detach(shape);
    461462        // Note: this->collisionShape_ already notifies us of any changes.
    462463    }
     
    465466    CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index)
    466467    {
    467         return this->collisionShape_.getAttachedShape(index);
     468        return this->collisionShape_->getAttachedShape(index);
    468469    }
    469470
     
    718719*/
    719720            // Create new rigid body
    720             btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_.getCollisionShape());
     721            btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape());
    721722            this->physicalBody_ = new btRigidBody(bodyConstructionInfo);
    722723            this->physicalBody_->setUserPointer(this);
     
    851852            {
    852853                this->deactivatePhysics();
    853                 this->physicalBody_->setCollisionShape(this->collisionShape_.getCollisionShape());
     854                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
    854855                this->activatePhysics();
    855856            }
    856857            else
    857                 this->physicalBody_->setCollisionShape(this->collisionShape_.getCollisionShape());
     858                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
    858859        }
    859860        recalculateMassProps();
     
    865866        // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape.
    866867        float totalMass = this->mass_ + this->childrenMass_;
    867         this->collisionShape_.calculateLocalInertia(totalMass, this->localInertia_);
     868        this->collisionShape_->calculateLocalInertia(totalMass, this->localInertia_);
    868869        if (this->hasPhysics())
    869870        {
     
    878879                CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0" << std::endl;
    879880                btVector3 inertia(0, 0, 0);
    880                 this->collisionShape_.calculateLocalInertia(1.0f, inertia);
     881                this->collisionShape_->calculateLocalInertia(1.0f, inertia);
    881882                this->physicalBody_->setMassProps(1.0f, inertia);
    882883            }
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h

    r2540 r2562  
    4343#include "core/BaseObject.h"
    4444#include "network/synchronisable/Synchronisable.h"
    45 #include "objects/collisionshapes/CompoundCollisionShape.h"
    4645
    4746namespace orxonox
     
    6968        You can get more information at the corresponding set function.
    7069
    71         Collision shapes: These are controlled by the internal CompoundCollisionShape. @see CompoundCollisionShape.
     70        Collision shapes: These are controlled by the internal WorldEntityCollisionShape. @see WorldEntityCollisionShape.
    7271    */
    7372    class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState
     
    399398            //! When attaching objects hierarchically this variable tells this object (as child) whether physics was activated before attaching (because the deactivate physics while being attached).
    400399            bool                         bPhysicsActiveBeforeAttaching_;
    401             CompoundCollisionShape       collisionShape_;                //!< Attached collision shapes go here
     400            WorldEntityCollisionShape*   collisionShape_;                //!< Attached collision shapes go here
    402401            btScalar                     mass_;                          //!< @see setMass
    403402            btVector3                    localInertia_;                  //!< @see getLocalInertia
Note: See TracChangeset for help on using the changeset viewer.