- Timestamp:
- Dec 13, 2008, 8:55:40 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2423 r2426 32 32 33 33 #include <cassert> 34 #include <OgreSceneNode.h> 34 35 #include <OgreSceneManager.h> 35 36 #include "BulletDynamics/Dynamics/btRigidBody.h" … … 249 250 } 250 251 252 void WorldEntity::attachOgreObject(Ogre::MovableObject* object) 253 { 254 this->node_->attachObject(object); 255 } 256 257 void WorldEntity::detachOgreObject(Ogre::MovableObject* object) 258 { 259 this->node_->detachObject(object); 260 } 261 262 Ogre::MovableObject* WorldEntity::detachOgreObject(const Ogre::String& name) 263 { 264 return this->node_->detachObject(name); 265 } 266 251 267 void WorldEntity::attachCollisionShape(CollisionShape* shape) 252 268 { … … 289 305 } 290 306 307 #ifndef _NDEBUG 308 const Vector3& WorldEntity::getPosition() const 309 { 310 return this->node_->getPosition(); 311 } 312 313 const Quaternion& WorldEntity::getOrientation() const 314 { 315 return this->node_->getOrientation(); 316 } 317 318 const Vector3& WorldEntity::getScale3D() const 319 { 320 return this->node_->getScale(); 321 } 322 #endif 323 324 const Vector3& WorldEntity::getWorldPosition() const 325 { 326 return this->node_->_getDerivedPosition(); 327 } 328 329 const Quaternion& WorldEntity::getWorldOrientation() const 330 { 331 return this->node_->_getDerivedOrientation(); 332 } 333 334 void WorldEntity::translate(const Vector3& distance, TransformSpace::Space relativeTo) 335 { 336 switch (relativeTo) 337 { 338 case TransformSpace::Local: 339 // position is relative to parent so transform downwards 340 this->setPosition(this->getPosition() + this->getOrientation() * distance); 341 break; 342 case TransformSpace::Parent: 343 this->setPosition(this->getPosition() + distance); 344 break; 345 case TransformSpace::World: 346 // position is relative to parent so transform upwards 347 if (this->node_->getParent()) 348 setPosition(getPosition() + (node_->getParent()->_getDerivedOrientation().Inverse() * distance) 349 / node_->getParent()->_getDerivedScale()); 350 else 351 this->setPosition(this->getPosition() + distance); 352 break; 353 } 354 } 355 356 void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Space relativeTo) 357 { 358 switch(relativeTo) 359 { 360 case TransformSpace::Local: 361 this->setOrientation(this->getOrientation() * rotation); 362 break; 363 case TransformSpace::Parent: 364 // Rotations are normally relative to local axes, transform up 365 this->setOrientation(rotation * this->getOrientation()); 366 break; 367 case TransformSpace::World: 368 // Rotations are normally relative to local axes, transform up 369 this->setOrientation(this->getOrientation() * this->getWorldOrientation().Inverse() 370 * rotation * this->getWorldOrientation()); 371 break; 372 } 373 } 374 375 void WorldEntity::lookAt(const Vector3& target, TransformSpace::Space relativeTo, const Vector3& localDirectionVector) 376 { 377 Vector3 origin; 378 switch (relativeTo) 379 { 380 case TransformSpace::Local: 381 origin = Vector3::ZERO; 382 break; 383 case TransformSpace::Parent: 384 origin = this->getPosition(); 385 break; 386 case TransformSpace::World: 387 origin = this->getWorldPosition(); 388 break; 389 } 390 this->setDirection(target - origin, relativeTo, localDirectionVector); 391 } 392 393 void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Space relativeTo, const Vector3& localDirectionVector) 394 { 395 Quaternion savedOrientation(this->getOrientation()); 396 Ogre::Node::TransformSpace ogreRelativeTo; 397 switch (relativeTo) 398 { 399 case TransformSpace::Local: 400 ogreRelativeTo = Ogre::Node::TS_LOCAL; break; 401 case TransformSpace::Parent: 402 ogreRelativeTo = Ogre::Node::TS_PARENT; break; 403 case TransformSpace::World: 404 ogreRelativeTo = Ogre::Node::TS_WORLD; break; 405 } 406 this->node_->setDirection(direction, ogreRelativeTo, localDirectionVector); 407 Quaternion newOrientation(this->node_->getOrientation()); 408 this->node_->setOrientation(savedOrientation); 409 this->setOrientation(newOrientation); 410 } 411 291 412 void WorldEntity::setScale3D(const Vector3& scale) 292 413 { … … 295 416 296 417 this->node_->setScale(scale); 297 }298 299 void WorldEntity::scale3D(const Vector3& scale)300 {301 if (this->hasPhysics())302 ThrowException(NotImplemented, "Cannot set the scale of a physical object: Not yet implemented.");303 304 this->node_->scale(scale);305 418 } 306 419
Note: See TracChangeset
for help on using the changeset viewer.