Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 8, 2011, 11:45:32 PM (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup/src/orxonox/collisionshapes/CollisionShape.h

    r7163 r8422  
    2727 */
    2828
     29/**
     30    @file CollisionShape.h
     31    @brief Definition of the CollisionShape class.
     32    @ingroup Collisionshapes
     33*/
     34
    2935#ifndef _CollisionShape_H__
    3036#define _CollisionShape_H__
     
    3844namespace orxonox
    3945{
     46
     47    /**
     48    @brief
     49        Wrapper for bullet collision shape class btCollisionShape.
     50
     51    @author
     52        Reto Grieder
     53
     54    @see btCollisionShape
     55    @ingroup Collisionshapes
     56    */
    4057    class _OrxonoxExport CollisionShape : public BaseObject, public Synchronisable
    4158    {
     
    4663            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4764
     65            /**
     66            @brief Set the position of the CollisionShape.
     67                   If the position changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     68            @param position A vector indicating the new position.
     69            */
    4870            inline void setPosition(const Vector3& position)
    49                 { this->position_ = position; this->updateParent(); }
     71                { if(this->position_ == position) return; this->position_ = position; this->updateParent(); }
     72            /**
     73            @brief Get the position of the CollisionShape.
     74            @return Returns the position of the CollisionShape as a vector.
     75            */
    5076            inline const Vector3& getPosition() const
    5177                { return this->position_; }
    5278
     79            /**
     80            @brief Set the orientation of the CollisionShape.
     81                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     82            @param orientation A quaternion indicating the new orientation.
     83            */
    5384            inline void setOrientation(const Quaternion& orientation)
    54                 { this->orientation_ = orientation; this->updateParent(); }
     85                { if(this->orientation_ == orientation) return; this->orientation_ = orientation; this->updateParent(); }
     86            /**
     87            @brief Get the orientation of the CollisionShape.
     88            @return Returns the orientation of the CollisionShape as a quaternion.
     89            */
    5590            inline const Quaternion& getOrientation() const
    5691                { return this->orientation_; }
    5792
    58             void yaw(const Degree& angle)   { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); }
    59             void pitch(const Degree& angle) { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); }
    60             void roll(const Degree& angle)  { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); }
     93            /**
     94            @brief Rotate the CollisionShape around the y-axis by the specified angle.
     95                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     96            @param angle The angle by which the CollisionShape is rotated.
     97            */
     98            void yaw(const Degree& angle)
     99                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Y)); }
     100            /**
     101            @brief Rotate the CollisionShape around the x-axis by the specified angle.
     102                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     103            @param angle The angle by which the CollisionShape is rotated.
     104            */
     105            void pitch(const Degree& angle)
     106                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_X)); }
     107            /**
     108            @brief Rotate the CollisionShape around the z-axis by the specified angle.
     109                   If the orientation changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     110            @param angle The angle by which the CollisionShape is rotated.
     111            */
     112            void roll(const Degree& angle)
     113                { this->setOrientation(this->orientation_ * Quaternion(angle, Vector3::UNIT_Z)); }
    61114
    62             virtual void setScale3D(const Vector3& scale);
    63             virtual void setScale(float scale);
     115            /**
     116            @brief Scale the CollisionShape by the input vector.
     117                   Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions.
     118                   If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     119                   Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes.
     120            @param scale The scaling vector by which the CollisionShape is scaled.
     121            */
     122            inline void scale3D(const Vector3& scale)
     123                { this->setScale3D(this->getScale3D()*scale); }
     124            void setScale3D(const Vector3& scale); // Set the scale of the CollisionShape.
     125            /**
     126            @brief Get the scale of the CollisionShape.
     127            @return Returns a vector indicating the scale of the CollisionShape.
     128            */
    64129            inline const Vector3& getScale3D() const
    65130                { return this->scale_; }
    66131
    67             void updateShape();
     132            /**
     133            @brief (Uniformly) scale the CollisionShape by the input scale.
     134                   If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     135            @param scale The value by which the CollisionShape is scaled.
     136            */
     137            inline void scale(float scale)
     138                { this->setScale3D(this->getScale3D()*scale); }
     139            void setScale(float scale); // Set the (uniform) scale of the CollisionShape.
     140            /**
     141            @brief Get the (uniform) scale of the CollisionShape.
     142                   This is only meaningful if the CollisionShape has uniform scaling.
     143            @return Returns the (uniform) scale of the CollisionShape. Returns 0.0f if the scaling is non-uniform.
     144            */
     145            inline float getScale()
     146                { if(this->hasUniformScaling()) return this->scale_.x; return 0.0f; }
    68147
    69             void calculateLocalInertia(float mass, btVector3& inertia) const;
     148            /**
     149            @brief Check whether the CollisionShape is uniformly scaled.
     150            @return Returns true if the CollisionShape is uniformly scaled, false if not.
     151            */
     152            inline bool hasUniformScaling()
     153                { return this->uniformScale_; }
     154            virtual void changedScale(); // Is called when the scale of the CollisionShape has changed.
    70155
     156            void updateShape(); // Updates the shape.
     157
     158            void calculateLocalInertia(float mass, btVector3& inertia) const; // Calculates the local inertia of the collision shape.
     159
     160            /**
     161            @brief Get the bullet collision shape of this CollisionShape.
     162            @return Returns a pointer to the bullet collision shape of this CollisionShape.
     163            */
    71164            inline btCollisionShape* getCollisionShape() const
    72165                { return this->collisionShape_; }
    73166
    74             bool hasTransform() const;
     167            bool hasTransform() const; // Check whether the CollisionShape has been either moved or rotated or both.
    75168
    76             bool notifyBeingAttached(CompoundCollisionShape* newParent);
    77             void notifyDetached();
     169            bool notifyBeingAttached(CompoundCollisionShape* newParent); // Notifies the CollisionShape of being attached to a CompoundCollisionShape.
     170            void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape.
    78171
    79172        protected:
    80             virtual void updateParent();
    81             virtual void parentChanged();
     173            virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed.
     174            virtual void parentChanged(); // Is called when the parentID of the CollisionShape has changed.
     175
     176            /**
     177            @brief Create a new bullet collision shape depending on the internal parameters of the specific CollisionShape.
     178            @return Returns a pointer to the new bullet collision shape.
     179            */
    82180            virtual btCollisionShape* createNewShape() const = 0;
    83181
    84             btCollisionShape*       collisionShape_;
    85             CompoundCollisionShape* parent_;
    86             unsigned int            parentID_;
     182            btCollisionShape*       collisionShape_; //!< The bullet collision shape of this CollisionShape.
     183            CompoundCollisionShape* parent_; //!< The CompoundCollisionShape this CollisionShape belongs to, NULL if it doesn't belong to one.
     184            unsigned int            parentID_; //!< The objectID of the parent of this CollisionShape, which can either be a CompoundCollisionShape or a WorldEntity.
    87185
    88186        private:
    89187            void registerVariables();
    90188
    91             Vector3                 position_;
    92             Quaternion              orientation_;
    93             Vector3                 scale_;
     189            Vector3                 position_; //!< The position of the CollisionShape.
     190            Quaternion              orientation_; //!< The orientation of the CollisionShape.
     191            Vector3                 scale_; //!< The scale of the CollisionShape.
     192            bool                    uniformScale_; //!< Whether the scale is uniform.
    94193    };
    95194}
Note: See TracChangeset for help on using the changeset viewer.