- Timestamp:
- Nov 12, 2008, 1:44:09 PM (16 years ago)
- Location:
- code/branches/physics
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics
- Property svn:mergeinfo changed
/code/branches/physics (added) merged: 1913,1919-1920,1922-1925,1933,1963-1967,1971-1974,1983-1988,1995,2047
- Property svn:mergeinfo changed
-
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2087 r2192 32 32 #include <cassert> 33 33 #include <OgreSceneManager.h> 34 #include "BulletCollision/CollisionShapes/btSphereShape.h" 34 35 35 36 #include "core/CoreIncludes.h" … … 63 64 this->node_->setOrientation(Quaternion::IDENTITY); 64 65 66 // Default behaviour does not include physics 67 this->bAddedToPhysicalWorld_ = false; 68 this->physicalBody_ = 0; 69 65 70 this->registerVariables(); 66 71 } … … 73 78 if (this->getScene()->getSceneManager()) 74 79 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); 80 81 // Physics is not guaranteed, so check first 82 if (this->physicalBody_) 83 { 84 if (this->bAddedToPhysicalWorld_) 85 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 86 if (this->physicalBody_->getCollisionShape()) 87 delete this->physicalBody_->getCollisionShape(); 88 delete this->physicalBody_; 89 } 75 90 } 76 91 } … … 89 104 XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 90 105 XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode); 106 XMLPortParam(WorldEntity, "collisionRadius", setcollisionRadius, getcollisionRadius, xmlelement, mode); 91 107 92 108 XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode); … … 127 143 object->parent_ = this; 128 144 object->parentID_ = this->getObjectID(); 145 146 // Do the physical connection if required 147 this->attachPhysicalObject(object); 129 148 } 130 149 … … 150 169 return 0; 151 170 } 171 172 void WorldEntity::createPhysicalBody() 173 { 174 // Note: The motion state will be configured in a derived class. 175 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, 0, btVector3(0,0,0)); 176 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 177 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 178 this->bAddedToPhysicalWorld_ = true; 179 } 180 181 void WorldEntity::setcollisionRadius(float radius) 182 { 183 if (!this->physicalBody_) 184 createPhysicalBody(); 185 186 // destroy old onw first 187 btCollisionShape* oldShape = this->physicalBody_->getCollisionShape(); 188 if (oldShape) 189 delete oldShape; 190 191 this->physicalBody_->setCollisionShape(new btSphereShape(btScalar(radius))); 192 } 193 194 float WorldEntity::getcollisionRadius() 195 { 196 if (this->physicalBody_) 197 { 198 btSphereShape* sphere = dynamic_cast<btSphereShape*>(this->physicalBody_->getCollisionShape()); 199 if (sphere) 200 return (float)sphere->getRadius(); 201 } 202 return 0.0f; 203 } 152 204 }
Note: See TracChangeset
for help on using the changeset viewer.