- Timestamp:
- Dec 13, 2008, 11:18:44 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.