Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2403


Ignore:
Timestamp:
Dec 10, 2008, 11:33:58 PM (16 years ago)
Author:
rgrieder
Message:
  • Fixed issues with CollisionShape loading, handling and synchronisation.
  • Added eol-style native to PlaneCollisionShape
  • Unified treatment of configuring btCollisionShapes when parameters change
Location:
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.cc

    r2374 r2403  
    5252        this->parentID_ = (unsigned int)-1;
    5353        this->collisionShape_ = 0;
     54        this->position_ = Vector3::ZERO;
     55        this->orientation_ = Quaternion::IDENTITY;
     56        this->scale_ = Vector3::UNIT_SCALE;
    5457    }
    5558
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.cc

    r2374 r2403  
    4444        RegisterObject(CompoundCollisionShape);
    4545
    46         this->collisionShape_ = 0;
    4746        this->compoundShape_  = new btCompoundShape();
    4847    }
     
    6766        if (this->collisionShape_)
    6867            return this->collisionShape_;
    69         else if (this->childShapes_.size() != 0)
     68        else if (!this->empty())
    7069            return this->compoundShape_;
    7170        else
     
    7574    void CompoundCollisionShape::addChildShape(CollisionShape* shape)
    7675    {
    77         if (!shape || !shape->getCollisionShape())
     76        if (!shape)
    7877            return;
    79         assert(this->compoundShape_);
    80         btTransform transf(omni_cast<btQuaternion>(shape->getOrientation()), omni_cast<btVector3>(shape->getPosition()));
    81         this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     78        this->childShapes_.push_back(shape);
    8279
    83         if (this->childShapes_.size() == 1 && this->childShapes_[0] && !this->childShapes_[0]->hasTransform())
     80        if (shape->getCollisionShape())
    8481        {
    85             // --> Only shape to be added, no transform; add it directly
    86             this->collisionShape_ = shape->getCollisionShape();
    87         }
    88         else
    89         {
    90             // Make sure we use the compound shape
    91             this->collisionShape_ = 0;
     82            // Only actually attach if we didn't pick a CompoundCollisionShape with no content
     83            btTransform transf(omni_cast<btQuaternion>(shape->getOrientation()), omni_cast<btVector3>(shape->getPosition()));
     84            this->compoundShape_->addChildShape(transf, shape->getCollisionShape());
     85
     86            if (this->childShapes_.size() == 1 && !this->childShapes_[0]->hasTransform())
     87            {
     88                // --> Only shape to be added, no transform; add it directly
     89                this->collisionShape_ = shape->getCollisionShape();
     90            }
     91            else
     92            {
     93                // Make sure we use the compound shape when returning the btCollisionShape
     94                this->collisionShape_ = 0;
     95            }
    9296        }
    9397
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.h

    r2374 r2403  
    5050            virtual btCollisionShape* getCollisionShape() const;
    5151
     52            inline bool empty() const
     53                { return this->childShapes_.size() == 0; }
     54
    5255        private:
    53             btCompoundShape* compoundShape_;
     56            btCompoundShape*             compoundShape_;
    5457            std::vector<CollisionShape*> childShapes_;
    5558    };
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.cc

    • Property svn:eol-style set to native
    r2374 r2403  
    4242        RegisterObject(PlaneCollisionShape);
    4343
    44         this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1, 1), 0);
    45         this->collisionShape_ = this->planeShape_;
    46         this->planeNormal_ = Vector3(1, 1, 1);
    47         this->planeOffset_ = 0.0f;
     44        this->normal_ = Vector3(0, 1, 0);
     45        this->offset_ = 0.0f;
     46        updatePlane();
     47
     48        this->registerVariables();
    4849    }
    4950
     
    5152    {
    5253        if (this->isInitialized())
    53             delete this->planeShape_;
     54            delete this->collisionShape_;
    5455    }
    5556
    5657    void PlaneCollisionShape::registerVariables()
    5758    {
    58         REGISTERDATA(this->planeNormal_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeNormalChanged));
    59         REGISTERDATA(this->planeOffset_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeOffsetChanged));
     59        REGISTERDATA(this->normal_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));
     60        REGISTERDATA(this->offset_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));
    6061    }
    6162
     
    6465        SUPER(PlaneCollisionShape, XMLPort, xmlelement, mode);
    6566
    66         XMLPortParam(PlaneCollisionShape, "planeNormal", setNormal, getNormal, xmlelement, mode);
    67         XMLPortParam(PlaneCollisionShape, "planeOffset", setOffset, getOffset, xmlelement, mode);   
     67        XMLPortParam(PlaneCollisionShape, "normal", setNormal, getNormal, xmlelement, mode);
     68        XMLPortParam(PlaneCollisionShape, "offset", setOffset, getOffset, xmlelement, mode);   
    6869    }
    6970
    70     void PlaneCollisionShape::setNormal(const Vector3& normal)
     71    void PlaneCollisionShape::updatePlane()
    7172    {
    72         delete this->planeShape_;
    73         this->planeNormal_ = normal;
    74         this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), this->planeOffset_);
    75         this->collisionShape_ = this->planeShape_;
    76     }
    77 
    78     void PlaneCollisionShape::setOffset(float offset)
    79     {
    80         delete this->planeShape_;
    81         this->planeOffset_ = offset;
    82         this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(this->planeNormal_), offset);
    83         this->collisionShape_ = this->planeShape_;
     73        if (this->collisionShape_)
     74            delete this->collisionShape_;
     75        this->collisionShape_ = new btStaticPlaneShape(omni_cast<btVector3>(this->normal_), this->offset_);
    8476    }
    8577}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.h

    • Property svn:eol-style set to native
    r2374 r2403  
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4747
     48            inline void setNormal(const Vector3& normal)
     49                { this->normal_ = normal; updatePlane(); }
     50            inline const Vector3& getNormal()
     51                { return normal_;}
     52
     53            inline void setOffset(float offset)
     54                { this->offset_ = offset; updatePlane(); }
    4855            inline float getOffset()
    49                 { return this->planeShape_->getPlaneConstant();}
    50             void setOffset(float offset);
     56                { return this->offset_;}
    5157
    52             inline btVector3 getNormal()
    53                 { return this->planeShape_->getPlaneNormal();}
    54             void setNormal(const Vector3& normal);
    55 
    56             inline void planeNormalChanged()
    57                 { this->setNormal(this->planeNormal_); }
    58 
    59             inline void planeOffsetChanged()
    60                 { this->setOffset(this->planeOffset_); }
     58            void updatePlane();
    6159
    6260        private:
    63             btStaticPlaneShape* planeShape_;
    64             Vector3             planeNormal_;
    65             float               planeOffset_;
     61            Vector3 normal_;
     62            float   offset_;
    6663     };
    6764}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.cc

    r2374 r2403  
    4444        RegisterObject(SphereCollisionShape);
    4545
    46         this->sphereShape_ = new btSphereShape(1.0f);
    47         this->collisionShape_ = this->sphereShape_;
     46        this->radius_ = 1.0f;
     47        updateSphere();
    4848
    4949        this->registerVariables();
     
    5858    void SphereCollisionShape::registerVariables()
    5959    {
    60         REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::radiusChanged));
     60        REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::updateSphere));
    6161    }
    6262
     
    6868    }
    6969
    70     void SphereCollisionShape::setRadius(float radius)
     70    void SphereCollisionShape::updateSphere()
    7171    {
    72         // TODO: Think about where this could be referenced already.
    73         this->radius_ = radius;
    74         delete this->sphereShape_;
    75         this->sphereShape_ = new btSphereShape(radius);
     72        if (this->collisionShape_)
     73            delete this->collisionShape_;
     74        this->collisionShape_ = new btSphereShape(this->radius_);
    7675    }
    7776}
  • code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.h

    r2374 r2403  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646
    47             void setRadius(float radius);
     47            inline void setRadius(float radius)
     48                { this->radius_ = radius; updateSphere(); }
    4849            inline float getRadius() const
    4950                { return this->radius_;}
    5051
    51             inline void radiusChanged()
    52                 { this->setRadius(this->radius_); }
     52            void updateSphere();
    5353
    5454        private:
    55             btSphereShape* sphereShape_;
    56             float          radius_;
     55            float radius_;
    5756    };
    5857}
Note: See TracChangeset for help on using the changeset viewer.