Changeset 3163
- Timestamp:
- Jun 14, 2009, 11:24:42 AM (15 years ago)
- Location:
- code/branches/pch/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/orxonox/objects/worldentities/WorldEntity.cc
r3159 r3163 34 34 #include <OgreSceneManager.h> 35 35 #include "BulletDynamics/Dynamics/btRigidBody.h" 36 #include <boost/static_assert.hpp> 36 37 37 38 #include "util/OrxAssert.h" … … 51 52 const Vector3 WorldEntity::DOWN = Vector3::NEGATIVE_UNIT_Y; 52 53 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); 53 59 54 60 /** … … 574 580 Translates this WorldEntity by a vector. 575 581 @param relativeTo 576 @see TransformSpace::Enum577 */ 578 void WorldEntity::translate(const Vector3& distance, TransformSpace ::EnumrelativeTo)582 @see WorldEntity::TransformSpace 583 */ 584 void WorldEntity::translate(const Vector3& distance, TransformSpace relativeTo) 579 585 { 580 586 switch (relativeTo) 581 587 { 582 case TransformSpace::Local:588 case WorldEntity::Local: 583 589 // position is relative to parent so transform downwards 584 590 this->setPosition(this->getPosition() + this->getOrientation() * distance); 585 591 break; 586 case TransformSpace::Parent:592 case WorldEntity::Parent: 587 593 this->setPosition(this->getPosition() + distance); 588 594 break; 589 case TransformSpace::World:595 case WorldEntity::World: 590 596 // position is relative to parent so transform upwards 591 597 if (this->node_->getParent()) … … 602 608 Rotates this WorldEntity by a quaternion. 603 609 @param relativeTo 604 @see TransformSpace::Enum605 */ 606 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace ::EnumrelativeTo)610 @see WorldEntity::TransformSpace 611 */ 612 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace relativeTo) 607 613 { 608 614 switch(relativeTo) 609 615 { 610 case TransformSpace::Local:616 case WorldEntity::Local: 611 617 this->setOrientation(this->getOrientation() * rotation); 612 618 break; 613 case TransformSpace::Parent:619 case WorldEntity::Parent: 614 620 // Rotations are normally relative to local axes, transform up 615 621 this->setOrientation(rotation * this->getOrientation()); 616 622 break; 617 case TransformSpace::World:623 case WorldEntity::World: 618 624 // Rotations are normally relative to local axes, transform up 619 625 this->setOrientation(this->getOrientation() * this->getWorldOrientation().Inverse() … … 627 633 Makes this WorldEntity look a specific target location. 628 634 @param relativeTo 629 @see TransformSpace::Enum635 @see WorldEntity::TransformSpace 630 636 @param localDirectionVector 631 637 The vector which normally describes the natural direction of the object, usually -Z. 632 638 */ 633 void WorldEntity::lookAt(const Vector3& target, TransformSpace ::EnumrelativeTo, const Vector3& localDirectionVector)639 void WorldEntity::lookAt(const Vector3& target, TransformSpace relativeTo, const Vector3& localDirectionVector) 634 640 { 635 641 Vector3 origin(0, 0, 0); 636 642 switch (relativeTo) 637 643 { 638 case TransformSpace::Local:644 case WorldEntity::Local: 639 645 origin = Vector3::ZERO; 640 646 break; 641 case TransformSpace::Parent:647 case WorldEntity::Parent: 642 648 origin = this->getPosition(); 643 649 break; 644 case TransformSpace::World:650 case WorldEntity::World: 645 651 origin = this->getWorldPosition(); 646 652 break; … … 653 659 Makes this WorldEntity look in specific direction. 654 660 @param relativeTo 655 @see TransformSpace::Enum661 @see WorldEntity::TransformSpace 656 662 @param localDirectionVector 657 663 The vector which normally describes the natural direction of the object, usually -Z. 658 664 */ 659 void WorldEntity::setDirection(const Vector3& direction, TransformSpace ::EnumrelativeTo, const Vector3& localDirectionVector)665 void WorldEntity::setDirection(const Vector3& direction, TransformSpace relativeTo, const Vector3& localDirectionVector) 660 666 { 661 667 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); 674 669 Quaternion newOrientation(this->node_->getOrientation()); 675 670 this->node_->setOrientation(savedOrientation); -
code/branches/pch/src/orxonox/objects/worldentities/WorldEntity.h
r3077 r3163 75 75 76 76 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: 77 93 WorldEntity(BaseObject* creator); 78 94 virtual ~WorldEntity(); … … 97 113 const Vector3& getWorldPosition() const; 98 114 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) 101 117 { this->translate(Vector3(x, y, z), relativeTo); } 102 118 … … 114 130 const Quaternion& getWorldOrientation() const; 115 131 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) 118 134 { this->rotate(Quaternion(angle, axis), relativeTo); } 119 135 120 inline void yaw(const Degree& angle, TransformSpace ::Enum relativeTo = TransformSpace::Local)136 inline void yaw(const Degree& angle, TransformSpace relativeTo = WorldEntity::Local) 121 137 { 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) 123 139 { 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) 125 141 { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); } 126 142 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) 130 146 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } 131 147 -
code/branches/pch/src/util/Math.h
r3146 r3163 54 54 namespace orxonox 55 55 { 56 // Also define our own transform space enum57 namespace TransformSpace58 {59 /**60 @brief61 Enumeration denoting the spaces which a transform can be relative to.62 */63 enum Enum64 {65 //! Transform is relative to the local space66 Local,67 //! Transform is relative to the space of the parent node68 Parent,69 //! Transform is relative to world space70 World71 };72 }73 74 56 _UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian); 75 57 _UtilExport std::istream& operator>>(std::istream& in, orxonox::Radian& radian);
Note: See TracChangeset
for help on using the changeset viewer.