Changeset 2429
- Timestamp:
- Dec 13, 2008, 11:18:44 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/collisionshapes/CollisionShape.cc
r2423 r2429 67 67 XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 68 68 XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); 69 XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 70 XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode); 69 71 XMLPortParamLoadOnly(CollisionShape, "yaw", yaw, xmlelement, mode); 70 72 XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode); 71 73 XMLPortParamLoadOnly(CollisionShape, "roll", roll, xmlelement, mode); 72 XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);73 XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode);74 74 } 75 75 -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2426 r2429 72 72 this->bPhysicsActive_ = false; 73 73 this->collisionShape_ = new CompoundCollisionShape(this); 74 this->mass_ = 0;75 this->childrenMass_ = 0;76 74 this->collisionType_ = None; 77 75 this->collisionTypeSynchronised_ = None; 76 this->mass_ = 0; 77 this->childrenMass_ = 0; 78 // Use bullet default values 79 this->restitution_ = 0; 80 this->angularFactor_ = 1; 81 this->linearDamping_ = 0; 82 this->angularDamping_ = 0; 83 this->friction_ = 0.5; 78 84 79 85 this->registerVariables(); … … 103 109 SUPER(WorldEntity, XMLPort, xmlelement, mode); 104 110 105 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition,xmlelement, mode, const Vector3&);111 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 106 112 XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); 107 XMLPortParam LoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode);108 XMLPortParam LoadOnly(WorldEntity, "direction", setDirection_xmlport,xmlelement, mode);109 XMLPortParamLoadOnly(WorldEntity, " yaw", yaw_xmlport,xmlelement, mode);110 XMLPortParamLoadOnly(WorldEntity, " pitch", pitch_xmlport, xmlelement, mode);111 XMLPortParamLoadOnly(WorldEntity, " roll", roll_xmlport,xmlelement, mode);112 XMLPortParam Template(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);113 XMLPortParam (WorldEntity, "scale", setScale, getScale,xmlelement, mode);113 XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 114 XMLPortParam (WorldEntity, "scale", setScale, getScale, xmlelement, mode); 115 XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode); 116 XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode); 117 XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode); 118 XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode); 119 XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode); 114 120 115 121 // Physics 116 XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode); 117 XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode); 122 XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode); 123 XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode); 124 XMLPortParam(WorldEntity, "restitution", setRestitution, getRestitution, xmlelement, mode); 125 XMLPortParam(WorldEntity, "angularFactor", setAngularFactor, getAngularFactor, xmlelement, mode); 126 XMLPortParam(WorldEntity, "linearDamping", setLinearDamping, getLinearDamping, xmlelement, mode); 127 XMLPortParam(WorldEntity, "angularDamping", setAngularDamping, getAngularDamping, xmlelement, mode); 128 XMLPortParam(WorldEntity, "friction", setFriction, getFriction, xmlelement, mode); 118 129 119 130 // Other attached WorldEntities … … 125 136 void WorldEntity::registerVariables() 126 137 { 127 REGISTERDATA(this->bActive_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));128 REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));129 130 REGISTERDATA(this->getScale3D(), network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));138 REGISTERDATA(this->bActive_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 139 REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); 140 141 REGISTERDATA(this->getScale3D(), network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged)); 131 142 132 143 REGISTERDATA((int&)this->collisionTypeSynchronised_, 133 network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged)); 134 REGISTERDATA(this->mass_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged)); 144 network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged)); 145 REGISTERDATA(this->mass_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged)); 146 REGISTERDATA(this->restitution_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::restitutionChanged)); 147 REGISTERDATA(this->angularFactor_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::angularFactorChanged)); 148 REGISTERDATA(this->linearDamping_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::linearDampingChanged)); 149 REGISTERDATA(this->angularDamping_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged)); 150 REGISTERDATA(this->friction_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged)); 135 151 REGISTERDATA(this->bPhysicsActiveSynchronised_, 136 network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged));137 138 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent));139 } 140 141 void WorldEntity:: updateParent()152 network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged)); 153 154 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::parentChanged)); 155 } 156 157 void WorldEntity::parentChanged() 142 158 { 143 159 WorldEntity* parent = dynamic_cast<WorldEntity*>(Synchronisable::getSynchronisable(this->parentID_)); … … 162 178 this->setCollisionType(this->collisionTypeSynchronised_); 163 179 } 164 }165 166 void WorldEntity::massChanged()167 {168 this->setMass(this->mass_);169 180 } 170 181 … … 214 225 // mass 215 226 this->childrenMass_ += object->getMass(); 216 recalculate PhysicsProps();227 recalculateMassProps(); 217 228 } 218 229 … … 225 236 { 226 237 this->childrenMass_ -= object->getMass(); 227 recalculate PhysicsProps();238 recalculateMassProps(); 228 239 } 229 240 … … 418 429 } 419 430 420 void WorldEntity::setMass(float mass)421 {422 this->mass_ = mass;423 recalculatePhysicsProps();424 }425 426 431 void WorldEntity::setCollisionType(CollisionType type) 427 432 { … … 430 435 ThrowException(PhysicsViolation, "Cannot set the collision type of a WorldEntity with a parent"); 431 436 else if (this->addedToPhysicalWorld()) 432 ThrowException(PhysicsViolation, " Warning:Cannot set the collision type at run time.");437 ThrowException(PhysicsViolation, "Cannot set the collision type at run time."); 433 438 434 439 // Check for type legality. Could be StaticEntity or MobileEntity 435 440 if (!this->isCollisionTypeLegal(type)) 436 441 return; // exception gets issued anyway 442 if (type != None && !this->getScene()->hasPhysics()) 443 ThrowException(PhysicsViolation, "Cannot have physical bodies in a non physical scene"); 437 444 438 445 // Check whether we have to create or destroy. … … 444 451 445 452 // Create new rigid body 446 btCollisionShape* temp = 0;447 453 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape()); 448 bodyConstructionInfo.m_restitution = 1;449 454 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 450 455 this->physicalBody_->setUserPointer(this); … … 485 490 486 491 // update mass and inertia tensor 487 recalculatePhysicsProps(); 492 recalculateMassProps(); 493 resetPhysicsProps(); 488 494 activatePhysics(); 489 495 } … … 544 550 for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it) 545 551 this->childrenMass_ += (*it)->getMass(); 546 recalculate PhysicsProps();552 recalculateMassProps(); 547 553 // Notify parent WE 548 554 if (this->parent_) … … 564 570 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 565 571 } 566 recalculate PhysicsProps();567 } 568 569 void WorldEntity::recalculate PhysicsProps()572 recalculateMassProps(); 573 } 574 575 void WorldEntity::recalculateMassProps() 570 576 { 571 577 if (this->hasPhysics()) … … 589 595 } 590 596 } 597 598 void WorldEntity::resetPhysicsProps() 599 { 600 if (this->hasPhysics()) 601 { 602 this->physicalBody_->setRestitution(this->restitution_); 603 this->physicalBody_->setAngularFactor(this->angularFactor_); 604 this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_); 605 this->physicalBody_->setFriction(this->friction_); 606 } 607 } 591 608 } -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h
r2426 r2429 141 141 142 142 private: 143 void updateParent();144 145 143 inline void lookAt_xmlport(const Vector3& target) 146 144 { this->lookAt(target); } … … 154 152 { this->roll(angle); } 155 153 154 // network callbacks 155 void parentChanged(); 156 156 inline void scaleChanged() 157 157 { this->setScale3D(this->getScale3D()); } … … 192 192 std::string getCollisionTypeStr() const; 193 193 194 void setMass(float mass); 194 inline void setMass(float mass) 195 { this->mass_ = mass; recalculateMassProps(); } 195 196 inline float getMass() const 196 197 { return this->mass_; } 198 197 199 inline float getTotalMass() const 198 200 { return this->mass_ + this->childrenMass_; } 201 202 inline void setRestitution(float restitution) 203 { this->restitution_ = restitution; resetPhysicsProps(); } 204 inline float getRestitution() const 205 { return this->restitution_; } 206 207 inline void setAngularFactor(float angularFactor) 208 { this->angularFactor_ = angularFactor; resetPhysicsProps(); } 209 inline float getAngularFactor() const 210 { return this->angularFactor_; } 211 212 inline void setLinearDamping(float linearDamping) 213 { this->linearDamping_ = linearDamping; resetPhysicsProps(); } 214 inline float getLinearDamping() const 215 { return this->linearDamping_; } 216 217 inline void setAngularDamping(float angularDamping) 218 { this->angularDamping_ = angularDamping; resetPhysicsProps(); } 219 inline float getAngularDamping() const 220 { return this->angularDamping_; } 221 222 inline void setFriction(float friction) 223 { this->friction_ = friction; resetPhysicsProps(); } 224 inline float getFriction() const 225 { return this->friction_; } 199 226 200 227 void attachCollisionShape(CollisionShape* shape); … … 217 244 private: 218 245 void updateCollisionType(); 219 void recalculatePhysicsProps(); 246 void recalculateMassProps(); 247 void resetPhysicsProps(); 220 248 221 249 // network callbacks 222 250 void collisionTypeChanged(); 223 void massChanged();224 251 void physicsActivityChanged(); 252 inline void massChanged() 253 { this->setMass(this->mass_); } 254 inline void restitutionChanged() 255 { this->setRestitution(this->restitution_); } 256 inline void angularFactorChanged() 257 { this->setAngularFactor(this->angularFactor_); } 258 inline void linearDampingChanged() 259 { this->setLinearDamping(this->linearDamping_); } 260 inline void angularDampingChanged() 261 { this->setAngularDamping(this->angularDamping_); } 262 inline void frictionChanged() 263 { this->setFriction(this->friction_); } 225 264 226 265 CollisionType collisionType_; … … 230 269 CompoundCollisionShape* collisionShape_; 231 270 btScalar mass_; 271 btScalar restitution_; 272 btScalar angularFactor_; 273 btScalar linearDamping_; 274 btScalar angularDamping_; 275 btScalar friction_; 232 276 btScalar childrenMass_; 233 277 };
Note: See TracChangeset
for help on using the changeset viewer.