Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8556


Ignore:
Timestamp:
May 23, 2011, 11:40:58 PM (13 years ago)
Author:
dafrick
Message:

Merging pickup branch into presentation branch.

Location:
code/branches/presentation
Files:
20 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/data/levels/includes/pickups.oxi

    r7163 r8556  
    202202<PickupRepresentation
    203203    pickupName = "Drone Pickup"
    204     pickupDescription = "Adds a Drone to the Players Spaceship"
     204    pickupDescription = "Adds a Drone to the Player's Spaceship"
    205205    spawnerTemplate = "dronepickupRepresentation"
    206206>
     
    210210</PickupRepresentation>
    211211
     212<!-- Shrink Pickup -->
     213
     214<PickupRepresentation
     215    pickupName = "Small Shrink"
     216    pickupDescription = "Shrinks the Ship by a bit"
     217    spawnerTemplate = "smallshrinkpickupRepresentation"
     218>
     219    <pickup>
     220        <ShrinkPickup template=smallshrinkpickup />
     221    </pickup>
     222</PickupRepresentation>
     223
     224<PickupRepresentation
     225    pickupName = "Medium Shrink"
     226    pickupDescription = "Shrinks the Ship"
     227    spawnerTemplate = "mediumshrinkpickupRepresentation"
     228>
     229    <pickup>
     230        <ShrinkPickup template=mediumshrinkpickup />
     231    </pickup>
     232</PickupRepresentation>
     233
     234<PickupRepresentation
     235    pickupName = "Huge Shrink"
     236    pickupDescription = "Shrinks the Ship considerably"
     237    spawnerTemplate = "hugeshrinkpickupRepresentation"
     238>
     239    <pickup>
     240        <ShrinkPickup template=hugeshrinkpickup />
     241    </pickup>
     242</PickupRepresentation>
     243
  • code/branches/presentation/data/levels/pickups.oxw

    r7679 r8556  
    190190    </PickupSpawner>
    191191
     192    <PickupSpawner position="-25,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
     193      <pickup>
     194        <ShrinkPickup template ="smallshrinkpickup"/>
     195      </pickup>
     196    </PickupSpawner>
     197
     198    <PickupSpawner position="0,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
     199      <pickup>
     200        <ShrinkPickup template ="mediumshrinkpickup"/>
     201      </pickup>
     202    </PickupSpawner>
     203
     204    <PickupSpawner position="25,-50,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5">
     205      <pickup>
     206        <ShrinkPickup template ="hugeshrinkpickup"/>
     207      </pickup>
     208    </PickupSpawner>
     209
     210    <!--StaticEntity position="0,-200,0" direction="0,-1,0" collisionType=static mass=500 friction=0.01 >
     211      <attached>
     212        <Model position="0,0,0" mesh="cube.mesh" scale3D="10,10,10" />
     213      </attached>
     214      <collisionShapes>
     215        <BoxCollisionShape position="0,0,0" halfExtents="10,10,10" />
     216      </collisionShapes>
     217  </StaticEntity-->
     218
    192219  </Scene>
    193220</Level>
  • code/branches/presentation/data/levels/templates/pickupRepresentationTemplates.oxt

    r7679 r8556  
    391391  <InvisiblePickup
    392392    duration = 20.0
     393    activaionType = "immediate"
     394    durationType = "continuous"
     395  />
     396</Template>
     397
     398<Template name=smallshrinkpickupRepresentation>
     399    <PickupRepresentation>
     400        <spawner-representation>
     401            <StaticEntity>
     402                <attached>
     403                    <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1>
     404                        <attached>
     405                            <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=0.4 />
     406                        </attached>
     407                    </Billboard>
     408                </attached>
     409            </StaticEntity>
     410        </spawner-representation>
     411    </PickupRepresentation>
     412</Template>
     413
     414<Template name=smallshrinkpickup>
     415  <InvisiblePickup
     416    duration = 10.0
     417    shrinkFactor = 2.5
     418    activaionType = "immediate"
     419    durationType = "continuous"
     420  />
     421</Template>
     422
     423<Template name=mediumshrinkpickupRepresentation>
     424    <PickupRepresentation>
     425        <spawner-representation>
     426            <StaticEntity>
     427                <attached>
     428                    <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1>
     429                        <attached>
     430                            <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=0.7 />
     431                        </attached>
     432                    </Billboard>
     433                </attached>
     434            </StaticEntity>
     435        </spawner-representation>
     436    </PickupRepresentation>
     437</Template>
     438
     439<Template name=mediumshrinkpickup>
     440  <InvisiblePickup
     441    duration = 30.0
     442    shrinkFactor = 5.0
     443    activaionType = "immediate"
     444    durationType = "continuous"
     445  />
     446</Template>
     447
     448<Template name=hugeshrinkpickupRepresentation>
     449    <PickupRepresentation>
     450        <spawner-representation>
     451            <StaticEntity>
     452                <attached>
     453                    <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Sphere2" scale=0.1>
     454                        <attached>
     455                            <Billboard position="0,0,0" colour="1.0,0.55,1.0" material="Shrink" scale=1.0 />
     456                        </attached>
     457                    </Billboard>
     458                </attached>
     459            </StaticEntity>
     460        </spawner-representation>
     461    </PickupRepresentation>
     462</Template>
     463
     464<Template name=hugeshrinkpickup>
     465  <InvisiblePickup
     466    duration = 60.0
     467    shrinkFactor = 10.0
    393468    activaionType = "immediate"
    394469    durationType = "continuous"
  • code/branches/presentation/src/libraries/util/SubString.h

    r7401 r8556  
    169169        /// Returns the number of tokens stored in this SubString
    170170        inline unsigned int size() const { return this->tokens_.size(); }
    171         /// Returns the i'th token from the subset of strings @param index The index of the requested doken
     171        /// Returns the i'th token from the subset of strings @param index The index of the requested token
    172172        inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; }
    173173        /// Returns the i'th token from the subset of strings @param index The index of the requested token
  • code/branches/presentation/src/modules/objects/collisionshapes/BoxCollisionShape.cc

    r6417 r8556  
    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/presentation/src/modules/objects/collisionshapes/BoxCollisionShape.h

    r7601 r8556  
    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    @see btBoxShape
     54    @ingroup Collisionshapes
     55    */
    4556    class _ObjectsExport BoxCollisionShape : public CollisionShape
    4657    {
     
    5162            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5263
    53             inline void setHalfExtents(const Vector3& extents)
    54                 { this->halfExtents_ = extents; updateShape(); }
     64            /**
     65            @brief Set the half extents of the BoxCollisionShape.
     66                   If the half extent changes, this causes the internal collision shape to be recreated.
     67            @param extents A vector with the half extents.
     68                   The x-component is half the length, the y-component is half the height and the z-component is half the width.
     69            @return Returns true if the half extent has changed, false if not.
     70            */
     71            inline bool setHalfExtents(const Vector3& extents)
     72                { if(this->halfExtents_ == extents) return false; this->halfExtents_ = extents; updateShape(); return true; }
     73            /**
     74            @brief Get the half extents of the BoxCollisionShape.
     75            @return Returns a vector containing the half extents.
     76            */
    5577            inline const Vector3& getHalfExtents() const
    5678                { return halfExtents_;}
    5779
    58             inline void setWidth(float value)
    59                 { this->halfExtents_.z = value / 2; updateShape(); }
     80            /**
     81            @brief Set the width of the BoxCollisionShape.
     82                   If the width changes, this causes the internal collision shape to be recreated.
     83            @param value The width to be set.
     84            @return Returns true if the width has changed, false if not.
     85            */
     86            inline bool setWidth(float value)
     87                { if(this->halfExtents_.z == value/2.0f) return false; this->halfExtents_.z = value / 2.0f; updateShape(); return true; }
     88            /**
     89            @brief Get the width of the BoxCollisionShape.
     90            @return Returns the width of the BoxCollisionShape.
     91            */
    6092            inline float getWidth() const
    61                 { return this->halfExtents_.z * 2; }
     93                { return this->halfExtents_.z * 2.0f; }
    6294
    63             inline void setHeight(float value)
    64                 { this->halfExtents_.y = value / 2; updateShape(); }
     95            /**
     96            @brief Set the height of the BoxCollisionShape.
     97                   If the height changes, this causes the internal collision shape to be recreated.
     98            @param value The height to be set.
     99            @return Returns true if the height has changed, false if not.
     100            */
     101            inline bool setHeight(float value)
     102                { if(this->halfExtents_.y == value/2.0f) return false; this->halfExtents_.y = value / 2.0f; updateShape(); return true; }
     103            /**
     104            @brief Get the height of the BoxCollisionShape.
     105            @return Returns the height of the BoxCollisionShape.
     106            */
    65107            inline float getHeight() const
    66                 { return this->halfExtents_.y * 2; }
     108                { return this->halfExtents_.y * 2.0f; }
    67109
    68             inline void setLength(float value)
    69                 { this->halfExtents_.x = value / 2; updateShape(); }
     110            /**
     111            @brief Set the length of the BoxCollisionShape.
     112                   If the length changes, this causes the internal collision shape to be recreated.
     113            @param value The length to be set.
     114            @return Returns true if the length has changed, false if not.
     115            */
     116            inline bool setLength(float value)
     117                { if(this->halfExtents_.x == value/2.0f) return false; this->halfExtents_.x = value / 2.0f; updateShape(); return true; }
     118            /**
     119            @brief Get the length of the BoxCollisionShape.
     120            @return Returns the length of the BoxCollisionShape.
     121            */
    70122            inline float getLength() const
    71                 { return this->halfExtents_.x * 2; }
     123                { return this->halfExtents_.x * 2.0f; }
     124
     125            virtual void changedScale(); // Is called when the scale of the BoxCollisionShape has changed.
    72126
    73127        private:
    74128            void registerVariables();
    75129
    76             btCollisionShape* createNewShape() const;
     130            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the BoxCollisionShape.
    77131
    78             Vector3 halfExtents_;
     132            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.
    79133     };
    80134}
  • code/branches/presentation/src/modules/objects/collisionshapes/ConeCollisionShape.cc

    r6417 r8556  
    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/presentation/src/modules/objects/collisionshapes/ConeCollisionShape.h

    r7601 r8556  
    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    @see btConeShape
     52    @ingroup Collisionshapes
     53    */
    4354    class _ObjectsExport ConeCollisionShape : public CollisionShape
    4455    {
     
    4960            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5061
    51             inline void setRadius(float value)
    52                 { this->radius_ = value; updateShape(); }
     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            */
    5374            inline float getRadius() const
    5475                { return radius_; }
    5576
    56             inline void setHeight(float value)
    57                 { this->height_ = value; updateShape(); }
     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            */
    5889            inline float getHeight() const
    5990                { return this->height_; }
     91
     92            virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed.
    6093
    6194        private:
    6295            void registerVariables();
    6396
    64             btCollisionShape* createNewShape() const;
     97            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape.
    6598
    66             float radius_;
    67             float height_;
     99            float radius_; //!< The radius of the ConeCollisionShape.
     100            float height_; //!< The height of the ConeCollisionShape.
    68101     };
    69102}
  • code/branches/presentation/src/modules/objects/collisionshapes/PlaneCollisionShape.cc

    r6417 r8556  
    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/presentation/src/modules/objects/collisionshapes/PlaneCollisionShape.h

    r7601 r8556  
    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    @see btStaticPlaneShape
     54    @ingroup Collisionshapes
     55    */
    4556    class _ObjectsExport PlaneCollisionShape : public CollisionShape
    4657    {
     
    5162            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5263
    53             inline void setNormal(const Vector3& normal)
    54                 { this->normal_ = normal; updateShape(); }
    55             inline const Vector3& getNormal()
     64            /**
     65            @brief Set the normal of the PlaneCollisionShape.
     66                   If the normal changes, this causes the internal collision shape to be recreated.
     67            @param normal The normal vector to be set.
     68            @return Returns true if the normal has changed, false if not.
     69            */
     70            inline bool setNormal(const Vector3& normal)
     71                { if(this->normal_ == normal) return false; this->normal_ = normal; updateShape(); return true; }
     72            /**
     73            @brief Get the normal of the PlaneCollisionShape.
     74            @return Returns the normal vector of the PlaneCollisionShape.
     75            */
     76            inline const Vector3& getNormal() const
    5677                { return normal_;}
    5778
    58             inline void setOffset(float offset)
    59                 { this->offset_ = offset; updateShape(); }
    60             inline float getOffset()
     79            /**
     80            @brief Set the offset of the PlaneCollisionShape.
     81                   If the offset changes, this causes the internal collision shape to be recreated.
     82            @param offset The offset to be set.
     83            @return Returns true if the offset has changed, false if not.
     84            */
     85            inline bool setOffset(float offset)
     86                { if(this->offset_ == offset) return false; this->offset_ = offset; updateShape(); return true; }
     87            /**
     88            @brief Get the offset of the PlaneCollisionShape.
     89            @return Returns the offset of the PlaneCollisionShape.
     90            */
     91            inline float getOffset() const
    6192                { return this->offset_;}
     93
     94            virtual void changedScale(); // Is called when the scale of the PlaneCollisionShape has changed.
    6295
    6396        private:
    6497            void registerVariables();
    6598
    66             btCollisionShape* createNewShape()const;
     99            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the PlaneCollisionShape.
    67100
    68             Vector3 normal_;
    69             float   offset_;
     101            Vector3 normal_; //!< The normal vector of the PlaneCollisionShape.
     102            float   offset_; //!< The offset of the PlaneCollisionShape.
    70103     };
    71104}
  • code/branches/presentation/src/modules/objects/collisionshapes/SphereCollisionShape.cc

    r5781 r8556  
    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/presentation/src/modules/objects/collisionshapes/SphereCollisionShape.h

    r7601 r8556  
    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    @see btSphereShape
     52    @ingroup Collisionshapes
     53    */
    4354    class _ObjectsExport SphereCollisionShape : public CollisionShape
    4455    {
     
    4960            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5061
    51             inline void setRadius(float radius)
    52                 { this->radius_ = radius; updateShape(); }
     62            /**
     63            @brief Set the radius of the SphereCollisionShape.
     64                   If the radius changes, this causes the internal collision shape to be recreated.
     65            @param radius The radius to be set.
     66            @return Returns true if the radius has changed, false if not.
     67            */
     68            inline bool setRadius(float radius)
     69                { if(this->radius_ == radius) return false; this->radius_ = radius; updateShape(); return true; }
     70            /**
     71            @brief Get the radius of the SphereCollisionShape.
     72            @return Returns the radius of the SphereCollisionShape.
     73            */
    5374            inline float getRadius() const
    5475                { return this->radius_; }
     76
     77            virtual void changedScale(); // Is called when the scale of the SphereCollisionShape has changed.
    5578
    5679        private:
     
    5982            btCollisionShape* createNewShape() const;
    6083
    61             float radius_;
     84            float radius_; //!< The radius of the SphereCollisionShape.
    6285    };
    6386}
  • code/branches/presentation/src/modules/pickup/PickupPrereqs.h

    r8351 r8556  
    8585    class SpeedPickup;
    8686    class ShieldPickup;
     87    class ShrinkPickup;
    8788
    8889}
  • code/branches/presentation/src/modules/pickup/items/CMakeLists.txt

    r7163 r8556  
    66  SpeedPickup.cc
    77  ShieldPickup.cc
     8  ShrinkPickup.cc
    89)
  • code/branches/presentation/src/modules/pickup/items/ShrinkPickup.cc

    r8554 r8556  
    6060
    6161        this->initialize();
    62         this->shrinkFactor_ = 5.0;
    63         this->shrinkSpeed_ = 5.0;
    64         this->duration_ = 5.0;
    65         isActive_ = false;
    66         isTerminating_ = false;
     62        this->shrinkFactor_ = 5.0f;
     63        this->shrinkSpeed_ = 5.0f;
     64        this->duration_ = 5.0f;
     65        this->isActive_ = false;
     66        this->isTerminating_ = false;
     67
     68        this->size_ = 0;
     69        this->defaultCameraPos_ = 0.0f;
     70        this->defaultScale_ = Vector3::UNIT_SCALE;
     71        this->actualScale_ = Vector3::UNIT_SCALE;
     72        this->smallScale_ = Vector3::UNIT_SCALE;
     73        this->defaultMass_ = 1.0f;
     74        this->actualMass_ = 1.0f;
     75        this->smallMass_ = 1.0f;
     76        this->pawn_ = NULL;
    6777    }
    6878
     
    157167        {
    158168            this->pawn_ = this->carrierToPawnHelper();
    159             if(pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
     169            if(this->pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    160170                this->Pickupable::destroy();
    161171
    162172            //Collect scaling information.
    163             defaultScale_ = this->pawn_->getScale3D();
    164             defaultMass_ = this->pawn_->getMass();
    165 
    166             smallScale_ = defaultScale_ / shrinkFactor_;
    167             smallMass_ = defaultMass_ / shrinkFactor_;
    168 
    169             actualScale_ = defaultScale_;
    170             actualMass_ = defaultMass_;
    171 
    172             cameraPositions_ = this->pawn_->getCameraPositions();
    173             size_ = cameraPositions_.size();
    174             isActive_ = true;    //start shrinking now.
    175             durationTimer_.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
     173            this->defaultScale_ = this->pawn_->getScale3D();
     174            this->defaultMass_ = this->pawn_->getMass();
     175
     176            this->smallScale_ = this->defaultScale_ / this->shrinkFactor_;
     177            this->smallMass_ = this->defaultMass_ / this->shrinkFactor_;
     178
     179            this->actualScale_ = this->defaultScale_;
     180            this->actualMass_ = this->defaultMass_;
     181
     182            this->cameraPositions_ = this->pawn_->getCameraPositions();
     183            this->size_ = this->cameraPositions_.size();
     184            this->isActive_ = true;    //start shrinking now.
     185            this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
    176186        }
    177187    }
     
    185195    void ShrinkPickup::tick(float dt)
    186196    {
    187         if(isActive_ == true && actualScale_ > smallScale_)    //if the ship has not reached the target scale, continue shrinking
     197        if(this->isActive_ == true && this->actualScale_ > this->smallScale_)    //if the ship has not reached the target scale, continue shrinking
    188198        {
    189             float factor_ = 1 + dt*shrinkSpeed_;
    190 
    191             actualScale_ /= factor_;
    192             actualMass_ /= factor_;
    193 
    194             this->pawn_->setScale3D(actualScale_);
    195             this->pawn_->setMass(actualMass_);
    196 
    197             for(int index = 0; index < size_; index++)
     199            float factor = 1 + dt*this->shrinkSpeed_;
     200
     201            this->actualScale_ /= factor;
     202            this->actualMass_ /= factor;
     203
     204            this->pawn_->setScale3D(this->actualScale_);
     205            this->pawn_->setMass(this->actualMass_);
     206
     207            for(int index = 0; index < this->size_; index++)
    198208            {
    199                 CameraPosition* cameraPos_ = this->pawn_->getCameraPosition(index);
    200                 if(cameraPos_ == NULL)
     209                CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
     210                if(cameraPos == NULL)
    201211                continue;
    202                 cameraPos_->setPosition(cameraPos_->getPosition()*factor_);
     212                cameraPos->setPosition(cameraPos->getPosition()*factor);
    203213            }
    204214        }
    205         else isActive_ = false;
    206 
    207         if(isTerminating_ == true && actualScale_ < defaultScale_)    //grow until the ship reaches its default scale.
     215        else this->isActive_ = false;
     216
     217        if(this->isTerminating_ == true && this->actualScale_ < this->defaultScale_)    //grow until the ship reaches its default scale.
    208218        {
    209             float factor_ = 1 + dt*shrinkSpeed_;
    210 
    211             actualScale_ *= factor_;
    212             actualMass_ *= factor_;
    213 
    214             this->pawn_->setScale3D(actualScale_);
    215             this->pawn_->setMass(actualMass_);
    216 
    217             for(int index = 0; index < size_; index++)
     219            float factor = 1 + dt*this->shrinkSpeed_;
     220
     221            this->actualScale_ *= factor;
     222            this->actualMass_ *= factor;
     223
     224            this->pawn_->setScale3D(this->actualScale_);
     225            this->pawn_->setMass(this->actualMass_);
     226
     227            for(int index = 0; index < this->size_; index++)
    218228            {
    219                 CameraPosition* cameraPos_ = this->pawn_->getCameraPosition(index);
    220                 if(cameraPos_ == NULL)
     229                CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
     230                if(cameraPos == NULL)
    221231                continue;
    222                 cameraPos_->setPosition(cameraPos_->getPosition()/factor_);
     232                cameraPos->setPosition(cameraPos->getPosition()/factor);
    223233            }
    224234        }
    225         else if(isTerminating_ == true)
     235        else if(this->isTerminating_ == true)
    226236            this->Pickupable::destroy();
    227237
     
    234244    void ShrinkPickup::terminate(void)
    235245    {
    236         isActive_ = false;
    237         isTerminating_ = true;
     246        this->isActive_ = false;
     247        this->isTerminating_ = true;
    238248        setUsed(false);
    239249    }
  • code/branches/presentation/src/orxonox/collisionshapes/CollisionShape.cc

    r7401 r8556  
    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/presentation/src/orxonox/collisionshapes/CollisionShape.h

    r7163 r8556  
    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/presentation/src/orxonox/collisionshapes/CompoundCollisionShape.cc

    r5929 r8556  
    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        std::vector<CollisionShape*> shapes;
     264        // Iterate through all attached CollisionShapes and add them to the list of shapes.
     265        for(std::map<CollisionShape*, btCollisionShape*>::iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)
     266            shapes.push_back(it->first);
     267
     268        // Delete the compound shape and create a new one.
     269        delete this->compoundShape_;
     270        this->compoundShape_ = new btCompoundShape();
     271
     272        // Re-attach all CollisionShapes.
     273        for(std::vector<CollisionShape*>::iterator it = shapes.begin(); it != shapes.end(); it++)
     274        {
     275            CollisionShape* shape = *it;
     276            shape->setScale3D(this->getScale3D());
     277            // Only actually attach if we didn't pick a CompoundCollisionShape with no content.
     278            if (shape->getCollisionShape())
     279            {
     280                btTransform transf(multi_cast<btQuaternion>(shape->getOrientation()), multi_cast<btVector3>(shape->getPosition()));
     281                // Add the btCollisionShape of the CollisionShape as a child shape to the btCompoundShape of the CompoundCollisionShape.
     282                this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     283            }
     284        }
     285
     286        this->updatePublicShape();
     287
     288        /*
     289        // Iterate through all attached CollisionShapes
     290        for(std::map<CollisionShape*, btCollisionShape*>::const_iterator it = this->attachedShapes_.begin(); it != this->attachedShapes_.end(); it++)
     291        {
     292            // Rescale the CollisionShape.
     293            it->first->setScale3D(this->getScale3D());
     294            this->updateAttachedShape(it->first);
     295        }
     296
     297        this->updatePublicShape();*/
     298    }
    192299}
  • code/branches/presentation/src/orxonox/collisionshapes/CompoundCollisionShape.h

    r5781 r8556  
    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    @see btCompoundShape
     55    @ingroup Collisionshapes
     56    */
    4057    class _OrxonoxExport CompoundCollisionShape : public CollisionShape
    4158    {
     
    5370            void updateAttachedShape(CollisionShape* shape);
    5471
     72            virtual void changedScale();
     73
    5574        private:
    5675            void updatePublicShape();
  • code/branches/presentation/src/orxonox/worldentities/WorldEntity.cc

    r7937 r8556  
    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 (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.