Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 8, 2011, 11:45:32 PM (13 years ago)
Author:
dafrick
Message:

Documenting collision shapes in an effort to understand them and implement scaling.
Scaling is however not working yet, and thus not yet enabled.

Location:
code/branches/pickup/src/modules/objects/collisionshapes
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup/src/modules/objects/collisionshapes/BoxCollisionShape.cc

    r6417 r8422  
    2727 */
    2828
     29/**
     30    @file BoxCollisionShape.cc
     31    @brief Implementation of the BoxCollisionShape class.
     32*/
     33
    2934#include "BoxCollisionShape.h"
    3035
     
    3944    CreateFactory(BoxCollisionShape);
    4045
     46    /**
     47    @brief
     48        Constructor. Registers and initializes the object.
     49    */
    4150    BoxCollisionShape::BoxCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4251    {
     
    4453
    4554        this->halfExtents_ = Vector3(1, 1, 1);
    46         updateShape();
     55        this->updateShape();
    4756
    4857        this->registerVariables();
     
    5160    BoxCollisionShape::~BoxCollisionShape()
    5261    {
     62        // TODO: Move to CollisionShape?
    5363        if (this->isInitialized())
    5464            delete this->collisionShape_;
     
    7080    }
    7181
     82    /**
     83    @brief
     84        Is called when the scale of the BoxCollisionShape has changed.
     85    */
     86    void BoxCollisionShape::changedScale()
     87    {
     88        CollisionShape::changedScale();
     89
     90        // Resize the internal collision shape
     91        // TODO: Assuming setLocalScaling works.
     92        // this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
     93        if(!this->hasUniformScaling())
     94        {
     95            CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl;
     96            return;
     97        }
     98
     99        this->setHalfExtents(this->halfExtents_ * this->getScale());
     100    }
     101
     102    /**
     103    @brief
     104        Creates a new internal collision shape for the BoxCollisionShape.
     105    @return
     106        Returns a pointer to the newly created btBoxShape.
     107    */
    72108    btCollisionShape* BoxCollisionShape::createNewShape() const
    73109    {
  • code/branches/pickup/src/modules/objects/collisionshapes/BoxCollisionShape.h

    r7601 r8422  
    4343namespace orxonox
    4444{
     45
     46    /**
     47    @brief
     48        Wrapper for the bullet box collision shape class btBoxShape.
     49
     50    @author
     51        Reto Grieder
     52
     53    @ingroup Collisionshapes
     54    */
    4555    class _ObjectsExport BoxCollisionShape : public CollisionShape
    4656    {
     
    5161            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5262
    53             inline void setHalfExtents(const Vector3& extents)
    54                 { this->halfExtents_ = extents; updateShape(); }
     63            /**
     64            @brief Set the half extents of the BoxCollisionShape.
     65                   If the half extent changes, this causes the internal collision shape to be recreated.
     66            @param extents A vector with the half extents.
     67                   The x-component is half the length, the y-component is half the height and the z-component is half the width.
     68            @return Returns true if the half extent has changed, false if not.
     69            */
     70            inline bool setHalfExtents(const Vector3& extents)
     71                { if(this->halfExtents_ == extents) return false; this->halfExtents_ = extents; updateShape(); return true; }
     72            /**
     73            @brief Get the half extents of the BoxCollisionShape.
     74            @return Returns a vector containing the half extents.
     75            */
    5576            inline const Vector3& getHalfExtents() const
    5677                { return halfExtents_;}
    5778
    58             inline void setWidth(float value)
    59                 { this->halfExtents_.z = value / 2; updateShape(); }
     79            /**
     80            @brief Set the width of the BoxCollisionShape.
     81                   If the width changes, this causes the internal collision shape to be recreated.
     82            @param value The width to be set.
     83            @return Returns true if the width has changed, false if not.
     84            */
     85            inline bool setWidth(float value)
     86                { if(this->halfExtents_.z == value/2.0f) return false; this->halfExtents_.z = value / 2.0f; updateShape(); return true; }
     87            /**
     88            @brief Get the width of the BoxCollisionShape.
     89            @return Returns the width of the BoxCollisionShape.
     90            */
    6091            inline float getWidth() const
    61                 { return this->halfExtents_.z * 2; }
     92                { return this->halfExtents_.z * 2.0f; }
    6293
    63             inline void setHeight(float value)
    64                 { this->halfExtents_.y = value / 2; updateShape(); }
     94            /**
     95            @brief Set the height of the BoxCollisionShape.
     96                   If the height changes, this causes the internal collision shape to be recreated.
     97            @param value The height to be set.
     98            @return Returns true if the height has changed, false if not.
     99            */
     100            inline bool setHeight(float value)
     101                { if(this->halfExtents_.y == value/2.0f) return false; this->halfExtents_.y = value / 2.0f; updateShape(); return true; }
     102            /**
     103            @brief Get the height of the BoxCollisionShape.
     104            @return Returns the height of the BoxCollisionShape.
     105            */
    65106            inline float getHeight() const
    66                 { return this->halfExtents_.y * 2; }
     107                { return this->halfExtents_.y * 2.0f; }
    67108
    68             inline void setLength(float value)
    69                 { this->halfExtents_.x = value / 2; updateShape(); }
     109            /**
     110            @brief Set the length of the BoxCollisionShape.
     111                   If the length changes, this causes the internal collision shape to be recreated.
     112            @param value The length to be set.
     113            @return Returns true if the length has changed, false if not.
     114            */
     115            inline bool setLength(float value)
     116                { if(this->halfExtents_.x == value/2.0f) return false; this->halfExtents_.x = value / 2.0f; updateShape(); return true; }
     117            /**
     118            @brief Get the length of the BoxCollisionShape.
     119            @return Returns the length of the BoxCollisionShape.
     120            */
    70121            inline float getLength() const
    71                 { return this->halfExtents_.x * 2; }
     122                { return this->halfExtents_.x * 2.0f; }
     123
     124            virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed.
    72125
    73126        private:
    74127            void registerVariables();
    75128
    76             btCollisionShape* createNewShape() const;
     129            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape.
    77130
    78             Vector3 halfExtents_;
     131            Vector3 halfExtents_; //!< The half extents of the BoxCollisionShape. The x-component is half the length, the y-component is half the height and the z-component is half the width.
    79132     };
    80133}
  • code/branches/pickup/src/modules/objects/collisionshapes/ConeCollisionShape.cc

    r6417 r8422  
    2727 */
    2828
     29/**
     30    @file ConeCollisionShape.cc
     31    @brief Implementation of the ConeCollisionShape class.
     32*/
     33
    2934#include "ConeCollisionShape.h"
    3035
     
    3338#include "core/CoreIncludes.h"
    3439#include "core/XMLPort.h"
     40#include "tools/BulletConversions.h"
    3541
    3642namespace orxonox
     
    3844    CreateFactory(ConeCollisionShape);
    3945
     46    /**
     47    @brief
     48        Constructor. Registers and initializes the object.
     49    */
    4050    ConeCollisionShape::ConeCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4151    {
     
    6979    }
    7080
     81    /**
     82    @brief
     83        Is called when the scale of the ConeCollisionShape has changed.
     84    */
     85    void ConeCollisionShape::changedScale()
     86    {
     87        CollisionShape::changedScale();
     88
     89        // Resize the internal collision shape
     90        // TODO: Assuming setLocalScaling works.
     91        //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
     92        if(!this->hasUniformScaling())
     93        {
     94            CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl;
     95            return;
     96        }
     97
     98        this->radius_ *= this->getScale();
     99        this->height_ *= this->getScale();
     100        this->updateShape();
     101    }
     102
     103    /**
     104    @brief
     105        Creates a new internal collision shape for the ConeCollisionShape.
     106    @return
     107        Returns a pointer to the newly created btConeShape.
     108    */
    71109    btCollisionShape* ConeCollisionShape::createNewShape() const
    72110    {
  • code/branches/pickup/src/modules/objects/collisionshapes/ConeCollisionShape.h

    r7601 r8422  
    4141namespace orxonox
    4242{
     43
     44    /**
     45    @brief
     46        Wrapper for the bullet cone collision shape class btConeShape.
     47
     48    @author
     49        Reto Grieder
     50
     51    @ingroup Collisionshapes.
     52    */
    4353    class _ObjectsExport ConeCollisionShape : public CollisionShape
    4454    {
     
    4959            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5060
    51             inline void setRadius(float value)
    52                 { this->radius_ = value; updateShape(); }
     61            /**
     62            @brief Set the radius of the ConeCollisionShape.
     63                   If the radius changes, this causes the internal collision shape to be recreated.
     64            @param value The radius to be set.
     65            @return Returns true if the radius has changed, false if not.
     66            */
     67            inline bool setRadius(float value)
     68                { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; }
     69            /**
     70            @brief Get the radius of the ConeCollisionShape.
     71            @return Returns the radius of the ConeCollisionShape.
     72            */
    5373            inline float getRadius() const
    5474                { return radius_; }
    5575
    56             inline void setHeight(float value)
    57                 { this->height_ = value; updateShape(); }
     76            /**
     77            @brief Set the height of the ConeCollisionShape.
     78                   If the height changes, this causes the internal collision shape to be recreated.
     79            @param value The height to be set.
     80            @return Returns true if the height has changed, false if not.
     81            */
     82            inline bool setHeight(float value)
     83                { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; }
     84            /**
     85            @brief Get the height of the ConeCollisionShape.
     86            @return Returns the height of the ConeCollisionShape.
     87            */
    5888            inline float getHeight() const
    5989                { return this->height_; }
     90
     91            virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed.
    6092
    6193        private:
    6294            void registerVariables();
    6395
    64             btCollisionShape* createNewShape() const;
     96            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape.
    6597
    66             float radius_;
    67             float height_;
     98            float radius_; //!< The radius of the ConeCollisionShape.
     99            float height_; //!< The height of the ConeCollisionShape.
    68100     };
    69101}
  • code/branches/pickup/src/modules/objects/collisionshapes/PlaneCollisionShape.cc

    r6417 r8422  
    2727 */
    2828
     29/**
     30    @file PlaneCollisionShape.cc
     31    @brief Implementation of the PlaneCollisionShape class.
     32*/
     33
    2934#include "PlaneCollisionShape.h"
    3035
     
    3944    CreateFactory(PlaneCollisionShape);
    4045
     46    /**
     47    @brief
     48        Constructor. Registers and initializes the object.
     49    */
    4150    PlaneCollisionShape::PlaneCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4251    {
     
    7079    }
    7180
     81    /**
     82    @brief
     83        Is called when the scale of the PlaneCollisionShape has changed.
     84    */
     85    void PlaneCollisionShape::changedScale()
     86    {
     87        CollisionShape::changedScale();
     88
     89        // Resize the internal collision shape
     90        // TODO: Assuming setLocalScaling works.
     91        //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
     92        if(!this->hasUniformScaling())
     93        {
     94            CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl;
     95            return;
     96        }
     97
     98        this->setOffset(this->offset_*this->getScale());
     99    }
     100
     101    /**
     102    @brief
     103        Creates a new internal collision shape for the PlaneCollisionShape.
     104    @return
     105        Returns a pointer to the newly created btStaticPlaneShape.
     106    */
    72107    btCollisionShape* PlaneCollisionShape::createNewShape() const
    73108    {
  • code/branches/pickup/src/modules/objects/collisionshapes/PlaneCollisionShape.h

    r7601 r8422  
    4343namespace orxonox
    4444{
     45
     46    /**
     47    @brief
     48        Wrapper for the bullet plane collision shape class btStaticPlaneShape.
     49
     50    @author
     51        Martin Stypinski
     52
     53    @ingroup Collisionshapes
     54    */
    4555    class _ObjectsExport PlaneCollisionShape : public CollisionShape
    4656    {
     
    5161            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5262
    53             inline void setNormal(const Vector3& normal)
    54                 { this->normal_ = normal; updateShape(); }
    55             inline const Vector3& getNormal()
     63            /**
     64            @brief Set the normal of the PlaneCollisionShape.
     65                   If the normal changes, this causes the internal collision shape to be recreated.
     66            @param normal The normal vector to be set.
     67            @return Returns true if the normal has changed, false if not.
     68            */
     69            inline bool setNormal(const Vector3& normal)
     70                { if(this->normal_ == normal) return false; this->normal_ = normal; updateShape(); return true; }
     71            /**
     72            @brief Get the normal of the PlaneCollisionShape.
     73            @return Returns the normal vector of the PlaneCollisionShape.
     74            */
     75            inline const Vector3& getNormal() const
    5676                { return normal_;}
    5777
    58             inline void setOffset(float offset)
    59                 { this->offset_ = offset; updateShape(); }
    60             inline float getOffset()
     78            /**
     79            @brief Set the offset of the PlaneCollisionShape.
     80                   If the offset changes, this causes the internal collision shape to be recreated.
     81            @param offset The offset to be set.
     82            @return Returns true if the offset has changed, false if not.
     83            */
     84            inline bool setOffset(float offset)
     85                { if(this->offset_ == offset) return false; this->offset_ = offset; updateShape(); return true; }
     86            /**
     87            @brief Get the offset of the PlaneCollisionShape.
     88            @return Returns the offset of the PlaneCollisionShape.
     89            */
     90            inline float getOffset() const
    6191                { return this->offset_;}
     92
     93            virtual void changedScale(); // Is called when the scale of the PlaneCollisionShape has changed.
    6294
    6395        private:
    6496            void registerVariables();
    6597
    66             btCollisionShape* createNewShape()const;
     98            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the PlaneCollisionShape.
    6799
    68             Vector3 normal_;
    69             float   offset_;
     100            Vector3 normal_; //!< The normal vector of the PlaneCollisionShape.
     101            float   offset_; //!< The offset of the PlaneCollisionShape.
    70102     };
    71103}
  • code/branches/pickup/src/modules/objects/collisionshapes/SphereCollisionShape.cc

    r5781 r8422  
    2727 */
    2828
     29/**
     30    @file SphereCollisionShape.cc
     31    @brief Implementation of the SphereCollisionShape class.
     32*/
     33
    2934#include "SphereCollisionShape.h"
    3035
     
    3338#include "core/CoreIncludes.h"
    3439#include "core/XMLPort.h"
     40#include "tools/BulletConversions.h"
    3541
    3642namespace orxonox
     
    3844    CreateFactory(SphereCollisionShape);
    3945
     46    /**
     47    @brief
     48        Constructor. registers and initializes the object.
     49    */
    4050    SphereCollisionShape::SphereCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4151    {
     
    6676    }
    6777
     78    /**
     79    @brief
     80        Is called when the scale of the SphereCollisionShape has changed.
     81    */
     82    void SphereCollisionShape::changedScale()
     83    {
     84        CollisionShape::changedScale();
     85
     86        // Resize the internal collision shape
     87        // TODO: Assuming setLocalScaling works.
     88        //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
     89        if(!this->hasUniformScaling())
     90        {
     91            CCOUT(1) << "Error: Non-uniform scaling is not yet supported." << endl;
     92            return;
     93        }
     94
     95        this->setRadius(this->radius_*this->getScale());
     96    }
     97
     98    /**
     99    @brief
     100        Creates a new internal collision shape for the SphereCollisionShape.
     101    @return
     102        Returns a pointer to the newly created btSphereShape.
     103    */
    68104    btCollisionShape* SphereCollisionShape::createNewShape() const
    69105    {
  • code/branches/pickup/src/modules/objects/collisionshapes/SphereCollisionShape.h

    r7601 r8422  
    4141namespace orxonox
    4242{
     43
     44    /**
     45    @brief
     46        Wrapper for the bullet sphere collision shape class btSphereShape.
     47
     48    @author
     49        Reto Grieder
     50
     51    @ingroup Collisionshapes
     52    */
    4353    class _ObjectsExport SphereCollisionShape : public CollisionShape
    4454    {
     
    4959            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5060
    51             inline void setRadius(float radius)
    52                 { this->radius_ = radius; updateShape(); }
     61            /**
     62            @brief Set the radius of the SphereCollisionShape.
     63                   If the radius changes, this causes the internal collision shape to be recreated.
     64            @param radius The radius to be set.
     65            @return Returns true if the radius has changed, false if not.
     66            */
     67            inline bool setRadius(float radius)
     68                { if(this->radius_ == radius) return false; this->radius_ = radius; updateShape(); return true; }
     69            /**
     70            @brief Get the radius of the SphereCollisionShape.
     71            @return Returns the radius of the SphereCollisionShape.
     72            */
    5373            inline float getRadius() const
    5474                { return this->radius_; }
     75
     76            virtual void changedScale(); // Is called when the scale of the SphereCollisionShape has changed.
    5577
    5678        private:
     
    5981            btCollisionShape* createNewShape() const;
    6082
    61             float radius_;
     83            float radius_; //!< The radius of the SphereCollisionShape.
    6284    };
    6385}
Note: See TracChangeset for help on using the changeset viewer.