Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3163 for code/branches


Ignore:
Timestamp:
Jun 14, 2009, 11:24:42 AM (15 years ago)
Author:
rgrieder
Message:

Moved orxonox::TransformSpace::Enum to WorldEntity::TransformSpace and asserted the conversions with a BOOST_STATIC_ASSERT (avoids unnecessary switch statements).
Also

Location:
code/branches/pch/src
Files:
3 edited

Legend:

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

    r3159 r3163  
    3434#include <OgreSceneManager.h>
    3535#include "BulletDynamics/Dynamics/btRigidBody.h"
     36#include <boost/static_assert.hpp>
    3637
    3738#include "util/OrxAssert.h"
     
    5152    const Vector3 WorldEntity::DOWN  = Vector3::NEGATIVE_UNIT_Y;
    5253    const Vector3 WorldEntity::UP    = Vector3::UNIT_Y;
     54
     55    // Be sure we don't do bad conversions
     56    BOOST_STATIC_ASSERT((int)Ogre::Node::TS_LOCAL  == (int)WorldEntity::Local);
     57    BOOST_STATIC_ASSERT((int)Ogre::Node::TS_PARENT == (int)WorldEntity::Parent);
     58    BOOST_STATIC_ASSERT((int)Ogre::Node::TS_WORLD  == (int)WorldEntity::World);
    5359
    5460    /**
     
    574580        Translates this WorldEntity by a vector.
    575581    @param relativeTo
    576         @see TransformSpace::Enum
    577     */
    578     void WorldEntity::translate(const Vector3& distance, TransformSpace::Enum relativeTo)
     582        @see WorldEntity::TransformSpace
     583    */
     584    void WorldEntity::translate(const Vector3& distance, TransformSpace relativeTo)
    579585    {
    580586        switch (relativeTo)
    581587        {
    582         case TransformSpace::Local:
     588        case WorldEntity::Local:
    583589            // position is relative to parent so transform downwards
    584590            this->setPosition(this->getPosition() + this->getOrientation() * distance);
    585591            break;
    586         case TransformSpace::Parent:
     592        case WorldEntity::Parent:
    587593            this->setPosition(this->getPosition() + distance);
    588594            break;
    589         case TransformSpace::World:
     595        case WorldEntity::World:
    590596            // position is relative to parent so transform upwards
    591597            if (this->node_->getParent())
     
    602608        Rotates this WorldEntity by a quaternion.
    603609    @param relativeTo
    604         @see TransformSpace::Enum
    605     */
    606     void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo)
     610        @see WorldEntity::TransformSpace
     611    */
     612    void WorldEntity::rotate(const Quaternion& rotation, TransformSpace relativeTo)
    607613    {
    608614        switch(relativeTo)
    609615        {
    610         case TransformSpace::Local:
     616        case WorldEntity::Local:
    611617            this->setOrientation(this->getOrientation() * rotation);
    612618            break;
    613         case TransformSpace::Parent:
     619        case WorldEntity::Parent:
    614620            // Rotations are normally relative to local axes, transform up
    615621            this->setOrientation(rotation * this->getOrientation());
    616622            break;
    617         case TransformSpace::World:
     623        case WorldEntity::World:
    618624            // Rotations are normally relative to local axes, transform up
    619625            this->setOrientation(this->getOrientation() * this->getWorldOrientation().Inverse()
     
    627633        Makes this WorldEntity look a specific target location.
    628634    @param relativeTo
    629         @see TransformSpace::Enum
     635        @see WorldEntity::TransformSpace
    630636    @param localDirectionVector
    631637        The vector which normally describes the natural direction of the object, usually -Z.
    632638    */
    633     void WorldEntity::lookAt(const Vector3& target, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector)
     639    void WorldEntity::lookAt(const Vector3& target, TransformSpace relativeTo, const Vector3& localDirectionVector)
    634640    {
    635641        Vector3 origin(0, 0, 0);
    636642        switch (relativeTo)
    637643        {
    638         case TransformSpace::Local:
     644        case WorldEntity::Local:
    639645            origin = Vector3::ZERO;
    640646            break;
    641         case TransformSpace::Parent:
     647        case WorldEntity::Parent:
    642648            origin = this->getPosition();
    643649            break;
    644         case TransformSpace::World:
     650        case WorldEntity::World:
    645651            origin = this->getWorldPosition();
    646652            break;
     
    653659        Makes this WorldEntity look in specific direction.
    654660    @param relativeTo
    655         @see TransformSpace::Enum
     661        @see WorldEntity::TransformSpace
    656662    @param localDirectionVector
    657663        The vector which normally describes the natural direction of the object, usually -Z.
    658664    */
    659     void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Enum relativeTo, const Vector3& localDirectionVector)
     665    void WorldEntity::setDirection(const Vector3& direction, TransformSpace relativeTo, const Vector3& localDirectionVector)
    660666    {
    661667        Quaternion savedOrientation(this->getOrientation());
    662         Ogre::Node::TransformSpace ogreRelativeTo = Ogre::Node::TS_LOCAL;
    663         switch (relativeTo)
    664         {
    665         case TransformSpace::Local:
    666             ogreRelativeTo = Ogre::Node::TS_LOCAL; break;
    667         case TransformSpace::Parent:
    668             ogreRelativeTo = Ogre::Node::TS_PARENT; break;
    669         case TransformSpace::World:
    670             ogreRelativeTo = Ogre::Node::TS_WORLD; break;
    671         default: OrxAssert(false, "Faulty TransformSpace::Enum assigned.");
    672         }
    673         this->node_->setDirection(direction, ogreRelativeTo, localDirectionVector);
     668        this->node_->setDirection(direction, static_cast<Ogre::Node::TransformSpace>(relativeTo), localDirectionVector);
    674669        Quaternion newOrientation(this->node_->getOrientation());
    675670        this->node_->setOrientation(savedOrientation);
  • code/branches/pch/src/orxonox/objects/worldentities/WorldEntity.h

    r3077 r3163  
    7575
    7676        public:
     77            // Define our own transform space enum to avoid Ogre includes here
     78            /**
     79            @brief
     80                Enumeration denoting the spaces which a transform can be relative to.
     81            */
     82            enum TransformSpace
     83            {
     84                //! Transform is relative to the local space
     85                Local,
     86                //! Transform is relative to the space of the parent node
     87                Parent,
     88                //! Transform is relative to world space
     89                World
     90            };
     91
     92        public:
    7793            WorldEntity(BaseObject* creator);
    7894            virtual ~WorldEntity();
     
    97113            const Vector3& getWorldPosition() const;
    98114
    99             void translate(const Vector3& distance, TransformSpace::Enum relativeTo = TransformSpace::Parent);
    100             inline void translate(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Parent)
     115            void translate(const Vector3& distance, TransformSpace relativeTo = WorldEntity::Parent);
     116            inline void translate(float x, float y, float z, TransformSpace relativeTo = WorldEntity::Parent)
    101117                { this->translate(Vector3(x, y, z), relativeTo); }
    102118
     
    114130            const Quaternion& getWorldOrientation() const;
    115131
    116             void rotate(const Quaternion& rotation, TransformSpace::Enum relativeTo = TransformSpace::Local);
    117             inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local)
     132            void rotate(const Quaternion& rotation, TransformSpace relativeTo = WorldEntity::Local);
     133            inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace relativeTo = WorldEntity::Local)
    118134                { this->rotate(Quaternion(angle, axis), relativeTo); }
    119135
    120             inline void yaw(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local)
     136            inline void yaw(const Degree& angle, TransformSpace relativeTo = WorldEntity::Local)
    121137                { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); }
    122             inline void pitch(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local)
     138            inline void pitch(const Degree& angle, TransformSpace relativeTo = WorldEntity::Local)
    123139                { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); }
    124             inline void roll(const Degree& angle, TransformSpace::Enum relativeTo = TransformSpace::Local)
     140            inline void roll(const Degree& angle, TransformSpace relativeTo = WorldEntity::Local)
    125141                { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); }
    126142
    127             void lookAt(const Vector3& target, TransformSpace::Enum relativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    128             void setDirection(const Vector3& direction, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    129             inline void setDirection(float x, float y, float z, TransformSpace::Enum relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
     143            void lookAt(const Vector3& target, TransformSpace relativeTo = WorldEntity::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
     144            void setDirection(const Vector3& direction, TransformSpace relativeTo = WorldEntity::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
     145            inline void setDirection(float x, float y, float z, TransformSpace relativeTo = WorldEntity::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
    130146                { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
    131147
  • code/branches/pch/src/util/Math.h

    r3146 r3163  
    5454namespace orxonox
    5555{
    56     // Also define our own transform space enum
    57     namespace TransformSpace
    58     {
    59         /**
    60         @brief
    61             Enumeration denoting the spaces which a transform can be relative to.
    62         */
    63         enum Enum
    64         {
    65             //! Transform is relative to the local space
    66             Local,
    67             //! Transform is relative to the space of the parent node
    68             Parent,
    69             //! Transform is relative to world space
    70             World
    71         };
    72     }
    73 
    7456    _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
    7557    _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian);
Note: See TracChangeset for help on using the changeset viewer.