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 CollisionCameraController::update(float timeSinceLast) { Ogre::Camera* camera = mGraphicsSystem->getCamera(); Ogre::Node* cameraNode = camera->getParentNode(); { btTransform transform = mGhostObject->getWorldTransform(); btQuaternion q = transform.getRotation(); q *= btQuaternion(btVector3(0, 1, 0), mCameraYaw); mGhostObject->getWorldTransform().setRotation(q); } camera->pitch(Ogre::Radian(mCameraPitch)); mCameraYaw = 0.0f; mCameraPitch = 0.0f; int camMovementZ = mKeymapState[Backward].second - mKeymapState[Forward].second; int camMovementX = mKeymapState[Rightward].second - mKeymapState[Leftward].second; int slideUpDown = mKeymapState[Up].second - mKeymapState[Down].second; Ogre::Vector3 camMovementDir(camMovementX, slideUpDown, camMovementZ); camMovementDir.normalise(); camMovementDir *= timeSinceLast * mCameraBaseSpeed * (1 + mSpeedModifier * mCameraSpeedBoost); if (camMovementDir.y > 0) { mCharacter->jump(); camMovementDir.y = 0; } mCharacter->setWalkDirection(Collision::Converter::to(Collision::Converter::to(mGhostObject->getWorldTransform().getRotation()) * camMovementDir)); { Ogre::Node* cameraNode = camera->getParentNode(); Ogre::Quaternion q; q = q * (Collision::Converter::to(mGhostObject->getWorldTransform().getRotation())); q = q * Ogre::Quaternion(cameraNode->getOrientation().getPitch(), Ogre::Vector3(1, 0, 0)); cameraNode->setOrientation(q); cameraNode->setPosition(Collision::Converter::to(mGhostObject->getWorldTransform().getOrigin() /* + btVector3(0,1.8,0)*/)); } }
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); }