Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10189


Ignore:
Timestamp:
Jan 11, 2015, 3:40:41 PM (9 years ago)
Author:
landauf
Message:

added new collision shape (cylinder)

Location:
code/trunk
Files:
3 added
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/CoreIncludes.h

    r9667 r10189  
    114114
    115115/**
    116     @brief Registers an abstract class in the framework.
     116    @brief Registers an abstract class in the framework. Should be used in combination with inheritsFrom(base-class-identifier).
    117117    @param ClassName The name of the class
    118118*/
  • code/trunk/src/modules/objects/ObjectsPrereqs.h

    r9526 r10189  
    7676
    7777    // collisionshapes
     78    class AbstractRadiusHeightCollisionShape;
    7879    class BoxCollisionShape;
    7980    class ConeCollisionShape;
     81    class CylinderCollisionShape;
    8082    class PlaneCollisionShape;
    8183    class SphereCollisionShape;
  • code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc

    r10184 r10189  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
    2828
    2929/**
    30     @file ConeCollisionShape.cc
    31     @brief Implementation of the ConeCollisionShape class.
     30    @file AbstractRadiusHeightCollisionShape.cc
     31    @brief Implementation of the AbstractRadiusHeightCollisionShape class.
    3232*/
    3333
    34 #include "ConeCollisionShape.h"
    35 
    36 #include <BulletCollision/CollisionShapes/btConeShape.h>
     34#include "AbstractRadiusHeightCollisionShape.h"
    3735
    3836#include "core/CoreIncludes.h"
     
    4240namespace orxonox
    4341{
    44     RegisterClass(ConeCollisionShape);
     42    RegisterAbstractClass(AbstractRadiusHeightCollisionShape).inheritsFrom(Class(CollisionShape));
    4543
    4644    /**
     
    4846        Constructor. Registers and initializes the object.
    4947    */
    50     ConeCollisionShape::ConeCollisionShape(Context* context) : CollisionShape(context)
     48    AbstractRadiusHeightCollisionShape::AbstractRadiusHeightCollisionShape(Context* context) : CollisionShape(context)
    5149    {
    52         RegisterObject(ConeCollisionShape);
     50        RegisterObject(AbstractRadiusHeightCollisionShape);
    5351
    5452        this->radius_ = 1.0f;
    5553        this->height_ = 1.0f;
    56         updateShape();
    5754
    5855        this->registerVariables();
    5956    }
    6057
    61     ConeCollisionShape::~ConeCollisionShape()
    62     {
    63         if (this->isInitialized())
    64             delete this->collisionShape_;
    65     }
    66 
    67     void ConeCollisionShape::registerVariables()
     58    void AbstractRadiusHeightCollisionShape::registerVariables()
    6859    {
    6960        registerVariable(this->radius_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
     
    7162    }
    7263
    73     void ConeCollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     64    void AbstractRadiusHeightCollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7465    {
    75         SUPER(ConeCollisionShape, XMLPort, xmlelement, mode);
     66        SUPER(AbstractRadiusHeightCollisionShape, XMLPort, xmlelement, mode);
    7667
    77         XMLPortParam(ConeCollisionShape, "radius", setRadius, getRadius, xmlelement, mode);
    78         XMLPortParam(ConeCollisionShape, "height", setHeight, getHeight, xmlelement, mode);
     68        XMLPortParam(AbstractRadiusHeightCollisionShape, "radius", setRadius, getRadius, xmlelement, mode);
     69        XMLPortParam(AbstractRadiusHeightCollisionShape, "height", setHeight, getHeight, xmlelement, mode);
    7970    }
    8071
    8172    /**
    8273    @brief
    83         Is called when the scale of the ConeCollisionShape has changed.
     74        Is called when the scale of the AbstractRadiusHeightCollisionShape has changed.
    8475    */
    85     void ConeCollisionShape::changedScale()
     76    void AbstractRadiusHeightCollisionShape::changedScale()
    8677    {
    8778        CollisionShape::changedScale();
     
    9283        if(!this->hasUniformScaling())
    9384        {
    94             orxout(internal_error) << "ConeCollisionShape: Non-uniform scaling is not yet supported." << endl;
     85            orxout(internal_error) << "AbstractRadiusHeightCollisionShape: Non-uniform scaling is not yet supported." << endl;
    9586            return;
    9687        }
     
    10091        this->updateShape();
    10192    }
    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     */
    109     btCollisionShape* ConeCollisionShape::createNewShape() const
    110     {
    111         return new btConeShape(this->radius_, this->height_);
    112     }
    11393}
  • code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.h

    r10184 r10189  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Fabian 'x3n' Landau
    2626 *
    2727 */
    2828
    2929/**
    30     @file ConeCollisionShape.h
    31     @brief Definition of the ConeCollisionShape class.
     30    @file AbstractRadiusHeightCollisionShape.h
     31    @brief Definition of the AbstractRadiusHeightCollisionShape class.
    3232    @ingroup Collisionshapes
    3333*/
    3434
    35 #ifndef _ConeCollisionShape_H__
    36 #define _ConeCollisionShape_H__
     35#ifndef _AbstractRadiusHeightCollisionShape_H__
     36#define _AbstractRadiusHeightCollisionShape_H__
    3737
    3838#include "objects/ObjectsPrereqs.h"
     
    4444    /**
    4545    @brief
    46         Wrapper for the bullet cone collision shape class btConeShape.
     46        Wrapper for the bullet collision shapes with radius and height.
    4747
    48     @author
    49         Reto Grieder
    50 
    51     @see btConeShape
    5248    @ingroup Collisionshapes
    5349    */
    54     class _ObjectsExport ConeCollisionShape : public CollisionShape
     50    class _ObjectsExport AbstractRadiusHeightCollisionShape : public CollisionShape
    5551    {
    5652        public:
    57             ConeCollisionShape(Context* context);
    58             virtual ~ConeCollisionShape();
     53            AbstractRadiusHeightCollisionShape(Context* context);
    5954
    6055            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    6156
    6257            /**
    63             @brief Set the radius of the ConeCollisionShape.
     58            @brief Set the radius of the AbstractRadiusHeightCollisionShape.
    6459                   If the radius changes, this causes the internal collision shape to be recreated.
    6560            @param value The radius to be set.
     
    6964                { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; }
    7065            /**
    71             @brief Get the radius of the ConeCollisionShape.
    72             @return Returns the radius of the ConeCollisionShape.
     66            @brief Get the radius of the AbstractRadiusHeightCollisionShape.
     67            @return Returns the radius of the AbstractRadiusHeightCollisionShape.
    7368            */
    7469            inline float getRadius() const
     
    7671
    7772            /**
    78             @brief Set the height of the ConeCollisionShape.
     73            @brief Set the height of the AbstractRadiusHeightCollisionShape.
    7974                   If the height changes, this causes the internal collision shape to be recreated.
    8075            @param value The height to be set.
     
    8479                { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; }
    8580            /**
    86             @brief Get the height of the ConeCollisionShape.
    87             @return Returns the height of the ConeCollisionShape.
     81            @brief Get the height of the AbstractRadiusHeightCollisionShape.
     82            @return Returns the height of the AbstractRadiusHeightCollisionShape.
    8883            */
    8984            inline float getHeight() const
    9085                { return this->height_; }
    9186
    92             virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed.
     87            virtual void changedScale(); // Is called when the scale of the AbstractRadiusHeightCollisionShape has changed.
    9388
    9489        private:
    9590            void registerVariables();
    9691
    97             btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape.
    98 
    99             float radius_; //!< The radius of the ConeCollisionShape.
    100             float height_; //!< The height of the ConeCollisionShape.
     92            float radius_; //!< The radius of the AbstractRadiusHeightCollisionShape.
     93            float height_; //!< The height of the AbstractRadiusHeightCollisionShape.
    10194     };
    10295}
    10396
    104 #endif /* _ConeCollisionShape_H__ */
     97#endif /* _AbstractRadiusHeightCollisionShape_H__ */
  • code/trunk/src/modules/objects/collisionshapes/CMakeLists.txt

    r5781 r10189  
    11ADD_SOURCE_FILES(OBJECTS_SRC_FILES
     2  AbstractRadiusHeightCollisionShape.cc
    23  BoxCollisionShape.cc
    34  ConeCollisionShape.cc
     5  CylinderCollisionShape.cc
    46  PlaneCollisionShape.cc
    57  SphereCollisionShape.cc
  • code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc

    r9667 r10189  
    3737
    3838#include "core/CoreIncludes.h"
    39 #include "core/XMLPort.h"
    4039#include "tools/BulletConversions.h"
    4140
     
    4847        Constructor. Registers and initializes the object.
    4948    */
    50     ConeCollisionShape::ConeCollisionShape(Context* context) : CollisionShape(context)
     49    ConeCollisionShape::ConeCollisionShape(Context* context) : AbstractRadiusHeightCollisionShape(context)
    5150    {
    5251        RegisterObject(ConeCollisionShape);
    5352
    54         this->radius_ = 1.0f;
    55         this->height_ = 1.0f;
    5653        updateShape();
    57 
    58         this->registerVariables();
    5954    }
    6055
     
    6358        if (this->isInitialized())
    6459            delete this->collisionShape_;
    65     }
    66 
    67     void ConeCollisionShape::registerVariables()
    68     {
    69         registerVariable(this->radius_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
    70         registerVariable(this->height_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
    71     }
    72 
    73     void ConeCollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    74     {
    75         SUPER(ConeCollisionShape, XMLPort, xmlelement, mode);
    76 
    77         XMLPortParam(ConeCollisionShape, "radius", setRadius, getRadius, xmlelement, mode);
    78         XMLPortParam(ConeCollisionShape, "height", setHeight, getHeight, xmlelement, mode);
    79     }
    80 
    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             orxout(internal_error) << "ConeCollisionShape: 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();
    10160    }
    10261
     
    10968    btCollisionShape* ConeCollisionShape::createNewShape() const
    11069    {
    111         return new btConeShape(this->radius_, this->height_);
     70        return new btConeShape(this->getRadius(), this->getHeight());
    11271    }
    11372}
  • code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h

    r9667 r10189  
    3737
    3838#include "objects/ObjectsPrereqs.h"
    39 #include "collisionshapes/CollisionShape.h"
     39#include "AbstractRadiusHeightCollisionShape.h"
    4040
    4141namespace orxonox
     
    5252    @ingroup Collisionshapes
    5353    */
    54     class _ObjectsExport ConeCollisionShape : public CollisionShape
     54    class _ObjectsExport ConeCollisionShape : public AbstractRadiusHeightCollisionShape
    5555    {
    5656        public:
     
    5858            virtual ~ConeCollisionShape();
    5959
    60             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    61 
    62             /**
    63             @brief Set the radius of the ConeCollisionShape.
    64                    If the radius changes, this causes the internal collision shape to be recreated.
    65             @param value The radius to be set.
    66             @return Returns true if the radius has changed, false if not.
    67             */
    68             inline bool setRadius(float value)
    69                 { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; }
    70             /**
    71             @brief Get the radius of the ConeCollisionShape.
    72             @return Returns the radius of the ConeCollisionShape.
    73             */
    74             inline float getRadius() const
    75                 { return radius_; }
    76 
    77             /**
    78             @brief Set the height of the ConeCollisionShape.
    79                    If the height changes, this causes the internal collision shape to be recreated.
    80             @param value The height to be set.
    81             @return Returns true if the height has changed, false if not.
    82             */
    83             inline bool setHeight(float value)
    84                 { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; }
    85             /**
    86             @brief Get the height of the ConeCollisionShape.
    87             @return Returns the height of the ConeCollisionShape.
    88             */
    89             inline float getHeight() const
    90                 { return this->height_; }
    91 
    92             virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed.
    93 
    9460        private:
    95             void registerVariables();
    96 
    9761            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape.
    98 
    99             float radius_; //!< The radius of the ConeCollisionShape.
    100             float height_; //!< The height of the ConeCollisionShape.
    10162     };
    10263}
Note: See TracChangeset for help on using the changeset viewer.