Changeset 2403
- Timestamp:
- Dec 10, 2008, 11:33:58 PM (16 years ago)
- 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 52 52 this->parentID_ = (unsigned int)-1; 53 53 this->collisionShape_ = 0; 54 this->position_ = Vector3::ZERO; 55 this->orientation_ = Quaternion::IDENTITY; 56 this->scale_ = Vector3::UNIT_SCALE; 54 57 } 55 58 -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.cc
r2374 r2403 44 44 RegisterObject(CompoundCollisionShape); 45 45 46 this->collisionShape_ = 0;47 46 this->compoundShape_ = new btCompoundShape(); 48 47 } … … 67 66 if (this->collisionShape_) 68 67 return this->collisionShape_; 69 else if ( this->childShapes_.size() != 0)68 else if (!this->empty()) 70 69 return this->compoundShape_; 71 70 else … … 75 74 void CompoundCollisionShape::addChildShape(CollisionShape* shape) 76 75 { 77 if (!shape || !shape->getCollisionShape())76 if (!shape) 78 77 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); 82 79 83 if ( this->childShapes_.size() == 1 && this->childShapes_[0] && !this->childShapes_[0]->hasTransform())80 if (shape->getCollisionShape()) 84 81 { 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 } 92 96 } 93 97 -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.h
r2374 r2403 50 50 virtual btCollisionShape* getCollisionShape() const; 51 51 52 inline bool empty() const 53 { return this->childShapes_.size() == 0; } 54 52 55 private: 53 btCompoundShape* compoundShape_;56 btCompoundShape* compoundShape_; 54 57 std::vector<CollisionShape*> childShapes_; 55 58 }; -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.cc
- Property svn:eol-style set to native
r2374 r2403 42 42 RegisterObject(PlaneCollisionShape); 43 43 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(); 48 49 } 49 50 … … 51 52 { 52 53 if (this->isInitialized()) 53 delete this-> planeShape_;54 delete this->collisionShape_; 54 55 } 55 56 56 57 void PlaneCollisionShape::registerVariables() 57 58 { 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)); 60 61 } 61 62 … … 64 65 SUPER(PlaneCollisionShape, XMLPort, xmlelement, mode); 65 66 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); 68 69 } 69 70 70 void PlaneCollisionShape:: setNormal(const Vector3& normal)71 void PlaneCollisionShape::updatePlane() 71 72 { 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_); 84 76 } 85 77 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.h
- Property svn:eol-style set to native
r2374 r2403 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 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(); } 48 55 inline float getOffset() 49 { return this->planeShape_->getPlaneConstant();} 50 void setOffset(float offset); 56 { return this->offset_;} 51 57 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(); 61 59 62 60 private: 63 btStaticPlaneShape* planeShape_; 64 Vector3 planeNormal_; 65 float planeOffset_; 61 Vector3 normal_; 62 float offset_; 66 63 }; 67 64 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.cc
r2374 r2403 44 44 RegisterObject(SphereCollisionShape); 45 45 46 this-> sphereShape_ = new btSphereShape(1.0f);47 this->collisionShape_ = this->sphereShape_;46 this->radius_ = 1.0f; 47 updateSphere(); 48 48 49 49 this->registerVariables(); … … 58 58 void SphereCollisionShape::registerVariables() 59 59 { 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)); 61 61 } 62 62 … … 68 68 } 69 69 70 void SphereCollisionShape:: setRadius(float radius)70 void SphereCollisionShape::updateSphere() 71 71 { 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_); 76 75 } 77 76 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.h
r2374 r2403 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 47 void setRadius(float radius); 47 inline void setRadius(float radius) 48 { this->radius_ = radius; updateSphere(); } 48 49 inline float getRadius() const 49 50 { return this->radius_;} 50 51 51 inline void radiusChanged() 52 { this->setRadius(this->radius_); } 52 void updateSphere(); 53 53 54 54 private: 55 btSphereShape* sphereShape_; 56 float radius_; 55 float radius_; 57 56 }; 58 57 }
Note: See TracChangeset
for help on using the changeset viewer.