Changeset 2300 for code/branches/physics/src/orxonox/objects/worldentities
- Timestamp:
- Nov 30, 2008, 12:36:46 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects/worldentities
- Files:
-
- 2 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/Backlight.h
r2103 r2300 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include " PositionableEntity.h"34 #include "StaticEntity.h" 35 35 #include "tools/BillboardSet.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Backlight : public PositionableEntity39 class _OrxonoxExport Backlight : public StaticEntity 40 40 { 41 41 public: -
code/branches/physics/src/orxonox/objects/worldentities/Billboard.cc
r2296 r2300 38 38 CreateFactory(Billboard); 39 39 40 Billboard::Billboard(BaseObject* creator) : PositionableEntity(creator)40 Billboard::Billboard(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(Billboard); -
code/branches/physics/src/orxonox/objects/worldentities/Billboard.h
r2087 r2300 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "util/Math.h" 35 35 #include "tools/BillboardSet.h" … … 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Billboard : public PositionableEntity39 class _OrxonoxExport Billboard : public StaticEntity 40 40 { 41 41 public: -
code/branches/physics/src/orxonox/objects/worldentities/Camera.cc
r2296 r2300 47 47 CreateFactory(Camera); 48 48 49 Camera::Camera(BaseObject* creator) : PositionableEntity(creator)49 Camera::Camera(BaseObject* creator) : StaticEntity(creator) 50 50 { 51 51 RegisterObject(Camera); -
code/branches/physics/src/orxonox/objects/worldentities/Camera.h
r2103 r2300 33 33 34 34 #include <OgrePrerequisites.h> 35 #include "objects/worldentities/ PositionableEntity.h"35 #include "objects/worldentities/StaticEntity.h" 36 36 #include "objects/Tickable.h" 37 37 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport Camera : public PositionableEntity, public Tickable40 class _OrxonoxExport Camera : public StaticEntity, public Tickable 41 41 { 42 42 friend class CameraManager; -
code/branches/physics/src/orxonox/objects/worldentities/CameraPosition.cc
r2087 r2300 38 38 CreateFactory(CameraPosition); 39 39 40 CameraPosition::CameraPosition(BaseObject* creator) : PositionableEntity(creator)40 CameraPosition::CameraPosition(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(CameraPosition); -
code/branches/physics/src/orxonox/objects/worldentities/CameraPosition.h
r2087 r2300 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/ PositionableEntity.h"34 #include "objects/worldentities/StaticEntity.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport CameraPosition : public PositionableEntity38 class _OrxonoxExport CameraPosition : public StaticEntity 39 39 { 40 40 public: -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2292 r2300 57 57 this->bDestroyWhenPlayerLeft_ = false; 58 58 59 this->velocity_ = Vector3::ZERO;60 59 this->acceleration_ = Vector3::ZERO; 61 60 … … 332 331 if (Core::isMaster()) 333 332 { 334 this->server_position_ = this-> node_->getPosition();333 this->server_position_ = this->getPosition(); 335 334 ++this->server_overwrite_; 336 335 } 337 336 else if (this->bControlled_) 338 337 { 339 this->client_position_ = this-> node_->getPosition();338 this->client_position_ = this->getPosition(); 340 339 } 341 340 } … … 345 344 if (Core::isMaster()) 346 345 { 347 this->server_orientation_ = this-> node_->getOrientation();346 this->server_orientation_ = this->getOrientation(); 348 347 ++this->server_overwrite_; 349 348 } 350 349 else if (this->bControlled_) 351 350 { 352 this->client_orientation_ = this-> node_->getOrientation();351 this->client_orientation_ = this->getOrientation(); 353 352 } 354 353 } … … 358 357 if (Core::isMaster()) 359 358 { 360 this->server_velocity_ = this-> velocity_;359 this->server_velocity_ = this->getVelocity(); 361 360 ++this->server_overwrite_; 362 361 } 363 362 else if (this->bControlled_) 364 363 { 365 this->client_velocity_ = this->velocity_; 366 } 367 } 368 369 void ControllableEntity::setVelocity(const Vector3& velocity) 370 { 371 if (this->bControlled_ || Core::isMaster()) 372 { 373 if (!this->isDynamic()) 374 { 375 // no physics, we do it ourselves 376 internalSetVelocity(velocity); 377 } 378 else 379 { 380 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 381 } 382 velocityChanged(); 364 this->client_velocity_ = this->getVelocity(); 383 365 } 384 366 } -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h
r2292 r2300 79 79 { return this->hudtemplate_; } 80 80 81 void setVelocity(const Vector3& velocity);82 inline void setVelocity(float x, float y, float z)83 { setVelocity(Vector3(x,y,z)); }84 85 81 inline void setAcceleration(const Vector3& acceleration) 86 82 { this->acceleration_ = acceleration; } … … 127 123 void processClientOrientation(); 128 124 129 inline void internalSetVelocity(const Vector3& velocity)130 { this->velocity_ = velocity; }131 125 void positionChanged(); 132 126 void orientationChanged(); … … 137 131 unsigned int server_overwrite_; 138 132 unsigned int client_overwrite_; 139 140 Vector3 velocity_;141 133 142 134 bool bControlled_; -
code/branches/physics/src/orxonox/objects/worldentities/Light.cc
r2296 r2300 47 47 CreateFactory(Light); 48 48 49 Light::Light(BaseObject* creator) : PositionableEntity(creator)49 Light::Light(BaseObject* creator) : StaticEntity(creator) 50 50 { 51 51 RegisterObject(Light); -
code/branches/physics/src/orxonox/objects/worldentities/Light.h
r2087 r2300 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 #include <string> … … 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport Light : public PositionableEntity42 class _OrxonoxExport Light : public StaticEntity 43 43 { 44 44 public: -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.cc
r2292 r2300 45 45 RegisterObject(LinearEntity); 46 46 47 this->velocity_ = Vector3::ZERO;48 47 this->acceleration_ = Vector3::ZERO; 49 48 this->rotationAxis_ = Vector3::ZERO; … … 65 64 SUPER(LinearEntity, XMLPort, xmlelement, mode); 66 65 67 XMLPortParamTemplate(LinearEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);68 66 XMLPortParamTemplate(LinearEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&); 69 67 XMLPortParamTemplate(LinearEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&); … … 129 127 void LinearEntity::positionChanged() 130 128 { 131 this->overwrite_position_ = this-> node_->getPosition();129 this->overwrite_position_ = this->getPosition(); 132 130 } 133 131 134 132 void LinearEntity::orientationChanged() 135 133 { 136 this->overwrite_orientation_ = this->node_->getOrientation(); 137 } 138 139 void LinearEntity::setVelocity(const Vector3& velocity) 140 { 141 if (!this->isDynamic()) 142 { 143 // no physics, we do it ourselves 144 internalSetVelocity(velocity); 145 } 146 else 147 { 148 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 149 } 134 this->overwrite_orientation_ = this->getOrientation(); 150 135 } 151 136 } -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.h
r2292 r2300 48 48 void registerVariables(); 49 49 50 inline void setVelocity(const Vector3& velocity);51 inline void setVelocity(float x, float y, float z)52 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }53 inline const Vector3& getVelocity() const54 { return this->velocity_; }55 56 50 inline void setAcceleration(const Vector3& acceleration) 57 51 { this->acceleration_ = acceleration; } … … 92 86 void positionChanged(); 93 87 void orientationChanged(); 94 inline void internalSetVelocity(const Vector3& velocity)95 { this->velocity_ = velocity; }96 88 97 Vector3 velocity_;98 89 Vector3 acceleration_; 99 90 Vector3 rotationAxis_; -
code/branches/physics/src/orxonox/objects/worldentities/Model.cc
r2296 r2300 38 38 CreateFactory(Model); 39 39 40 Model::Model(BaseObject* creator) : PositionableEntity(creator)40 Model::Model(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(Model); -
code/branches/physics/src/orxonox/objects/worldentities/Model.h
r2192 r2300 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "tools/Mesh.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport Model : public PositionableEntity38 class _OrxonoxExport Model : public StaticEntity 39 39 { 40 40 public: -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2298 r2300 42 42 RegisterObject(MovableEntity); 43 43 44 this->velocity_ = Vector3::ZERO; 45 44 46 this->registerVariables(); 45 47 } … … 52 54 { 53 55 SUPER(MovableEntity, XMLPort, xmlelement, mode); 56 57 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&); 54 58 } 55 59 … … 165 169 this->physicalBody_->setWorldTransform(transf); 166 170 } 167 else 168 { 169 // no physics, we do it ourselves 170 this->node_->setPosition(position); 171 } 171 172 this->node_->setPosition(position); 173 positionChanged(); 172 174 } 173 175 … … 180 182 this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z)); 181 183 } 182 else 183 { 184 // no physics, we do it ourselves 185 this->node_->translate(distance, relativeTo); 186 } 184 185 this->node_->translate(distance, relativeTo); 186 positionChanged(); 187 187 } 188 188 … … 195 195 this->physicalBody_->setWorldTransform(transf); 196 196 } 197 else 198 { 199 // no physics, we do it ourselves 200 this->node_->setOrientation(orientation); 201 } 197 198 this->node_->setOrientation(orientation); 199 orientationChanged(); 202 200 } 203 201 … … 211 209 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.w, rotation.x, rotation.y, rotation.z))); 212 210 } 213 else 214 { 215 // no physics, we do it ourselves 216 this->node_->rotate(rotation, relativeTo); 217 } 211 212 this->node_->rotate(rotation, relativeTo); 213 orientationChanged(); 218 214 } 219 215 … … 228 224 this->physicalBody_->setWorldTransform(transf * rotation); 229 225 } 230 else 231 { 232 // no physics, we do it ourselves 233 this->node_->yaw(angle, relativeTo); 234 } 226 227 this->node_->yaw(angle, relativeTo); 228 orientationChanged(); 235 229 } 236 230 … … 245 239 this->physicalBody_->setWorldTransform(transf * rotation); 246 240 } 247 else 248 { 249 // no physics, we do it ourselves 250 this->node_->pitch(angle, relativeTo); 251 } 241 242 this->node_->pitch(angle, relativeTo); 243 orientationChanged(); 252 244 } 253 245 … … 262 254 this->physicalBody_->setWorldTransform(transf * rotation); 263 255 } 264 else 265 { 266 // no physics, we do it ourselves 267 this->node_->roll(angle, relativeTo); 268 } 256 257 this->node_->roll(angle, relativeTo); 258 orientationChanged(); 269 259 } 270 260 … … 279 269 //this->physicalBody_->setWorldTransform(transf); 280 270 } 281 else 282 { 283 // no physics, we do it ourselves 284 this->node_->lookAt(target, relativeTo, localDirectionVector); 285 } 271 272 this->node_->lookAt(target, relativeTo, localDirectionVector); 273 orientationChanged(); 286 274 } 287 275 … … 290 278 if (this->isDynamic()) 291 279 { 292 ThrowException(NotImplemented, "ControllableEntity:: lookAt() is not yet supported for physical objects.");280 ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects."); 293 281 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 294 282 to any other space than TS_LOCAL."); … … 296 284 //this->physicalBody_->setWorldTransform(transf); 297 285 } 298 else 299 { 300 // no physics, we do it ourselves 301 this->node_->setDirection(direction, relativeTo, localDirectionVector); 302 } 303 } 304 305 bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) 286 287 this->node_->setDirection(direction, relativeTo, localDirectionVector); 288 orientationChanged(); 289 } 290 291 void MovableEntity::setVelocity(const Vector3& velocity) 292 { 293 if (this->isDynamic()) 294 { 295 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 296 } 297 298 this->velocity_ = velocity; 299 velocityChanged(); 300 } 301 302 bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const 306 303 { 307 304 if (type == WorldEntity::Static) … … 320 317 this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z())); 321 318 const btVector3& velocity = this->physicalBody_->getLinearVelocity(); 322 internalSetVelocity(Vector3(velocity.x(), velocity.y(), velocity.z())); 319 this->velocity_ = Vector3(velocity.x(), velocity.y(), velocity.z()); 320 velocityChanged(); 323 321 positionChanged(); 324 322 orientationChanged(); … … 330 328 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 331 329 worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z)); 330 if (this->isDynamic()) 331 { 332 // This function gets called only once for dynamic objects to set the initial conditions 333 // We have to set the velocity too. 334 this->physicalBody_->setLinearVelocity(btVector3(velocity_.x, velocity_.y, velocity_.z)); 335 } 332 336 } 333 337 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h
r2298 r2300 67 67 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 68 68 69 void setVelocity(const Vector3& velocity); 70 inline void setVelocity(float x, float y, float z) 71 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; } 72 inline const Vector3& getVelocity() const 73 { return this->velocity_; } 74 75 protected: 76 Vector3 velocity_; 69 77 70 78 private: 71 79 //void attachPhysicalObject(WorldEntity* object); 72 80 73 virtual void internalSetVelocity(const Vector3& velocity) { }74 81 virtual void positionChanged() { } 75 82 virtual void orientationChanged() { } 76 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type); 83 virtual void velocityChanged() { } 84 85 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 77 86 78 87 // Bullet btMotionState related -
code/branches/physics/src/orxonox/objects/worldentities/ParticleEmitter.cc
r2296 r2300 45 45 CreateFactory(ParticleEmitter); 46 46 47 ParticleEmitter::ParticleEmitter(BaseObject* creator) : PositionableEntity(creator)47 ParticleEmitter::ParticleEmitter(BaseObject* creator) : StaticEntity(creator) 48 48 { 49 49 RegisterObject(ParticleEmitter); -
code/branches/physics/src/orxonox/objects/worldentities/ParticleEmitter.h
r2087 r2300 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport ParticleEmitter : public PositionableEntity37 class _OrxonoxExport ParticleEmitter : public StaticEntity 38 38 { 39 39 public: -
code/branches/physics/src/orxonox/objects/worldentities/SpawnPoint.cc
r2087 r2300 38 38 CreateFactory(SpawnPoint); 39 39 40 SpawnPoint::SpawnPoint(BaseObject* creator) : PositionableEntity(creator)40 SpawnPoint::SpawnPoint(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(SpawnPoint); -
code/branches/physics/src/orxonox/objects/worldentities/SpawnPoint.h
r2087 r2300 34 34 #include "core/Identifier.h" 35 35 #include "core/Template.h" 36 #include "PositionableEntity.h"37 36 #include "objects/worldentities/pawns/Pawn.h" 37 #include "objects/worldentities/StaticEntity.h" 38 38 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport SpawnPoint : public PositionableEntity41 class _OrxonoxExport SpawnPoint : public StaticEntity 42 42 { 43 43 public: -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.cc
r2298 r2300 60 60 } 61 61 62 bool StaticEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) 62 bool StaticEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const 63 63 { 64 64 if (type == WorldEntity::Static) … … 73 73 void StaticEntity::setWorldTransform(const btTransform& worldTrans) 74 74 { 75 OrxAssert(false, "Setting world transform of a StaticEntity, which is static!");75 OrxAssert(false, "Setting world transform of a StaticEntity, which is CF_STATIC!"); 76 76 //COUT(0) << "Setting world transform of a StaticEntity, which is static!" << std::endl; 77 77 } -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.h
r2298 r2300 74 74 private: 75 75 76 bool isCollisionTypeLegal(CollisionType type) ;76 bool isCollisionTypeLegal(CollisionType type) const; 77 77 78 78 // Bullet btMotionState related -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2298 r2300 192 192 } 193 193 194 float WorldEntity::getMass() 194 float WorldEntity::getMass() const 195 195 { 196 196 if (!checkPhysics()) 197 197 return 0.0f; 198 198 199 return 1.0f/this->physicalBody_->getInvMass(); 199 if (this->physicalBody_->getInvMass() == 0.0f) 200 return 0.0f; 201 else 202 return 1.0f/this->physicalBody_->getInvMass(); 200 203 } 201 204 … … 221 224 if (type != None && this->collisionType_ == None) 222 225 { 226 // First, check whether our SceneNode is relative to the root space of the scene. 227 // TODO: Static and Kinematic objects don't always have to obey this rule. 228 if (this->node_->getParent() != this->getScene()->getRootSceneNode()) 229 ThrowException(PhysicsViolation, "Cannot make WorldEntity physical that is not in the root space of the Scene."); 230 223 231 // Create new rigid body 224 232 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, 0, btVector3(0,0,0)); … … 227 235 228 236 // Adjust parameters according to the node 229 btTransform nodeTransform;237 //btTransform nodeTransform; 230 238 //this-> 231 239 } … … 303 311 } 304 312 305 std::string WorldEntity::getCollisionTypeStr() 313 std::string WorldEntity::getCollisionTypeStr() const 306 314 { 307 315 switch (this->getCollisionType()) … … 334 342 } 335 343 336 float WorldEntity::getCollisionRadius() 344 float WorldEntity::getCollisionRadius() const 337 345 { 338 346 if (checkPhysics()) … … 345 353 } 346 354 347 bool WorldEntity::checkPhysics() 355 bool WorldEntity::checkPhysics() const 348 356 { 349 357 if (!this->physicalBody_) -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h
r2298 r2300 168 168 std::set<WorldEntity*> children_; 169 169 170 ///////////// 171 // Physics // 172 ///////////// 170 171 ///////////// 172 // Physics // 173 ///////////// 173 174 174 175 public: … … 181 182 }; 182 183 183 bool hasPhysics() { return getCollisionType() != None; }184 185 CollisionType getCollisionType() { return this->collisionType_; }184 bool hasPhysics() const { return getCollisionType() != None; } 185 186 CollisionType getCollisionType() const { return this->collisionType_; } 186 187 void setCollisionType(CollisionType type); 187 188 188 189 void setCollisionTypeStr(const std::string& type); 189 std::string getCollisionTypeStr() ;190 191 bool isStatic() { return getCollisionType() == Static ; }192 bool isKinematic() { return getCollisionType() == Kinematic; }193 bool isDynamic() { return getCollisionType() == Dynamic ; }190 std::string getCollisionTypeStr() const; 191 192 bool isStatic() const { return getCollisionType() == Static ; } 193 bool isKinematic() const { return getCollisionType() == Kinematic; } 194 bool isDynamic() const { return getCollisionType() == Dynamic ; } 194 195 195 196 void setMass(float mass); 196 float getMass() ;197 float getMass() const; 197 198 198 199 void setCollisionRadius(float radius); 199 float getCollisionRadius() ;200 float getCollisionRadius() const; 200 201 201 202 protected: … … 203 204 //virtual void attachPhysicalObject(WorldEntity* object); 204 205 205 virtual bool isCollisionTypeLegal(CollisionType type) = 0;206 bool checkPhysics() ;206 virtual bool isCollisionTypeLegal(CollisionType type) const = 0; 207 bool checkPhysics() const; 207 208 void updateCollisionType(); 208 209 -
code/branches/physics/src/orxonox/objects/worldentities/triggers/Trigger.cc
r2296 r2300 44 44 CreateFactory(Trigger); 45 45 46 Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator)46 Trigger::Trigger(BaseObject* creator) : StaticEntity(creator) 47 47 { 48 48 RegisterObject(Trigger); -
code/branches/physics/src/orxonox/objects/worldentities/triggers/Trigger.h
r2103 r2300 36 36 37 37 #include "objects/Tickable.h" 38 #include "objects/worldentities/ PositionableEntity.h"38 #include "objects/worldentities/StaticEntity.h" 39 39 #include "tools/BillboardSet.h" 40 40 … … 48 48 }; 49 49 50 class _OrxonoxExport Trigger : public PositionableEntity, public Tickable50 class _OrxonoxExport Trigger : public StaticEntity, public Tickable 51 51 { 52 52 public:
Note: See TracChangeset
for help on using the changeset viewer.