- Timestamp:
- Dec 10, 2008, 1:38:17 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects/worldentities/collisionshapes
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.cc
r2306 r2374 37 37 #include "tools/BulletConversions.h" 38 38 39 #include "CompoundCollisionShape.h" 40 39 41 namespace orxonox 40 42 { 41 43 CreateFactory(CollisionShape); 42 44 43 CollisionShape::CollisionShape(BaseObject* creator) : StaticEntity(creator) 45 CollisionShape::CollisionShape(BaseObject* creator) 46 : BaseObject(creator) 47 , network::Synchronisable(creator) 44 48 { 45 49 RegisterObject(CollisionShape); 46 50 47 this->bIsCompound_ = false; 51 this->parent_ = 0; 52 this->parentID_ = (unsigned int)-1; 53 this->collisionShape_ = 0; 48 54 } 49 55 … … 55 61 { 56 62 SUPER(CollisionShape, XMLPort, xmlelement, mode); 63 64 XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 65 XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); 66 XMLPortParamLoadOnly(CollisionShape, "yaw", yaw, xmlelement, mode); 67 XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode); 68 XMLPortParamLoadOnly(CollisionShape, "roll", roll, xmlelement, mode); 69 XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 70 XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode); 57 71 } 58 72 59 bool CollisionShape::isCollisionTypeLegal(WorldEntity::CollisionType type) const73 void CollisionShape::registerVariables() 60 74 { 61 if (type != WorldEntity::None) 62 { 63 ThrowException(PhysicsViolation, "A CollisionShape can only have CollisionType 'None'."); 64 return false; 65 } 66 else 67 return true; 75 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<CollisionShape>(this, &CollisionShape::updateParent)); 68 76 } 69 77 70 bool CollisionShape::hasNoTransform() const78 void CollisionShape::updateParent() 71 79 { 72 return (this->getPosition().positionEquals(Vector3(0, 0, 0), 0.001) && 73 this->getOrientation().equals(Quaternion(1,0,0,0), Degree(0.1))); 80 CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_)); 81 if (parent) 82 parent->addChildShape(this); 74 83 } 75 84 76 b tVector3 CollisionShape::getTotalScaling()85 bool CollisionShape::hasTransform() const 77 86 { 78 return omni_cast<btVector3>(this->node_->getScale()); 87 return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) || 88 !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1))); 79 89 } 80 90 … … 84 94 } 85 95 86 void CollisionShape::s cale3D(const Vector3&scale)96 void CollisionShape::setScale(float scale) 87 97 { 88 98 ThrowException(NotImplemented, "Cannot set the scale of a collision shape: Not yet implemented."); -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.h
r2306 r2374 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/StaticEntity.h" 34 #include "util/Math.h" 35 #include "core/BaseObject.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport CollisionShape : public StaticEntity39 class _OrxonoxExport CollisionShape : public BaseObject, public network::Synchronisable 39 40 { 40 41 public: … … 43 44 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 void registerVariables(); 45 47 46 btCollisionShape* getCollisionShape() const { return this->collisionShape_; } 47 bool isCompoundShape() const { return this->bIsCompound_; } 48 inline void setPosition(const Vector3& position) 49 { this->position_ = position; } 50 inline const Vector3& getPosition() const 51 { return this->position_; } 48 52 49 bool hasNoTransform() const; 50 virtual btVector3 getTotalScaling(); 53 inline void setOrientation(const Quaternion& orientation) 54 { this->orientation_ = orientation; } 55 inline const Quaternion& getOrientation() const 56 { return this->orientation_; } 57 58 void yaw(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Y); } 59 void pitch(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_X); } 60 void roll(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Z); } 61 62 virtual void setScale3D(const Vector3& scale); 63 virtual void setScale(float scale); 64 inline const Vector3& getScale3D(void) const 65 { return this->scale_; } 66 67 virtual inline btCollisionShape* getCollisionShape() const 68 { return this->collisionShape_; } 69 70 bool hasTransform() const; 71 72 inline void setParent(CompoundCollisionShape* shape, unsigned int ID) 73 { this->parent_ = shape; this->parentID_ = ID; } 51 74 52 75 protected: 53 bool bIsCompound_;54 76 btCollisionShape* collisionShape_; 55 77 56 78 private: 57 virtual void setScale3D(const Vector3& scale); 58 virtual void scale3D(const Vector3& scale); 79 void updateParent(); 59 80 60 bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 81 Vector3 position_; 82 Quaternion orientation_; 83 Vector3 scale_; 84 CompoundCollisionShape* parent_; 85 unsigned int parentID_; 61 86 }; 62 87 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.cc
r2304 r2374 44 44 RegisterObject(CompoundCollisionShape); 45 45 46 this-> bIsCompound_ = true;46 this->collisionShape_ = 0; 47 47 this->compoundShape_ = new btCompoundShape(); 48 this->collisionShape_ = this->compoundShape_;49 48 } 50 49 … … 58 57 { 59 58 SUPER(CompoundCollisionShape, XMLPort, xmlelement, mode); 59 // Attached collision shapes 60 XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode); 61 } 60 62 61 XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode); 63 btCollisionShape* CompoundCollisionShape::getCollisionShape() const 64 { 65 // Note: Returning collisionShape_ means that it's the only one and has no transform. 66 // So we can get rid of the additional overhead with the compound shape. 67 if (this->collisionShape_) 68 return this->collisionShape_; 69 else if (this->childShapes_.size() != 0) 70 return this->compoundShape_; 71 else 72 return 0; 62 73 } 63 74 64 75 void CompoundCollisionShape::addChildShape(CollisionShape* shape) 65 76 { 66 this->childShapes_.push_back(shape); 77 if (!shape || !shape->getCollisionShape()) 78 return; 79 assert(this->compoundShape_); 67 80 btTransform transf(omni_cast<btQuaternion>(shape->getOrientation()), omni_cast<btVector3>(shape->getPosition())); 68 shape->getCollisionShape()->setLocalScaling(shape->getTotalScaling());69 81 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 82 83 if (this->childShapes_.size() == 1 && this->childShapes_[0] && !this->childShapes_[0]->hasTransform()) 84 { 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; 92 } 93 94 // network synchro 95 shape->setParent(this, this->getObjectID()); 70 96 } 71 97 -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.h
r2304 r2374 48 48 CollisionShape* getChildShape(unsigned int index) const; 49 49 50 virtual btCollisionShape* getCollisionShape() const; 51 50 52 private: 51 53 btCompoundShape* compoundShape_; -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.cc
r2323 r2374 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Martin Stypinski 24 24 * Co-authors: 25 25 * ... … … 30 30 #include "PlaneCollisionShape.h" 31 31 32 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"33 34 #include "tools/BulletConversions.h"35 32 #include "core/CoreIncludes.h" 36 33 #include "core/XMLPort.h" … … 45 42 RegisterObject(PlaneCollisionShape); 46 43 47 this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1,1), 0);44 this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1, 1), 0); 48 45 this->collisionShape_ = this->planeShape_; 46 this->planeNormal_ = Vector3(1, 1, 1); 47 this->planeOffset_ = 0.0f; 49 48 } 50 49 … … 52 51 { 53 52 if (this->isInitialized()) 54 delete this-> collisionShape_;53 delete this->planeShape_; 55 54 } 56 55 57 void PlaneCollisionShape:: setNormal(const Vector3& normal)56 void PlaneCollisionShape::registerVariables() 58 57 { 59 btScalar offset = this->planeShape_->getPlaneConstant(); 60 delete this->collisionShape_; 61 this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), offset); 62 this->collisionShape_ = this->planeShape_; 63 } 64 65 void PlaneCollisionShape::setOffset(float offset) 66 { 67 btVector3 normal = this->planeShape_->getPlaneNormal(); 68 delete this->collisionShape_; 69 this->planeShape_ = new btStaticPlaneShape(normal, offset); 70 this->collisionShape_ = this ->planeShape_; 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)); 71 60 } 72 61 … … 75 64 SUPER(PlaneCollisionShape, XMLPort, xmlelement, mode); 76 65 77 XMLPortParam(PlaneCollisionShape, " normal", setNormal, getNormal, xmlelement, mode);78 XMLPortParam(PlaneCollisionShape, " offset", setOffset, getOffset, xmlelement, mode);66 XMLPortParam(PlaneCollisionShape, "planeNormal", setNormal, getNormal, xmlelement, mode); 67 XMLPortParam(PlaneCollisionShape, "planeOffset", setOffset, getOffset, xmlelement, mode); 79 68 } 80 69 81 btVector3 PlaneCollisionShape::getTotalScaling()70 void PlaneCollisionShape::setNormal(const Vector3& normal) 82 71 { 83 return omni_cast<btVector3>(this->node_->getScale()); //* this->radius_; 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_; 84 84 } 85 85 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.h
r2323 r2374 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Martin Stypinski 24 24 * Co-authors: 25 25 * ... … … 33 33 34 34 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 35 36 35 #include "CollisionShape.h" 37 36 … … 44 43 virtual ~PlaneCollisionShape(); 45 44 45 void registerVariables(); 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 49 50 48 inline float getOffset() 51 49 { return this->planeShape_->getPlaneConstant();} 50 void setOffset(float offset); 52 51 53 52 inline btVector3 getNormal() 54 53 { return this->planeShape_->getPlaneNormal();} 55 void setOffset(float offset);56 54 void setNormal(const Vector3& normal); 57 55 58 private:59 virtual btVector3 getTotalScaling();56 inline void planeNormalChanged() 57 { this->setNormal(this->planeNormal_); } 60 58 59 inline void planeOffsetChanged() 60 { this->setOffset(this->planeOffset_); } 61 62 private: 61 63 btStaticPlaneShape* planeShape_; 64 Vector3 planeNormal_; 65 float planeOffset_; 62 66 }; 63 67 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.cc
r2304 r2374 46 46 this->sphereShape_ = new btSphereShape(1.0f); 47 47 this->collisionShape_ = this->sphereShape_; 48 49 this->registerVariables(); 48 50 } 49 51 … … 52 54 if (this->isInitialized()) 53 55 delete this->collisionShape_; 56 } 57 58 void SphereCollisionShape::registerVariables() 59 { 60 REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::radiusChanged)); 54 61 } 55 62 … … 61 68 } 62 69 63 btVector3 SphereCollisionShape::getTotalScaling()70 void SphereCollisionShape::setRadius(float radius) 64 71 { 65 return omni_cast<btVector3>(this->node_->getScale()) * this->radius_; 72 // TODO: Think about where this could be referenced already. 73 this->radius_ = radius; 74 delete this->sphereShape_; 75 this->sphereShape_ = new btSphereShape(radius); 66 76 } 67 77 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.h
r2304 r2374 42 42 virtual ~SphereCollisionShape(); 43 43 44 void registerVariables(); 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 46 46 inline void setRadius(float radius) 47 { this->radius_ = radius; } 47 void setRadius(float radius); 48 48 inline float getRadius() const 49 49 { return this->radius_;} 50 50 51 inline void radiusChanged() 52 { this->setRadius(this->radius_); } 53 51 54 private: 52 virtual btVector3 getTotalScaling();53 54 55 btSphereShape* sphereShape_; 55 56 float radius_;
Note: See TracChangeset
for help on using the changeset viewer.