- Timestamp:
- Dec 14, 2008, 4:16:52 PM (15 years ago)
- Location:
- code/branches/physics_merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/WorldEntity.h
r2371 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #define OGRE_FORCE_ANGLE_TYPES 35 35 #ifdef _NDEBUG 36 36 #include <OgreSceneNode.h> 37 #else 38 #include <OgrePrerequisites.h> 39 #endif 40 #include "LinearMath/btMotionState.h" 37 41 38 42 #include "network/synchronisable/Synchronisable.h" … … 42 46 namespace orxonox 43 47 { 44 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable 48 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState 45 49 { 46 50 public: … … 51 55 void registerVariables(); 52 56 53 inline Ogre::SceneNode* getNode() const57 inline const Ogre::SceneNode* getNode() const 54 58 { return this->node_; } 55 59 … … 64 68 inline void setPosition(float x, float y, float z) 65 69 { this->setPosition(Vector3(x, y, z)); } 66 inline const Vector3& getPosition() const 67 { return this->node_->getPosition(); } 68 inline const Vector3& getWorldPosition() const 69 { return this->node_->getWorldPosition(); } 70 71 virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 72 inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 70 const Vector3& getPosition() const; 71 const Vector3& getWorldPosition() const; 72 73 void translate(const Vector3& distance, TransformSpace::Space relativeTo = TransformSpace::Parent); 74 inline void translate(float x, float y, float z, TransformSpace::Space relativeTo = TransformSpace::Parent) 73 75 { this->translate(Vector3(x, y, z), relativeTo); } 74 76 … … 80 82 inline void setOrientation(const Vector3& axis, const Degree& angle) 81 83 { this->setOrientation(Quaternion(angle, axis)); } 82 inline const Quaternion& getOrientation() const 83 { return this->node_->getOrientation(); } 84 inline const Quaternion& getWorldOrientation() const 85 { return this->node_->getWorldOrientation(); } 86 87 virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 88 inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 84 const Quaternion& getOrientation() const; 85 const Quaternion& getWorldOrientation() const; 86 87 void rotate(const Quaternion& rotation, TransformSpace::Space relativeTo = TransformSpace::Local); 88 inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local) 89 89 { this->rotate(Quaternion(angle, axis), relativeTo); } 90 inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 91 { this->rotate(Quaternion(angle, axis), relativeTo); } 92 93 virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 94 inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 95 { this->yaw(Degree(angle), relativeTo); } 96 virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 97 inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 98 { this->pitch(Degree(angle), relativeTo); } 99 virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; 100 inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 101 { this->roll(Degree(angle), relativeTo); } 102 103 virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; 104 virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; 105 inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 90 91 inline void yaw(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local) 92 { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); } 93 inline void pitch(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local) 94 { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); } 95 inline void roll(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local) 96 { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); } 97 98 void lookAt(const Vector3& target, TransformSpace::Space relativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 99 void setDirection(const Vector3& direction, TransformSpace::Space relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 100 inline void setDirection(float x, float y, float z, TransformSpace::Space relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 106 101 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } 107 102 108 inline void setScale3D(const Vector3& scale) 109 { this->node_->setScale(scale); } 103 virtual void setScale3D(const Vector3& scale); 110 104 inline void setScale3D(float x, float y, float z) 111 { this->node_->setScale(x, y, z); } 112 inline const Vector3& getScale3D(void) const 113 { return this->node_->getScale(); } 114 115 inline void setScale(float scale) 116 { this->node_->setScale(scale, scale, scale); } 105 { this->setScale3D(Vector3(x, y, z)); } 106 const Vector3& getScale3D(void) const; 107 108 void setScale(float scale) 109 { this->setScale3D(scale, scale, scale); } 117 110 inline float getScale() const 118 111 { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } 119 112 120 113 inline void scale3D(const Vector3& scale) 121 { this-> node_->scale(scale); }114 { this->setScale3D(this->getScale3D() * scale); } 122 115 inline void scale3D(float x, float y, float z) 123 { this-> node_->scale(x, y, z); }116 { this->scale3D(Vector3(x, y, z)); } 124 117 inline void scale(float scale) 125 { this-> node_->scale(scale, scale, scale); }118 { this->scale3D(scale, scale, scale); } 126 119 127 120 void attach(WorldEntity* object); … … 130 123 inline const std::set<WorldEntity*>& getAttachedObjects() const 131 124 { return this->children_; } 125 126 void attachOgreObject(Ogre::MovableObject* object); 127 void detachOgreObject(Ogre::MovableObject* object); 128 Ogre::MovableObject* detachOgreObject(const Ogre::String& name); 132 129 133 130 inline void attachToParent(WorldEntity* parent) … … 138 135 { return this->parent_; } 139 136 137 void notifyChildPropsChanged(); 138 140 139 protected: 141 140 Ogre::SceneNode* node_; 142 141 143 142 private: 144 void updateParent();145 146 143 inline void lookAt_xmlport(const Vector3& target) 147 144 { this->lookAt(target); } … … 155 152 { this->roll(angle); } 156 153 154 // network callbacks 155 void parentChanged(); 156 inline void scaleChanged() 157 { this->setScale3D(this->getScale3D()); } 158 157 159 WorldEntity* parent_; 158 160 unsigned int parentID_; 159 161 std::set<WorldEntity*> children_; 162 163 164 ///////////// 165 // Physics // 166 ///////////// 167 168 public: 169 enum CollisionType 170 { 171 Dynamic, 172 Kinematic, 173 Static, 174 None 175 }; 176 177 bool hasPhysics() const { return getCollisionType() != None ; } 178 bool isStatic() const { return getCollisionType() == Static ; } 179 bool isKinematic() const { return getCollisionType() == Kinematic; } 180 bool isDynamic() const { return getCollisionType() == Dynamic ; } 181 bool isPhysicsActive() const { return this->bPhysicsActive_; } 182 bool addedToPhysicalWorld() const; 183 184 void activatePhysics(); 185 void deactivatePhysics(); 186 187 inline CollisionType getCollisionType() const 188 { return this->collisionType_; } 189 void setCollisionType(CollisionType type); 190 191 void setCollisionTypeStr(const std::string& type); 192 std::string getCollisionTypeStr() const; 193 194 inline void setMass(float mass) 195 { this->mass_ = mass; recalculateMassProps(); } 196 inline float getMass() const 197 { return this->mass_; } 198 199 inline float getTotalMass() const 200 { return this->mass_ + this->childrenMass_; } 201 202 inline void setRestitution(float restitution) 203 { this->restitution_ = restitution; resetPhysicsProps(); } 204 inline float getRestitution() const 205 { return this->restitution_; } 206 207 inline void setAngularFactor(float angularFactor) 208 { this->angularFactor_ = angularFactor; resetPhysicsProps(); } 209 inline float getAngularFactor() const 210 { return this->angularFactor_; } 211 212 inline void setLinearDamping(float linearDamping) 213 { this->linearDamping_ = linearDamping; resetPhysicsProps(); } 214 inline float getLinearDamping() const 215 { return this->linearDamping_; } 216 217 inline void setAngularDamping(float angularDamping) 218 { this->angularDamping_ = angularDamping; resetPhysicsProps(); } 219 inline float getAngularDamping() const 220 { return this->angularDamping_; } 221 222 inline void setFriction(float friction) 223 { this->friction_ = friction; resetPhysicsProps(); } 224 inline float getFriction() const 225 { return this->friction_; } 226 227 void attachCollisionShape(CollisionShape* shape); 228 void detachCollisionShape(CollisionShape* shape); 229 CollisionShape* getAttachedCollisionShape(unsigned int index) const; 230 231 inline CompoundCollisionShape* getCollisionShape() 232 { return this->collisionShape_; } 233 inline btRigidBody* getPhysicalBody() 234 { return this->physicalBody_; } 235 236 void notifyCollisionShapeChanged(); 237 void notifyChildMassChanged(); 238 239 protected: 240 virtual bool isCollisionTypeLegal(CollisionType type) const = 0; 241 242 btRigidBody* physicalBody_; 243 244 private: 245 void updateCollisionType(); 246 void recalculateMassProps(); 247 void resetPhysicsProps(); 248 249 // network callbacks 250 void collisionTypeChanged(); 251 void physicsActivityChanged(); 252 inline void massChanged() 253 { this->setMass(this->mass_); } 254 inline void restitutionChanged() 255 { this->setRestitution(this->restitution_); } 256 inline void angularFactorChanged() 257 { this->setAngularFactor(this->angularFactor_); } 258 inline void linearDampingChanged() 259 { this->setLinearDamping(this->linearDamping_); } 260 inline void angularDampingChanged() 261 { this->setAngularDamping(this->angularDamping_); } 262 inline void frictionChanged() 263 { this->setFriction(this->friction_); } 264 265 CollisionType collisionType_; 266 CollisionType collisionTypeSynchronised_; 267 bool bPhysicsActive_; 268 bool bPhysicsActiveSynchronised_; 269 CompoundCollisionShape* collisionShape_; 270 btScalar mass_; 271 btScalar restitution_; 272 btScalar angularFactor_; 273 btScalar linearDamping_; 274 btScalar angularDamping_; 275 btScalar friction_; 276 btScalar childrenMass_; 160 277 }; 278 279 // Inline heavily used functions for release builds. In debug, we better avoid including OgreSceneNode here. 280 #ifdef _NDEBUG 281 inline const Vector3& WorldEntity::getPosition() const 282 { return this->node_->getPosition(); } 283 inline const Quaternion& WorldEntity::getOrientation() const 284 { return this->node_->getrOrientation(); } 285 inline const Vector3& WorldEntity::getScale3D(void) const 286 { return this->node_->getScale(); } 287 #endif 161 288 } 162 289
Note: See TracChangeset
for help on using the changeset viewer.