Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2008, 10:53:44 PM (16 years ago)
Author:
rgrieder
Message:

Minor changes and added localInertia_ to worldentity for faster access.

Location:
code/branches/physics_merge/src/orxonox/objects
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics_merge/src/orxonox/objects/collisionshapes/CollisionShape.cc

    r2445 r2452  
    108108    }
    109109
    110     btVector3 CollisionShape::getLocalInertia(btScalar mass) const
     110    void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
    111111    {
    112         btVector3 inertia(0, 0, 0);
    113112        if (this->collisionShape_)
    114113            this->collisionShape_->calculateLocalInertia(mass, inertia);
    115         return inertia;
     114        else
     115            inertia.setValue(0, 0, 0);
    116116    }
    117117}
  • code/branches/physics_merge/src/orxonox/objects/collisionshapes/CollisionShape.h

    r2445 r2452  
    6666                { return this->scale_; }
    6767
    68             btVector3 getLocalInertia(float mass) const;
     68            void calculateLocalInertia(float mass, btVector3& inertia) const;
    6969
    7070            inline btCollisionShape* getCollisionShape() const
  • code/branches/physics_merge/src/orxonox/objects/worldentities/MobileEntity.cc

    r2442 r2452  
    5151        this->angularAcceleration_ = Vector3::ZERO;
    5252        this->angularVelocity_     = Vector3::ZERO;
    53 
    54         this->registerVariables();
    5553    }
    5654
     
    6664        XMLPortParamTemplate(MobileEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);
    6765        XMLPortParam(MobileEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode);
    68     }
    69 
    70     void MobileEntity::registerVariables()
    71     {
    7266    }
    7367
  • code/branches/physics_merge/src/orxonox/objects/worldentities/MobileEntity.h

    r2442 r2452  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646            virtual void tick(float dt);
    47             void registerVariables();
    4847
    4948            virtual void setPosition(const Vector3& position);
  • code/branches/physics_merge/src/orxonox/objects/worldentities/WorldEntity.cc

    r2446 r2452  
    605605    void WorldEntity::recalculateMassProps()
    606606    {
     607        // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape.
     608        float totalMass = this->mass_ + this->childrenMass_;
     609        this->collisionShape_->calculateLocalInertia(totalMass, this->localInertia_);
    607610        if (this->hasPhysics())
    608611        {
     
    616619                // Use default values to avoid very large or very small values
    617620                CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl;
    618                 this->physicalBody_->setMassProps(1.0f, this->collisionShape_->getLocalInertia(1.0f));
     621                btVector3 inertia(0, 0, 0);
     622                this->collisionShape_->calculateLocalInertia(1.0f, inertia);
     623                this->physicalBody_->setMassProps(1.0f, inertia);
    619624            }
    620625            else
    621626            {
    622                 float mass = this->mass_ + this->childrenMass_;
    623                 this->physicalBody_->setMassProps(mass, this->collisionShape_->getLocalInertia(mass));
     627                this->physicalBody_->setMassProps(totalMass, this->localInertia_);
    624628            }
    625629        }
  • code/branches/physics_merge/src/orxonox/objects/worldentities/WorldEntity.h

    r2442 r2452  
    199199            inline float getTotalMass() const
    200200                { return this->mass_ + this->childrenMass_; }
     201
     202            inline const btVector3& getLocalInertia() const
     203                { return this->localInertia_; }
    201204
    202205            inline void setRestitution(float restitution)
     
    269272            CompoundCollisionShape*      collisionShape_;
    270273            btScalar                     mass_;
     274            btVector3                    localInertia_;
    271275            btScalar                     restitution_;
    272276            btScalar                     angularFactor_;
Note: See TracChangeset for help on using the changeset viewer.