void MScene::preparePhysics(void) { MPhysicsContext * physics = MEngine::getInstance()->getPhysicsContext(); if(! physics) return; physics->init(MVector3(-10000), MVector3(10000)); physics->setWorldGravity(m_gravity); // create shapes unsigned int i; unsigned int size = getEntitiesNumber(); for(i=0; i<size; i++) { MOEntity * entity = getEntityByIndex(i); prepareCollisionShape(entity); } // create objects for(i=0; i<size; i++) { MOEntity * entity = getEntityByIndex(i); prepareCollisionObject(entity); } // create constraints for(i=0; i<size; i++) { MOEntity * entity = getEntityByIndex(i); prepareConstraints(entity); } }
void ResourceManager::addEntityByIndex(int px, int py, int ID) { Entity* ent = getEntityByIndex(ID); if( ent != NULL) { map->setEntity(px, py, *ent); } }
void MScene::updatePhysics(void) { MPhysicsContext * physics = MEngine::getInstance()->getPhysicsContext(); if(! physics) return; unsigned int i; unsigned int size = getEntitiesNumber(); for(i=0; i<size; i++) { MOEntity * entity = getEntityByIndex(i); if(! entity->isActive()) continue; MPhysicsProperties * phyProps = entity->getPhysicsProperties(); if(! phyProps) continue; if(phyProps->getCollisionObjectId() > 0) { MObject3d * parent = entity->getParent(); if(parent && phyProps->isGhost()) { MVector3 euler = entity->getTransformedRotation(); physics->setObjectTransform( phyProps->getCollisionObjectId(), entity->getTransformedPosition(), MQuaternion(euler.x, euler.y, euler.z) ); } else if(entity->needToUpdate()) { physics->setObjectTransform( phyProps->getCollisionObjectId(), entity->getPosition(), entity->getRotation() ); } } } physics->setWorldGravity(m_gravity); physics->updateSimulation(); for(i=0; i<size; i++) { MOEntity * entity = getEntityByIndex(i); if(! entity->isActive()) continue; MPhysicsProperties * phyProps = entity->getPhysicsProperties(); if(phyProps) { if((phyProps->getCollisionObjectId() > 0) && (! phyProps->isGhost())) { MVector3 position = entity->getPosition(); MQuaternion rotation = entity->getRotation(); physics->getObjectTransform(phyProps->getCollisionObjectId(), &position, &rotation); entity->setPosition(position); entity->setRotation(rotation); } } } }