Changeset 2313 for code/branches/physics/src/orxonox/objects/Scene.cc
- Timestamp:
- Dec 3, 2008, 1:17:12 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/Scene.cc
r2306 r2313 125 125 126 126 XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 127 128 // finally add all rigid bodies to the physics engine129 if (hasPhysics())130 {131 for (std::list<BaseObject*>::const_iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)132 {133 WorldEntity* temp = dynamic_cast<WorldEntity*>(*it);134 if (temp)135 {136 if (temp->getCollisionType() != WorldEntity::None)137 this->physicalWorld_->addRigidBody(temp->getPhysicalBody());138 }139 }140 }141 127 } 142 128 … … 172 158 void Scene::tick(float dt) 173 159 { 174 // TODO: This is not stable! If physics cannot be calculated real time anymore,175 // framerate will drop exponentially.176 160 if (physicalWorld_) 161 { 162 if (this->physicsQueue_.size() > 0) 163 { 164 // Add all scheduled WorldEntities 165 for (std::set<btRigidBody*>::const_iterator it = this->physicsQueue_.begin(); 166 it != this->physicsQueue_.end(); ++it) 167 { 168 if (!(*it)->isInWorld()) 169 this->physicalWorld_->addRigidBody(*it); 170 } 171 this->physicsQueue_.clear(); 172 } 173 174 // TODO: This is not stable! If physics cannot be calculated real time anymore, 175 // framerate will drop exponentially. 177 176 physicalWorld_->stepSimulation(dt,(int)(dt/0.0166666f + 1.0f)); 177 } 178 178 } 179 179 … … 224 224 return 0; 225 225 } 226 227 void Scene::addRigidBody(btRigidBody* body) 228 { 229 if (!this->physicalWorld_) 230 COUT(1) << "Error: Cannot WorldEntity body to physical Scene: No physics." << std::endl; 231 else if (body) 232 this->physicsQueue_.insert(body); 233 } 234 235 void Scene::removeRigidBody(btRigidBody* body) 236 { 237 if (!this->physicalWorld_) 238 COUT(1) << "Error: Cannot WorldEntity body to physical Scene: No physics." << std::endl; 239 else if (body) 240 { 241 this->physicalWorld_->removeRigidBody(body); 242 // Also check queue 243 std::set<btRigidBody*>::iterator it = this->physicsQueue_.find(body); 244 if (it != this->physicsQueue_.end()) 245 this->physicsQueue_.erase(it); 246 } 247 } 226 248 }
Note: See TracChangeset
for help on using the changeset viewer.