Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 11:18:44 PM (15 years ago)
Author:
rgrieder
Message:

Added XML Parameters for restitution, angular factor, linear damping, angular damping and friction to WorldEntity.

File:
1 edited

Legend:

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

    r2426 r2429  
    7272        this->bPhysicsActive_ = false;
    7373        this->collisionShape_ = new CompoundCollisionShape(this);
    74         this->mass_ = 0;
    75         this->childrenMass_ = 0;
    7674        this->collisionType_ = None;
    7775        this->collisionTypeSynchronised_ = None;
     76        this->mass_           = 0;
     77        this->childrenMass_   = 0;
     78        // Use bullet default values
     79        this->restitution_    = 0;
     80        this->angularFactor_  = 1;
     81        this->linearDamping_  = 0;
     82        this->angularDamping_ = 0;
     83        this->friction_       = 0.5;
    7884
    7985        this->registerVariables();
     
    103109        SUPER(WorldEntity, XMLPort, xmlelement, mode);
    104110
    105         XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
     111        XMLPortParamTemplate(WorldEntity, "position",    setPosition,    getPosition,    xmlelement, mode, const Vector3&);
    106112        XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
    107         XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode);
    108         XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode);
    109         XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode);
    110         XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode);
    111         XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode);
    112         XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
    113         XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode);
     113        XMLPortParamTemplate(WorldEntity, "scale3D",     setScale3D,     getScale3D,     xmlelement, mode, const Vector3&);
     114        XMLPortParam        (WorldEntity, "scale",       setScale,       getScale,      xmlelement, mode);
     115        XMLPortParamLoadOnly(WorldEntity, "lookat",      lookAt_xmlport,      xmlelement, mode);
     116        XMLPortParamLoadOnly(WorldEntity, "direction",   setDirection_xmlport, xmlelement, mode);
     117        XMLPortParamLoadOnly(WorldEntity, "yaw",         yaw_xmlport,          xmlelement, mode);
     118        XMLPortParamLoadOnly(WorldEntity, "pitch",       pitch_xmlport,        xmlelement, mode);
     119        XMLPortParamLoadOnly(WorldEntity, "roll",        roll_xmlport,        xmlelement, mode);
    114120
    115121        // Physics
    116         XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
    117         XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode);
     122        XMLPortParam(WorldEntity, "collisionType",  setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
     123        XMLPortParam(WorldEntity, "mass",           setMass,             getMass,             xmlelement, mode);
     124        XMLPortParam(WorldEntity, "restitution",    setRestitution,      getRestitution,      xmlelement, mode);
     125        XMLPortParam(WorldEntity, "angularFactor",  setAngularFactor,    getAngularFactor,    xmlelement, mode);
     126        XMLPortParam(WorldEntity, "linearDamping",  setLinearDamping,    getLinearDamping,    xmlelement, mode);
     127        XMLPortParam(WorldEntity, "angularDamping", setAngularDamping,   getAngularDamping,   xmlelement, mode);
     128        XMLPortParam(WorldEntity, "friction",       setFriction,         getFriction,         xmlelement, mode);
    118129
    119130        // Other attached WorldEntities
     
    125136    void WorldEntity::registerVariables()
    126137    {
    127         REGISTERDATA(this->bActive_,     network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
    128         REGISTERDATA(this->bVisible_,    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
    129 
    130         REGISTERDATA(this->getScale3D(), network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));
     138        REGISTERDATA(this->bActive_,        network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
     139        REGISTERDATA(this->bVisible_,       network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
     140
     141        REGISTERDATA(this->getScale3D(),    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));
    131142
    132143        REGISTERDATA((int&)this->collisionTypeSynchronised_,
    133                                          network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
    134         REGISTERDATA(this->mass_,        network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged));
     144                                            network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
     145        REGISTERDATA(this->mass_,           network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged));
     146        REGISTERDATA(this->restitution_,    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::restitutionChanged));
     147        REGISTERDATA(this->angularFactor_,  network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::angularFactorChanged));
     148        REGISTERDATA(this->linearDamping_,  network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::linearDampingChanged));
     149        REGISTERDATA(this->angularDamping_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged));
     150        REGISTERDATA(this->friction_,       network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged));
    135151        REGISTERDATA(this->bPhysicsActiveSynchronised_,
    136                                          network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged));
    137 
    138         REGISTERDATA(this->parentID_,    network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent));
    139     }
    140 
    141     void WorldEntity::updateParent()
     152                                            network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged));
     153
     154        REGISTERDATA(this->parentID_,       network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::parentChanged));
     155    }
     156
     157    void WorldEntity::parentChanged()
    142158    {
    143159        WorldEntity* parent = dynamic_cast<WorldEntity*>(Synchronisable::getSynchronisable(this->parentID_));
     
    162178                this->setCollisionType(this->collisionTypeSynchronised_);
    163179        }
    164     }
    165 
    166     void WorldEntity::massChanged()
    167     {
    168         this->setMass(this->mass_);
    169180    }
    170181
     
    214225        // mass
    215226        this->childrenMass_ += object->getMass();
    216         recalculatePhysicsProps();
     227        recalculateMassProps();
    217228    }
    218229
     
    225236        {
    226237            this->childrenMass_ -= object->getMass();
    227             recalculatePhysicsProps();
     238            recalculateMassProps();
    228239        }
    229240
     
    418429    }
    419430
    420     void WorldEntity::setMass(float mass)
    421     {
    422         this->mass_ = mass;
    423         recalculatePhysicsProps();
    424     }
    425 
    426431    void WorldEntity::setCollisionType(CollisionType type)
    427432    {
     
    430435            ThrowException(PhysicsViolation, "Cannot set the collision type of a WorldEntity with a parent");
    431436        else if (this->addedToPhysicalWorld())
    432             ThrowException(PhysicsViolation, "Warning: Cannot set the collision type at run time.");
     437            ThrowException(PhysicsViolation, "Cannot set the collision type at run time.");
    433438
    434439        // Check for type legality. Could be StaticEntity or MobileEntity
    435440        if (!this->isCollisionTypeLegal(type))
    436441            return; // exception gets issued anyway
     442        if (type != None && !this->getScene()->hasPhysics())
     443            ThrowException(PhysicsViolation, "Cannot have physical bodies in a non physical scene");
    437444
    438445        // Check whether we have to create or destroy.
     
    444451
    445452            // Create new rigid body
    446             btCollisionShape* temp = 0;
    447453            btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape());
    448             bodyConstructionInfo.m_restitution = 1;
    449454            this->physicalBody_ = new btRigidBody(bodyConstructionInfo);
    450455            this->physicalBody_->setUserPointer(this);
     
    485490
    486491        // update mass and inertia tensor
    487         recalculatePhysicsProps();
     492        recalculateMassProps();
     493        resetPhysicsProps();
    488494        activatePhysics();
    489495    }
     
    544550        for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
    545551            this->childrenMass_ += (*it)->getMass();
    546         recalculatePhysicsProps();
     552        recalculateMassProps();
    547553        // Notify parent WE
    548554        if (this->parent_)
     
    564570                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
    565571        }
    566         recalculatePhysicsProps();
    567     }
    568 
    569     void WorldEntity::recalculatePhysicsProps()
     572        recalculateMassProps();
     573    }
     574
     575    void WorldEntity::recalculateMassProps()
    570576    {
    571577        if (this->hasPhysics())
     
    589595        }
    590596    }
     597
     598    void WorldEntity::resetPhysicsProps()
     599    {
     600        if (this->hasPhysics())
     601        {
     602            this->physicalBody_->setRestitution(this->restitution_);
     603            this->physicalBody_->setAngularFactor(this->angularFactor_);
     604            this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_);
     605            this->physicalBody_->setFriction(this->friction_);
     606        }
     607    }
    591608}
Note: See TracChangeset for help on using the changeset viewer.