Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 8:55:40 PM (16 years ago)
Author:
rgrieder
Message:
  • Handled translate, rotate, yaw, pitch, roll, lookAt and setDirection internally in WE. That only leaves setPosition and setOrientation to be pure virtual.
  • Removed loads of redundant and now obsolete code in MobileEntity and StaticEntity
  • Removed OgreSceneNode.h from WorldEntity in debug builds. getPosition, getOrientation and getScale3D are only inline in release mode. That should speed up dev builds a lot (the include is about 8300 line without Vector3, Quaternion, etc.)

Important:

  • Fixed a bug or introduced one: the lookAt(…) function in WE had default TransformSpace "TS_LOCAL", but that makes no sense the way I see it. Consider a SpaceShip and you would like it to face an asteroid. Then TS_LOCAL would yield weird results. The XMLPort attribute "lookAt" used the default value. That's where the bug might have been fixed or (I don't believe so) introduced.
File:
1 edited

Legend:

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

    r2423 r2426  
    3232
    3333#include <cassert>
     34#include <OgreSceneNode.h>
    3435#include <OgreSceneManager.h>
    3536#include "BulletDynamics/Dynamics/btRigidBody.h"
     
    249250    }
    250251
     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
    251267    void WorldEntity::attachCollisionShape(CollisionShape* shape)
    252268    {
     
    289305    }
    290306
     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
    291412    void WorldEntity::setScale3D(const Vector3& scale)
    292413    {
     
    295416
    296417        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);
    305418    }
    306419
Note: See TracChangeset for help on using the changeset viewer.