Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2008, 1:38:17 PM (15 years ago)
Author:
rgrieder
Message:

Trying to synchronise phyiscs over the network.

  • Removed derivation of CollisionShape from WorldEntity (BaseObject instead).
File:
1 edited

Legend:

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

    r2304 r2374  
    3131#include "StaticEntity.h"
    3232
     33#include "BulletDynamics/Dynamics/btRigidBody.h"
     34
    3335#include "util/Exception.h"
    3436#include "core/CoreIncludes.h"
     
    5153    void StaticEntity::registerVariables()
    5254    {
    53         REGISTERDATA(this->getPosition().x, network::direction::toclient);
    54         REGISTERDATA(this->getPosition().y, network::direction::toclient);
    55         REGISTERDATA(this->getPosition().z, network::direction::toclient);
    56 
    57         REGISTERDATA(this->getOrientation().w, network::direction::toclient);
    58         REGISTERDATA(this->getOrientation().x, network::direction::toclient);
    59         REGISTERDATA(this->getOrientation().y, network::direction::toclient);
    60         REGISTERDATA(this->getOrientation().z, network::direction::toclient);
     55        REGISTERDATA(this->getPosition(),    network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged));
     56        REGISTERDATA(this->getOrientation(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged));
     57    }
     58
     59
     60    void StaticEntity::setPosition(const Vector3& position)
     61    {
     62        if (this->isPhysicsRunning())
     63            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     64        if (this->isStatic())
     65        {
     66            btTransform transf = this->physicalBody_->getWorldTransform();
     67            transf.setOrigin(btVector3(position.x, position.y, position.z));
     68            this->physicalBody_->setWorldTransform(transf);
     69        }
     70
     71        this->node_->setPosition(position);
     72    }
     73
     74    void StaticEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
     75    {
     76        if (this->isPhysicsRunning())
     77            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     78        if (this->isStatic())
     79        {
     80            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot translate physical object relative \
     81                                                          to any other space than TS_LOCAL.");
     82            this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z));
     83        }
     84
     85        this->node_->translate(distance, relativeTo);
     86    }
     87
     88    void StaticEntity::setOrientation(const Quaternion& orientation)
     89    {
     90        if (this->isPhysicsRunning())
     91            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     92        if (this->isStatic())
     93        {
     94            btTransform transf = this->physicalBody_->getWorldTransform();
     95            transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w));
     96            this->physicalBody_->setWorldTransform(transf);
     97        }
     98
     99        this->node_->setOrientation(orientation);
     100    }
     101
     102    void StaticEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
     103    {
     104        if (this->isPhysicsRunning())
     105            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     106        if (this->isStatic())
     107        {
     108            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot rotate physical object relative \
     109                                                          to any other space than TS_LOCAL.");
     110            btTransform transf = this->physicalBody_->getWorldTransform();
     111            this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)));
     112        }
     113
     114        this->node_->rotate(rotation, relativeTo);
     115    }
     116
     117    void StaticEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     118    {
     119        if (this->isPhysicsRunning())
     120            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     121        if (this->isStatic())
     122        {
     123            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot yaw physical object relative \
     124                                                          to any other space than TS_LOCAL.");
     125            btTransform transf = this->physicalBody_->getWorldTransform();
     126            btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f));
     127            this->physicalBody_->setWorldTransform(transf * rotation);
     128        }
     129
     130        this->node_->yaw(angle, relativeTo);
     131    }
     132
     133    void StaticEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     134    {
     135        if (this->isPhysicsRunning())
     136            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     137        if (this->isStatic())
     138        {
     139            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot pitch physical object relative \
     140                                                          to any other space than TS_LOCAL.");
     141            btTransform transf = this->physicalBody_->getWorldTransform();
     142            btTransform rotation(btQuaternion(0.0f, angle.valueRadians(), 0.0f));
     143            this->physicalBody_->setWorldTransform(transf * rotation);
     144        }
     145
     146        this->node_->pitch(angle, relativeTo);
     147    }
     148
     149    void StaticEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
     150    {
     151        if (this->isPhysicsRunning())
     152            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     153        if (this->isStatic())
     154        {
     155            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot roll physical object relative \
     156                                                          to any other space than TS_LOCAL.");
     157            btTransform transf = this->physicalBody_->getWorldTransform();
     158            btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f));
     159            this->physicalBody_->setWorldTransform(transf * rotation);
     160        }
     161
     162        this->node_->roll(angle, relativeTo);
     163    }
     164
     165    void StaticEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
     166    {
     167        if (this->isPhysicsRunning())
     168            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     169        if (this->isStatic())
     170        {
     171            ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects.");
     172            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \
     173                                                          to any other space than TS_LOCAL.");
     174        }
     175
     176        this->node_->lookAt(target, relativeTo, localDirectionVector);
     177    }
     178
     179    void StaticEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
     180    {
     181        if (this->isPhysicsRunning())
     182            ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time.");
     183        if (this->isStatic())
     184        {
     185            ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects.");
     186            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \
     187                                                          to any other space than TS_LOCAL.");
     188        }
     189
     190        this->node_->setDirection(direction, relativeTo, localDirectionVector);
    61191    }
    62192
     
    81211    {
    82212        worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
    83         worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));
     213        worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
    84214    }
    85215}
Note: See TracChangeset for help on using the changeset viewer.