Changeset 2514 for code/branches
- Timestamp:
- Dec 21, 2008, 2:44:00 PM (16 years ago)
- Location:
- code/branches/presentation/src/orxonox/objects/collisionshapes
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/objects/collisionshapes/BoxCollisionShape.cc
r2486 r2514 45 45 46 46 this->halfExtents_ = Vector3(1, 1, 1); 47 update Box();47 updateShape(); 48 48 49 49 this->registerVariables(); … … 58 58 void BoxCollisionShape::registerVariables() 59 59 { 60 registerVariable(this->halfExtents_, variableDirection::toclient, new NetworkCallback< BoxCollisionShape>(this, &BoxCollisionShape::updateBox));60 registerVariable(this->halfExtents_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 61 61 } 62 62 … … 71 71 } 72 72 73 void BoxCollisionShape::updateBox()73 btCollisionShape* BoxCollisionShape::createNewShape() const 74 74 { 75 if (this->collisionShape_) 76 delete this->collisionShape_; 77 this->collisionShape_ = new btBoxShape(omni_cast<btVector3>(this->halfExtents_)); 78 this->updateParent(); 75 return new btBoxShape(omni_cast<btVector3>(this->halfExtents_)); 79 76 } 80 77 } -
code/branches/presentation/src/orxonox/objects/collisionshapes/BoxCollisionShape.h
r2486 r2514 46 46 47 47 inline void setHalfExtents(const Vector3& extents) 48 { this->halfExtents_ = extents; update Box(); }48 { this->halfExtents_ = extents; updateShape(); } 49 49 inline const Vector3& getHalfExtents() const 50 50 { return halfExtents_;} 51 51 52 52 inline void setWidth(float value) 53 { this->halfExtents_.z = value / 2; update Box(); }53 { this->halfExtents_.z = value / 2; updateShape(); } 54 54 inline float getWidth() const 55 55 { return this->halfExtents_.z * 2; } 56 56 57 57 inline void setHeight(float value) 58 { this->halfExtents_.y = value / 2; update Box(); }58 { this->halfExtents_.y = value / 2; updateShape(); } 59 59 inline float getHeight() const 60 60 { return this->halfExtents_.y * 2; } 61 61 62 62 inline void setLength(float value) 63 { this->halfExtents_.x = value / 2; update Box(); }63 { this->halfExtents_.x = value / 2; updateShape(); } 64 64 inline float getLength() const 65 65 { return this->halfExtents_.x * 2; } 66 66 67 void updateBox(); 67 private: 68 btCollisionShape* createNewShape() const; 68 69 69 private:70 70 Vector3 halfExtents_; 71 71 }; -
code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc
r2469 r2514 42 42 namespace orxonox 43 43 { 44 CreateFactory(CollisionShape);45 46 44 CollisionShape::CollisionShape(BaseObject* creator) 47 45 : BaseObject(creator) … … 62 60 CollisionShape::~CollisionShape() 63 61 { 62 // Detach from parent 63 if (this->isInitialized() && this->parent_) 64 this->parent_->removeChildShape(this); 64 65 } 65 66 … … 79 80 void CollisionShape::registerVariables() 80 81 { 81 registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged ));82 registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChangedCallback)); 82 83 } 83 84 84 85 void CollisionShape::parentChanged() 85 86 { 86 Synchronisable* synchronisable = Synchronisable::getSynchronisable(this->parentID_); 87 CompoundCollisionShape* CCSparent = dynamic_cast<CompoundCollisionShape*>(synchronisable); 88 if (CCSparent) 89 CCSparent->addChildShape(this); 90 else 91 { 92 WorldEntity* WEparent = dynamic_cast<WorldEntity*>(synchronisable); 93 if (WEparent) 94 WEparent->attachCollisionShape(this); 95 } 87 CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_)); 88 if (parent) 89 parent->addChildShape(this); 96 90 } 97 91 … … 118 112 } 119 113 114 void CollisionShape::updateShape() 115 { 116 btCollisionShape* oldShape = this->collisionShape_; 117 this->collisionShape_ = this->createNewShape(); 118 // When we recreate the shape, we have to inform the parent about this to update the shape 119 this->updateParent(); 120 if (oldShape) 121 delete oldShape; 122 } 123 120 124 void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const 121 125 { -
code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.h
r2459 r2514 66 66 { return this->scale_; } 67 67 68 void updateShape(); 69 68 70 void calculateLocalInertia(float mass, btVector3& inertia) const; 69 71 … … 78 80 protected: 79 81 virtual void updateParent(); 82 virtual void parentChanged(); 83 // Note: This is required because the NetworkCallback will not call functions virtually 84 void parentChangedCallback() { this->parentChanged(); } 85 virtual btCollisionShape* createNewShape() const = 0; 80 86 81 87 btCollisionShape* collisionShape_; … … 83 89 84 90 private: 85 void parentChanged();86 87 91 Vector3 position_; 88 92 Quaternion orientation_; -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.cc
r2484 r2514 54 54 if (this->isInitialized()) 55 55 { 56 // Notify children about removal56 // Delete all children 57 57 for (std::map<CollisionShape*, btCollisionShape*>::iterator it = this->childShapes_.begin(); 58 58 it != this->childShapes_.end(); ++it) 59 59 { 60 // make sure that the child doesn't want to detach itself --> speedup because of the missing update 60 61 it->first->setParent(0, OBJECTID_UNKNOWN); 62 delete it->first; 61 63 } 62 64 … … 197 199 if (this->parent_) 198 200 this->parent_->updateChildShape(this); 199 elseif (this->worldEntityParent_)201 if (this->worldEntityParent_) 200 202 this->worldEntityParent_->notifyCollisionShapeChanged(); 203 } 204 205 void CompoundCollisionShape::parentChanged() 206 { 207 if (!this->worldEntityParent_) 208 CollisionShape::parentChanged(); 201 209 } 202 210 -
code/branches/presentation/src/orxonox/objects/collisionshapes/CompoundCollisionShape.h
r2469 r2514 33 33 34 34 #include <vector> 35 #include <cassert> 35 36 #include "CollisionShape.h" 36 37 … … 59 60 private: 60 61 void updatePublicShape(); 62 void parentChanged(); 63 inline virtual btCollisionShape* createNewShape() const 64 { assert(false); return 0; } 61 65 62 66 btCompoundShape* compoundShape_; -
code/branches/presentation/src/orxonox/objects/collisionshapes/ConeCollisionShape.cc
r2486 r2514 46 46 this->radius_ = 1.0f; 47 47 this->height_ = 1.0f; 48 update Cone();48 updateShape(); 49 49 50 50 this->registerVariables(); … … 59 59 void ConeCollisionShape::registerVariables() 60 60 { 61 registerVariable(this->radius_, variableDirection::toclient, new NetworkCallback<Co neCollisionShape>(this, &ConeCollisionShape::updateCone));62 registerVariable(this->height_, variableDirection::toclient, new NetworkCallback<Co neCollisionShape>(this, &ConeCollisionShape::updateCone));61 registerVariable(this->radius_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 62 registerVariable(this->height_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 63 63 } 64 64 … … 71 71 } 72 72 73 void ConeCollisionShape::updateCone()73 btCollisionShape* ConeCollisionShape::createNewShape() const 74 74 { 75 if (this->collisionShape_) 76 delete this->collisionShape_; 77 this->collisionShape_ = new btConeShape(this->radius_, this->height_); 78 this->updateParent(); 75 return new btConeShape(this->radius_, this->height_); 79 76 } 80 77 } -
code/branches/presentation/src/orxonox/objects/collisionshapes/ConeCollisionShape.h
r2486 r2514 46 46 47 47 inline void setRadius(float value) 48 { this->radius_ = value; update Cone(); }48 { this->radius_ = value; updateShape(); } 49 49 inline float getRadius() const 50 50 { return radius_; } 51 51 52 52 inline void setHeight(float value) 53 { this->height_ = value; update Cone(); }53 { this->height_ = value; updateShape(); } 54 54 inline float getHeight() const 55 55 { return this->height_; } 56 56 57 void updateCone(); 57 private: 58 btCollisionShape* createNewShape() const; 58 59 59 private:60 60 float radius_; 61 61 float height_; -
code/branches/presentation/src/orxonox/objects/collisionshapes/PlaneCollisionShape.cc
r2459 r2514 46 46 this->normal_ = Vector3(0, 1, 0); 47 47 this->offset_ = 0.0f; 48 update Plane();48 updateShape(); 49 49 50 50 this->registerVariables(); … … 59 59 void PlaneCollisionShape::registerVariables() 60 60 { 61 registerVariable(this->normal_, variableDirection::toclient, new NetworkCallback< PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));62 registerVariable(this->offset_, variableDirection::toclient, new NetworkCallback< PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));61 registerVariable(this->normal_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 62 registerVariable(this->offset_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 63 63 } 64 64 … … 71 71 } 72 72 73 void PlaneCollisionShape::updatePlane()73 btCollisionShape* PlaneCollisionShape::createNewShape() const 74 74 { 75 if (this->collisionShape_) 76 delete this->collisionShape_; 77 this->collisionShape_ = new btStaticPlaneShape(omni_cast<btVector3>(this->normal_), this->offset_); 78 this->updateParent(); 75 return new btStaticPlaneShape(omni_cast<btVector3>(this->normal_), this->offset_); 79 76 } 80 77 } -
code/branches/presentation/src/orxonox/objects/collisionshapes/PlaneCollisionShape.h
r2459 r2514 46 46 47 47 inline void setNormal(const Vector3& normal) 48 { this->normal_ = normal; update Plane(); }48 { this->normal_ = normal; updateShape(); } 49 49 inline const Vector3& getNormal() 50 50 { return normal_;} 51 51 52 52 inline void setOffset(float offset) 53 { this->offset_ = offset; update Plane(); }53 { this->offset_ = offset; updateShape(); } 54 54 inline float getOffset() 55 55 { return this->offset_;} 56 56 57 void updatePlane(); 57 private: 58 btCollisionShape* createNewShape()const; 58 59 59 private:60 60 Vector3 normal_; 61 61 float offset_; -
code/branches/presentation/src/orxonox/objects/collisionshapes/SphereCollisionShape.cc
r2459 r2514 45 45 46 46 this->radius_ = 1.0f; 47 updateS phere();47 updateShape(); 48 48 49 49 this->registerVariables(); … … 58 58 void SphereCollisionShape::registerVariables() 59 59 { 60 registerVariable(this->radius_, variableDirection::toclient, new NetworkCallback< SphereCollisionShape>(this, &SphereCollisionShape::updateSphere));60 registerVariable(this->radius_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape)); 61 61 } 62 62 … … 68 68 } 69 69 70 void SphereCollisionShape::updateSphere()70 btCollisionShape* SphereCollisionShape::createNewShape() const 71 71 { 72 if (this->collisionShape_) 73 delete this->collisionShape_; 74 // When we recreate the shape, we have to inform the parent about this to update the shape 75 this->collisionShape_ = new btSphereShape(this->radius_); 76 this->updateParent(); 72 return new btSphereShape(this->radius_); 77 73 } 78 74 } -
code/branches/presentation/src/orxonox/objects/collisionshapes/SphereCollisionShape.h
r2486 r2514 46 46 47 47 inline void setRadius(float radius) 48 { this->radius_ = radius; updateS phere(); }48 { this->radius_ = radius; updateShape(); } 49 49 inline float getRadius() const 50 50 { return this->radius_; } 51 51 52 void updateSphere(); 52 private: 53 btCollisionShape* createNewShape() const; 53 54 54 private:55 55 float radius_; 56 56 };
Note: See TracChangeset
for help on using the changeset viewer.