bool PhysicsSystem::toggleCollisionMode() { playerphysics->ps.move_type = (playerphysics->ps.move_type == PM_NOCLIP ? PM_NORMAL : PM_NOCLIP); for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { if (it->first=="player") { OEngine::Physic::PhysicActor* act = it->second; bool cmode = act->getCollisionMode(); if(cmode) { act->enableCollisions(false); mFreeFly = true; return false; } else { mFreeFly = false; act->enableCollisions(true); return true; } } } throw std::logic_error ("can't find player"); }
void PhysicsSystem::addActor (const std::string& handle, const std::string& mesh, const Ogre::Vector3& position) { //TODO:optimize this. Searching the std::map isn't very efficient i think. mEngine->addCharacter(handle); OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle); act->setPosition(btVector3(position.x,position.y,position.z)); }
void PhysicsSystem::doPhysics(float dt, const std::vector<std::pair<std::string, Ogre::Vector3> >& actors) { //set the DebugRenderingMode. To disable it,set it to 0 //eng->setDebugRenderingMode(1); //set the walkdirection to 0 (no movement) for every actor) for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { OEngine::Physic::PhysicActor* act = it->second; act->setWalkDirection(btVector3(0,0,0)); } playerMove::playercmd& pm_ref = playerphysics->cmd; pm_ref.rightmove = 0; pm_ref.forwardmove = 0; pm_ref.upmove = 0; //playerphysics->ps.move_type = PM_NOCLIP; for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin()); iter!=actors.end(); ++iter) { //dirty stuff to get the camera orientation. Must be changed! Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); Ogre::Vector3 dir; Ogre::Node* yawNode = sceneNode->getChildIterator().getNext(); Ogre::Node* pitchNode = yawNode->getChildIterator().getNext(); Ogre::Quaternion yawQuat = yawNode->getOrientation(); Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; Ogre::Quaternion quat = yawNode->getOrientation(); Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); pm_ref.rightmove = -iter->second.x; pm_ref.forwardmove = -iter->second.y; pm_ref.upmove = iter->second.z; } mEngine->stepSimulation(dt); }
void PhysicsSystem::doPhysics(float dt, const std::vector<std::pair<std::string, Ogre::Vector3> >& actors) { //set the DebugRenderingMode. To disable it,set it to 0 //eng->setDebugRenderingMode(1); //set the movement keys to 0 (no movement) for every actor) for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { OEngine::Physic::PhysicActor* act = it->second; act->setMovement(0,0,0); } playerMove::playercmd& pm_ref = playerphysics->cmd; pm_ref.rightmove = 0; pm_ref.forwardmove = 0; pm_ref.upmove = 0; //playerphysics->ps.move_type = PM_NOCLIP; for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin()); iter!=actors.end(); ++iter) { //dirty stuff to get the camera orientation. Must be changed! if (iter->first == "player") { playerphysics->ps.viewangles.x = Ogre::Radian(mPlayerData.pitch).valueDegrees(); playerphysics->ps.viewangles.y = Ogre::Radian(mPlayerData.yaw).valueDegrees() + 90; pm_ref.rightmove = iter->second.x; pm_ref.forwardmove = -iter->second.y; pm_ref.upmove = iter->second.z; } } mEngine->stepSimulation(dt); }
void PhysicsSystem::doPhysics(float dt, const std::vector<std::pair<std::string, Ogre::Vector3> >& actors) { //set the DebugRenderingMode. To disable it,set it to 0 //eng->setDebugRenderingMode(1); //set the walkdirection to 0 (no movement) for every actor) for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) { OEngine::Physic::PhysicActor* act = it->second; act->setWalkDirection(btVector3(0,0,0)); } playerMove::playercmd& pm_ref = playerphysics->cmd; pm_ref.rightmove = 0; pm_ref.forwardmove = 0; pm_ref.upmove = 0; //playerphysics->ps.move_type = PM_NOCLIP; for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin()); iter!=actors.end(); ++iter) { OEngine::Physic::PhysicActor* act = mEngine->getCharacter(iter->first); //if(iter->first == "player") // std::cout << "This is player\n"; //dirty stuff to get the camera orientation. Must be changed! Ogre::SceneNode *sceneNode = mRender.getScene()->getSceneNode (iter->first); Ogre::Vector3 dir; Ogre::Node* yawNode = sceneNode->getChildIterator().getNext(); Ogre::Node* pitchNode = yawNode->getChildIterator().getNext(); Ogre::Quaternion yawQuat = yawNode->getOrientation(); Ogre::Quaternion pitchQuat = pitchNode->getOrientation(); // unused //Ogre::Quaternion both = yawQuat * pitchQuat; playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); playerphysics->ps.viewangles.z = 0; playerphysics->ps.viewangles.y = yawQuat.getYaw().valueDegrees() *-1 + 90; if(mFreeFly) { Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); pm_ref.rightmove = -dir1.x; pm_ref.forwardmove = dir1.z; pm_ref.upmove = dir1.y; //std::cout << "Current angle" << yawQuat.getYaw().valueDegrees() - 90<< "\n"; //playerphysics->ps.viewangles.x = pitchQuat.getPitch().valueDegrees(); //std::cout << "Pitch: " << yawQuat.getPitch() << "Yaw:" << yawQuat.getYaw() << "Roll: " << yawQuat.getRoll() << "\n"; dir = 0.07*(yawQuat*pitchQuat*dir1); } else { Ogre::Quaternion quat = yawNode->getOrientation(); Ogre::Vector3 dir1(iter->second.x,iter->second.z,-iter->second.y); pm_ref.rightmove = -dir1.x; pm_ref.forwardmove = dir1.z; pm_ref.upmove = dir1.y; dir = 0.025*(quat*dir1); } //set the walk direction act->setWalkDirection(btVector3(dir.x,-dir.z,dir.y)); } mEngine->stepSimulation(dt); }