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.

Location:
code/branches/pickup/src/orxonox
Files:
5 edited

Legend:

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

    r7401 r8422  
    2626 *
    2727 */
     28
     29/**
     30    @file CollisionShape.cc
     31    @brief Implementation of the CollisionShape class.
     32*/
    2833
    2934#include "CollisionShape.h"
     
    3944namespace orxonox
    4045{
     46
     47    /**
     48    @brief
     49        Constructor. Registers and initializes the object.
     50    */
    4151    CollisionShape::CollisionShape(BaseObject* creator)
    4252        : BaseObject(creator)
     
    5161        this->orientation_ = Quaternion::IDENTITY;
    5262        this->scale_ = Vector3::UNIT_SCALE;
     63        this->uniformScale_ = true;
    5364
    5465        this->registerVariables();
    5566    }
    5667
     68    /**
     69    @brief
     70        Destructor. Detaches the CollisionShape from its parent.
     71    */
    5772    CollisionShape::~CollisionShape()
    5873    {
    59         // Detach from parent
     74        // Detach from parent CompoundCollisionShape.
    6075        if (this->isInitialized() && this->parent_)
    6176            this->parent_->detach(this);
     
    7590    }
    7691
     92    /**
     93    @brief
     94        Register variables that need synchronizing over the network.
     95    */
    7796    void CollisionShape::registerVariables()
    7897    {
     98        // Keep the shape's parent (can be either a CompoundCollisionShape or a WorldEntity) consistent over the network.
    7999        registerVariable(this->parentID_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));
    80100    }
    81101
     102    /**
     103    @brief
     104        Notifies the CollisionShape of being attached to a CompoundCollisionShape.
     105    @param newParent
     106        A pointer to the CompoundCollisionShape the CollisionShape was attached to.
     107    @return
     108        Returns
     109    */
     110    bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent)
     111    {
     112        // If the CollisionShape is attached to a CompoundCollisionShapes, detach it.
     113        if (this->parent_)
     114            this->parent_->detach(this);
     115
     116        this->parent_ = newParent;
     117
     118        // If the new parent is a WorldEntityCollisionShape, the parentID is set to the objectID of the WorldEntity that is its owner.
     119        // TODO: Why?
     120        WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent);
     121        if (parentWECCS)
     122            this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID();
     123        // Else it is set to the objectID of the CompoundCollisionShape.
     124        else
     125            this->parentID_ = newParent->getObjectID();
     126
     127        return true;
     128    }
     129
     130    /**
     131    @brief
     132        Notifies the CollisionShape of being detached from a CompoundCollisionShape.
     133    */
     134    void CollisionShape::notifyDetached()
     135    {
     136        this->parent_ = 0;
     137        this->parentID_ = OBJECTID_UNKNOWN;
     138    }
     139
     140    /**
     141    @brief
     142        Updates the CompoundCollisionShape the CollisionShape belongs to (if it belongs to one), after the CollisionShape has changed.
     143    */
     144    void CollisionShape::updateParent()
     145    {
     146        if (this->parent_)
     147            this->parent_->updateAttachedShape(this);
     148    }
     149
     150    /**
     151    @brief
     152        Is called when the parentID of the CollisionShape has changed.
     153        Attaches it to the object with the changed parentID, which can either be a CompoundCollisionShape or a WorldEntity.
     154    */
    82155    void CollisionShape::parentChanged()
    83156    {
     157        // Get the parent object from the network.
    84158        Synchronisable* parent = Synchronisable::getSynchronisable(this->parentID_);
     159
    85160        // Parent can either be a WorldEntity or a CompoundCollisionShape. The reason is that the
    86161        // internal collision shape (which is compound) of a WE doesn't get synchronised.
    87162        CompoundCollisionShape* parentCCS = orxonox_cast<CompoundCollisionShape*>(parent);
     163
     164        // If the parent is a CompoundCollisionShape, attach the CollisionShape to it.
    88165        if (parentCCS)
    89166            parentCCS->attach(this);
    90167        else
    91168        {
     169            // If the parent is a WorldEntity, attach the CollisionShape to its collision shapes.
    92170            WorldEntity* parentWE = orxonox_cast<WorldEntity*>(parent);
    93171            if (parentWE)
     
    96174    }
    97175
    98     bool CollisionShape::notifyBeingAttached(CompoundCollisionShape* newParent)
    99     {
    100         if (this->parent_)
    101             this->parent_->detach(this);
    102 
    103         this->parent_ = newParent;
    104 
    105         WorldEntityCollisionShape* parentWECCS = orxonox_cast<WorldEntityCollisionShape*>(newParent);
    106         if (parentWECCS)
    107             this->parentID_ = parentWECCS->getWorldEntityOwner()->getObjectID();
    108         else
    109             this->parentID_ = newParent->getObjectID();
    110 
    111         return true;
    112     }
    113 
    114     void CollisionShape::notifyDetached()
    115     {
    116         this->parent_ = 0;
    117         this->parentID_ = OBJECTID_UNKNOWN;
    118     }
    119 
    120     void CollisionShape::updateParent()
    121     {
    122         if (this->parent_)
    123             this->parent_->updateAttachedShape(this);
    124     }
    125 
     176    /**
     177    @brief
     178        Check whether the CollisionShape has been either moved or rotated or both. (i.e. it doesn't have position zero and identity orientation any more)
     179    @return
     180        Returns true if it has been moved.
     181    */
    126182    bool CollisionShape::hasTransform() const
    127183    {
     
    130186    }
    131187
     188    /**
     189    @brief
     190        Set the scale of the CollisionShape.
     191        Since the scale is a vector the CollisionShape can be scaled independently in each direction, allowing for linear distortions.
     192        If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     193        Beware, non-uniform scaling (i.e. distortions) might not be supported by all CollisionShapes.
     194    @param scale
     195        The new scale to be set. Vector3::UNIT_SCALE is the initial scale.
     196    */
    132197    void CollisionShape::setScale3D(const Vector3& scale)
    133198    {
    134         CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
    135     }
    136 
     199        if(this->scale_ == scale)
     200            return;
     201
     202        // If the vectors are not in the same direction, then this is no longer a uniform scaling.
     203        if(scale_.crossProduct(scale).squaredLength() != 0.0f)
     204        {
     205            CCOUT(2) << "Warning: Non-uniform scaling is not yet supported." << endl;
     206            return;
     207        }
     208
     209        this->scale_ = scale;
     210
     211        this->changedScale();
     212        this->updateParent();
     213    }
     214
     215    /**
     216    @brief
     217        Set the (uniform) scale of the CollisionShape.
     218        If the scale changes, this causes the parent CompoundCollisionShape (if there is one) to be updated.
     219    @param scale
     220        The scale to scale the CollisionShape with. 1.0f is the initial scale.
     221    */
    137222    void CollisionShape::setScale(float scale)
    138223    {
    139         CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
    140     }
    141 
     224        if(this->scale_.length() == scale)
     225            return;
     226
     227        this->scale_ = Vector3::UNIT_SCALE*scale;
     228
     229        this->changedScale();
     230        this->updateParent();
     231    }
     232
     233    /**
     234    @brief
     235        Is called when the scale of the CollisionShape has changed.
     236    */
     237    void CollisionShape::changedScale()
     238    {
     239        // Adjust the position of the CollisionShape.
     240        this->position_ *= this->getScale3D();
     241    }
     242
     243    /**
     244    @brief
     245        Updates the shape.
     246        Is called when the internal parameters of the shape have changed such that a new shape needs to be created.
     247    */
    142248    void CollisionShape::updateShape()
    143249    {
    144250        btCollisionShape* oldShape = this->collisionShape_;
    145251        this->collisionShape_ = this->createNewShape();
     252        // If the CollisionShape has been rescaled, scale the shape to fit the current scale.
     253        if(this->scale_ != Vector3::UNIT_SCALE)
     254            this->changedScale();
    146255        // When we recreate the shape, we have to inform the parent about this to update the shape
    147256        this->updateParent();
     
    150259    }
    151260
     261    /**
     262    @brief
     263        Calculates the local inertia of the collision shape.
     264    @todo
     265        Document.
     266    */
    152267    void CollisionShape::calculateLocalInertia(float mass, btVector3& inertia) const
    153268    {
  • 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}
  • code/branches/pickup/src/orxonox/collisionshapes/CompoundCollisionShape.cc

    r5929 r8422  
    2727 */
    2828
     29/**
     30    @file CompoundCollisionShape.cc
     31    @brief Implementation of the CompoundCollisionShape class.
     32*/
     33
    2934#include "CompoundCollisionShape.h"
    3035
     
    3944    CreateFactory(CompoundCollisionShape);
    4045
     46    /**
     47    @brief
     48        Constructor. Registers and initializes the object.
     49    */
    4150    CompoundCollisionShape::CompoundCollisionShape(BaseObject* creator) : CollisionShape(creator)
    4251    {
     
    4655    }
    4756
     57    /**
     58    @brief
     59        Destructor.
     60        Deletes all its children.
     61    */
    4862    CompoundCollisionShape::~CompoundCollisionShape()
    4963    {
     
    7084    }
    7185
     86    /**
     87    @brief
     88        Attach the input CollisionShape to the CompoundCollisionShape.
     89    @param shape
     90        A pointer to the CollisionShape that is to be attached.
     91    */
    7292    void CompoundCollisionShape::attach(CollisionShape* shape)
    7393    {
     94        // If either the input shape is NULL or we try to attach the CollisionShape to itself.
    7495        if (!shape || static_cast<CollisionShape*>(this) == shape)
    7596            return;
     97
    7698        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    7799        {
     
    80102        }
    81103
     104        // Notify the CollisionShape that it is being attached to the CompoundCollisionShape.
    82105        if (!shape->notifyBeingAttached(this))
    83106            return;
    84107
     108        // Attach it.
    85109        this->attachedShapes_[shape] = shape->getCollisionShape();
    86110
     111        // Only actually attach if we didn't pick a CompoundCollisionShape with no content.
    87112        if (shape->getCollisionShape())
    88113        {
    89             // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    90114            btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
     115            // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape.
    91116            this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
    92117
     
    95120    }
    96121
     122    /**
     123    @brief
     124        Detach the input CollisionShape form the CompoundCollisionShape.
     125    @param shape
     126        A pointer to the CollisionShape to be detached.
     127    */
    97128    void CompoundCollisionShape::detach(CollisionShape* shape)
    98129    {
     130        // If the input CollisionShape is actually attached.
    99131        if (this->attachedShapes_.find(shape) != this->attachedShapes_.end())
    100132        {
    101133            this->attachedShapes_.erase(shape);
    102134            if (shape->getCollisionShape())
    103                 this->compoundShape_->removeChildShape(shape->getCollisionShape());
     135                this->compoundShape_->removeChildShape(shape->getCollisionShape()); // TODO: Apparently this is broken?
    104136            shape->notifyDetached();
    105137
     
    110142    }
    111143
     144    /**
     145    @brief
     146        Detach all attached CollisionShapes.
     147    */
    112148    void CompoundCollisionShape::detachAll()
    113149    {
     
    116152    }
    117153
     154    /**
     155    @brief
     156        Update the input CollisionShape that is attached to the CompoundCollisionShape.
     157        This is called when the input shape's internal collision shape (a btCollisionShape) has changed.
     158    @param shape
     159        A pointer to the CollisionShape to be updated.
     160    */
    118161    void CompoundCollisionShape::updateAttachedShape(CollisionShape* shape)
    119162    {
    120163        if (!shape)
    121164            return;
     165
    122166        std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.find(shape);
     167        // Check whether the input shape belongs to this CompoundCollisionShape.
    123168        if (it == this->attachedShapes_.end())
    124169        {
     
    129174        // Remove old btCollisionShape, stored in the children map
    130175        if (it->second)
    131             this->compoundShape_->removeChildShape(it->second);
     176            this->compoundShape_->removeChildShape(it->second); // TODO: Apparently this is broken?
     177
     178        // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    132179        if (shape->getCollisionShape())
    133180        {
    134             // Only actually attach if we didn't pick a CompoundCollisionShape with no content
    135181            btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
    136182            this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     
    141187    }
    142188
     189    /**
     190    @brief
     191        Updates the public shape, the collision shape this CompoundCollisionShape has to the outside.
     192    */
    143193    void CompoundCollisionShape::updatePublicShape()
    144194    {
    145         btCollisionShape* primitive = 0;
    146         bool bPrimitive = true;
    147         bool bEmpty = true;
     195        btCollisionShape* primitive = 0; // The primitive shape, if there is one.
     196        bool bPrimitive = true; // Whether the CompoundCollisionShape has just one non-empty CollisionShape. And that shape also has no transformation.
     197        bool bEmpty = true; // Whether the CompoundCollisionShape is empty.
     198        // Iterate over all CollisionShapes that belong to this CompoundCollisionShape.
    148199        for (std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); ++it)
    149200        {
     201            // TODO: Make sure this is correct.
    150202            if (it->second)
    151203            {
    152204                bEmpty = false;
    153                 if (!it->first->hasTransform() && !bPrimitive)
     205                if (!it->first->hasTransform() && bPrimitive)
    154206                    primitive = it->second;
    155207                else
     208                {
    156209                    bPrimitive = false;
     210                    break;
     211                }
    157212            }
    158213        }
     214
     215        // If there is no non-empty CollisionShape.
    159216        if (bEmpty)
    160217        {
     218            // If there was none all along, nothing needs to be changed.
    161219            if (this->collisionShape_ == 0)
    162             {
    163                 this->collisionShape_ = 0;
    164220                return;
    165             }
    166221            this->collisionShape_ = 0;
    167222        }
     223        // If the CompoundCollisionShape is just a primitive.
     224        // Only one shape to be added, no transform; return it directly.
    168225        else if (bPrimitive)
    169         {
    170             // --> Only one shape to be added, no transform; return it directly
    171226            this->collisionShape_ = primitive;
    172         }
     227        // Make sure we use the compound shape when returning a btCollisionShape.
    173228        else
    174         {
    175             // Make sure we use the compound shape when returning a btCollisionShape
    176229            this->collisionShape_ = this->compoundShape_;
    177         }
     230
    178231        this->updateParent();
    179232    }
    180233
     234    /**
     235    @brief
     236        Get the attached CollisionShape at the given index.
     237    @param index
     238        The index of the desired CollisionShape.
     239    @return
     240        Returns a pointer to the attached CollisionShape at the given index.
     241    */
    181242    CollisionShape* CompoundCollisionShape::getAttachedShape(unsigned int index) const
    182243    {
     
    190251        return 0;
    191252    }
     253
     254    /**
     255    @brief
     256        Is called when the scale of the CompoundCollisionShape has changed.
     257        Iterates over all attached CollisionShapes and scales them, then recomputes their compound shape.
     258    */
     259    void CompoundCollisionShape::changedScale()
     260    {
     261        CollisionShape::changedScale();
     262
     263        // Iterate through all attached CollisionShapes.
     264        for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)
     265        {
     266            // Rescale the CollisionShape.
     267            it->first->setScale3D(this->getScale3D());
     268            this->updateAttachedShape(it->first);
     269        }
     270
     271        this->updatePublicShape();
     272    }
    192273}
  • code/branches/pickup/src/orxonox/collisionshapes/CompoundCollisionShape.h

    r5781 r8422  
    2727 */
    2828
     29/**
     30    @file CompoundCollisionShape.h
     31    @brief Definition of the CompoundCollisionShape class.
     32    @ingroup Collisionshapes
     33*/
     34
    2935#ifndef _CompoundCollisionShape_H__
    3036#define _CompoundCollisionShape_H__
     
    3844namespace orxonox
    3945{
     46
     47    /**
     48    @brief
     49        Wrapper for the bullet compound collision shape class btCompoundShape.
     50
     51    @author
     52        Reto Grieder
     53
     54    @ingroup Collisionshapes
     55    */
    4056    class _OrxonoxExport CompoundCollisionShape : public CollisionShape
    4157    {
     
    5369            void updateAttachedShape(CollisionShape* shape);
    5470
     71            virtual void changedScale();
     72
    5573        private:
    5674            void updatePublicShape();
  • code/branches/pickup/src/orxonox/worldentities/WorldEntity.cc

    r7937 r8422  
    642642    void WorldEntity::setScale3D(const Vector3& scale)
    643643    {
    644 /*
    645 HACK HACK HACK
    646         if (bScalePhysics && this->hasPhysics() && scale != Vector3::UNIT_SCALE)
    647         {
    648             CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented. Ignoring scaling." << std::endl;
    649             return;
    650         }
    651 HACK HACK HACK
    652 */
     644        // If physics is enabled scale the attached CollisionShape.
     645        if (false && this->hasPhysics() && this->collisionShape_ != NULL)
     646        {
     647            this->collisionShape_->setScale3D(scale);
     648        }
     649
    653650        this->node_->setScale(scale);
    654651
Note: See TracChangeset for help on using the changeset viewer.