bool frameStarted(const Ogre::FrameEvent& evt) { if (mExit) return false; if (mWindow->isClosed()) return false; mKeyboard->capture(); mMouse->capture(); if (mKeyboard->isKeyDown(OIS::KC_A) || mKeyboard->isKeyDown(OIS::KC_LEFT)) mCamera->moveRelative(Ogre::Vector3(-evt.timeSinceLastFrame*20, 0, 0)); if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT)) mCamera->moveRelative(Ogre::Vector3(evt.timeSinceLastFrame*20, 0, 0)); if (mKeyboard->isKeyDown(OIS::KC_W) || mKeyboard->isKeyDown(OIS::KC_UP)) mCamera->moveRelative(Ogre::Vector3(0, 0, -evt.timeSinceLastFrame*20)); if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN)) mCamera->moveRelative(Ogre::Vector3(0, 0, evt.timeSinceLastFrame*20)); mGUI->injectFrameEntered(evt.timeSinceLastFrame); return true; }
bool frameStarted(const Ogre::FrameEvent& evt){ _key->capture(); _mouse->capture(); float movSpeed = 500.0f; if (_key->isKeyDown(OIS::KC_ESCAPE)) return false; Ogre::Vector3 t(0,0,0); if (_key->isKeyDown(OIS::KC_W)) t += Ogre::Vector3(0,0,-10); if (_key->isKeyDown(OIS::KC_S)) t += Ogre::Vector3(0,0,10); if (_key->isKeyDown(OIS::KC_A)) t += Ogre::Vector3(-10,0,0); if (_key->isKeyDown(OIS::KC_D)) t += Ogre::Vector3(10,0,0); _cam->moveRelative(t*evt.timeSinceLastFrame*movSpeed); float rotX = _mouse->getMouseState().X.rel * evt.timeSinceLastFrame* -1; float rotY = _mouse->getMouseState().Y.rel * evt.timeSinceLastFrame * -1; _cam->yaw(Ogre::Radian(rotX)); _cam->pitch(Ogre::Radian(rotY)); return true; }
//------------------------------------------------------------------- void TControlCamera::CameraTryMove() { if( flgMoveForward==false ) if( flgMoveBackward==false ) if( flgMoveLeft==false ) if( flgMoveRight==false ) if( flgMoveDown==false ) if( flgMoveUp==false ) return; Ogre::Vector3 v(0,0,0); if( flgMoveForward ) v.z = -DELTA_CAMERA_FORWARD; if( flgMoveBackward ) v.z = DELTA_CAMERA_BACKWARD; if( flgMoveLeft ) v.x = -DELTA_CAMERA_LEFT; if( flgMoveRight ) v.x = DELTA_CAMERA_RIGHT; if( flgMoveDown ) v.y = -DELTA_CAMERA_DOWN; if( flgMoveUp ) v.y = DELTA_CAMERA_UP; Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); pCamera->moveRelative(v); }
bool GraphicsImpl::doStep() { if (newWorld) { boost::mutex::scoped_lock lock(worldMutex); std::swap(frontWorld, backWorld); newWorld = false; } gui->injectFrameEntered(timeSinceLastFrame()); moveScale = timeSinceLastFrame() * 100; camera->moveRelative(movementVector * moveScale); updatePositions(); Ogre::WindowEventUtilities::messagePump(); caelumSystem->notifyCameraChanged(camera); return root->renderOneFrame(); }
//----------------------------------------------------------------------------------- void CameraController::update( float timeSinceLast ) { Ogre::Camera *camera = mGraphicsSystem->getCamera(); if( mCameraYaw || mCameraPitch ) { if( mUseSceneNode ) { Ogre::Node *cameraNode = camera->getParentNode(); // Update now as yaw needs the derived orientation. cameraNode->_getFullTransformUpdated(); cameraNode->yaw( Ogre::Radian( mCameraYaw ), Ogre::Node::TS_WORLD ); cameraNode->pitch( Ogre::Radian( mCameraPitch ) ); } else { camera->yaw( Ogre::Radian( mCameraYaw ) ); camera->pitch( Ogre::Radian( mCameraPitch ) ); } mCameraYaw = 0.0f; mCameraPitch = 0.0f; } int camMovementZ = mWASD[2] - mWASD[0]; int camMovementX = mWASD[3] - mWASD[1]; int slideUpDown = mSlideUpDown[0] - mSlideUpDown[1]; if( camMovementZ || camMovementX || slideUpDown ) { Ogre::Vector3 camMovementDir( camMovementX, slideUpDown, camMovementZ ); camMovementDir.normalise(); camMovementDir *= timeSinceLast * 10.0f * (1 + mSpeedMofifier * 5); if( mUseSceneNode ) { Ogre::Node *cameraNode = camera->getParentNode(); cameraNode->translate( camMovementDir, Ogre::Node::TS_LOCAL ); } else { camera->moveRelative( camMovementDir ); } } }
// Move the player relative to her own position and // orientation. After the call, the new position is returned. void moveRel(float &relX, float &relY, float &relZ) { using namespace Ogre; // Move camera relative to its own direction camera->moveRelative(Vector3(relX,0,relZ)); // Up/down movement is always done relative the world axis. camera->move(Vector3(0,relY,0)); // Get new camera position, converting back to MW coords. Vector3 pos = camera->getPosition(); relX = pos[0]; relY = -pos[2]; relZ = pos[1]; // TODO: Collision detection must be used to find the REAL new // position. // Set the position setPos(relX, relY, relZ); }
void TestApp::setCurrentScene(SceneBase* scene) { mInputHandler->setScene(scene); // Setup the renderer window (i.e. add a camera/viewport to it) Ogre::Camera* camera = scene->getCamera(); if (!mViewport) { mViewport = mRenderWindow->addViewport(camera); } mViewport->setCamera(camera); camera->setAspectRatio(((Ogre::Real)mViewport->getActualWidth()) / ((Ogre::Real)mViewport->getActualHeight())); camera->setAutoAspectRatio(true); camera->setNearClipDistance(5.0f); // AB: default is 100 camera->moveRelative(Ogre::Vector3(0.0f, 0.0f, 200.0f)); mInputHandler->setCamera(camera); Ogre::SceneManager* manager = scene->getSceneManager(); mGui->setSceneManager(manager); mGui->setSceneId(SceneHandler::getSceneHandler()->getSceneId(scene)); mGui->setSceneDescription(scene->getSceneDescription()); mScene = scene; mInputHandler->forceToggleCallbackActivation(); }
bool frameStarted(const Ogre::FrameEvent& evt){ Ogre::Vector3 translate(0,0,0); _Keyboard->capture(); if(_Keyboard->isKeyDown(OIS::KC_ESCAPE)){ return false; } if(_Keyboard->isKeyDown(OIS::KC_W)){ translate += Ogre::Vector3(0,0,-1); } if(_Keyboard->isKeyDown(OIS::KC_S)){ translate += Ogre::Vector3(0,0,1); } if(_Keyboard->isKeyDown(OIS::KC_A)){ translate += Ogre::Vector3(-1,0,0); } if(_Keyboard->isKeyDown(OIS::KC_D)){ translate += Ogre::Vector3(1,0,0); } /* Agregadas por mi */ if(_Keyboard->isKeyDown(OIS::KC_UP)){ _nodeRuedaSimple0->pitch(Ogre::Radian(-10)); _nodeRuedaSimple1->pitch(Ogre::Radian(-10)); _nodeRuedaSimple2->pitch(Ogre::Radian(-10)); _nodeRuedaSimple3->pitch(Ogre::Radian(-10)); _nodeRuedaSimple0->translate(0,0,5); _nodeRuedaSimple1->translate(0,0,5); _nodeRuedaSimple2->translate(0,0,5); _nodeRuedaSimple3->translate(0,0,5); _nodeChasisCarro->translate(0,0,5); eje->translate(0.0,0.0,5.0); desplazamiento += 5; if (desplazamiento >= 6500 && i<25) { eje->scale(1.1,1.1,1.1); i++; } } if(_Keyboard->isKeyDown(OIS::KC_RIGHT)){ /* _nodeRuedaSimple00->yaw(Ogre::Radian(5)); _nodeRuedaSimple11->yaw(Ogre::Radian(5)); _nodeRuedaSimple22->yaw(Ogre::Radian(5)); _nodeRuedaSimple33->yaw(Ogre::Radian(5));*/ _nodeRuedaSimple0->translate(-3,0,0); _nodeRuedaSimple1->translate(-3,0,0); _nodeRuedaSimple2->translate(-3,0,0); _nodeRuedaSimple3->translate(-3,0,0); _nodeChasisCarro->translate(-3,0,0); } if(_Keyboard->isKeyDown(OIS::KC_LEFT)){ /* _nodeRuedaSimple00->yaw(Ogre::Radian(-5)); _nodeRuedaSimple11->yaw(Ogre::Radian(-5)); _nodeRuedaSimple22->yaw(Ogre::Radian(-5)); _nodeRuedaSimple33->yaw(Ogre::Radian(-5)); */ _nodeRuedaSimple0->translate(3,0,0); _nodeRuedaSimple1->translate(3,0,0); _nodeRuedaSimple2->translate(3,0,0); _nodeRuedaSimple3->translate(3,0,0); _nodeChasisCarro->translate(3,0,0); } _Cam->moveRelative(translate*evt.timeSinceLastFrame * 600); _Mouse->capture(); float rotX = _Mouse->getMouseState().X.rel * evt.timeSinceLastFrame* -1; float rotY = _Mouse->getMouseState().Y.rel * evt.timeSinceLastFrame * -1; _Cam->yaw(Ogre::Radian(rotX)); _Cam->pitch(Ogre::Radian(rotY)); return true; }
//Ogre::Camera::moveRelative(Ogre::Vector3 const&) void camera_move_relative(CameraHandle handle, const float x, const float y, const float z) { Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle); camera->moveRelative(Ogre::Vector3(x, y, z)); }
bool frameStarted(const Ogre::FrameEvent& evt){ if(vidas==0) return false; _key->capture(); _mouse->capture(); float movSpeed = 500.0f; if (_key->isKeyDown(OIS::KC_ESCAPE)) return false; Ogre::Vector3 t(0,0,0); if (_key->isKeyDown(OIS::KC_W)) if (freemoving) t += Ogre::Vector3(0,0,-10); else nave->moverAdelante(); if (_key->isKeyDown(OIS::KC_S)) if (freemoving) t += Ogre::Vector3(0,0,10); else nave->moverAtras(); if (_key->isKeyDown(OIS::KC_A)) if (freemoving) t += Ogre::Vector3(-10,0,0); else nave->moverIzquierda(); if (_key->isKeyDown(OIS::KC_D)) if (freemoving) t += Ogre::Vector3(10,0,0); else nave->moverDerecha(); if (_key->isKeyDown(OIS::KC_UP)) nave->moverArriba(); if (_key->isKeyDown(OIS::KC_DOWN)) nave->moverAbajo(); if (!_key->isKeyDown(OIS::KC_A) && !_key->isKeyDown(OIS::KC_D)) nave->reset(); if(_key->isKeyDown(OIS::KC_I)) std::cout<<"CAMARA:"<<_cam->getPosition()<<std::endl <<"NAVE:"<<nave->nodoNave->getPosition()<<std::endl; _cam->moveRelative(t*evt.timeSinceLastFrame*movSpeed); if (freemoving){ float rotX = _mouse->getMouseState().X.rel * evt.timeSinceLastFrame* -1; float rotY = _mouse->getMouseState().Y.rel * evt.timeSinceLastFrame * -1; _cam->yaw(Ogre::Radian(rotX)); _cam->pitch(Ogre::Radian(rotY)); } for (int i = 0; i < num_monedas; i++) { moneda[i]->animState->addTime(evt.timeSinceLastFrame); } for (int i = 0; i < num_obstaculo; i++) { obstaculo[i]->animState->addTime(evt.timeSinceLastFrame); } for (int i = 0; i < num_monedas; i++) { if (moneda[i]->visible && nave->getBox().intersects(moneda[i]->getBox())){ moneda[i]->visible = false; moneda[i]->nodoMoneda->setVisible(false); puntaje+=100; mostrarPuntaje(); } } for (int i = 0; i < num_aros; i++) { Ogre::AxisAlignedBox boxNave = nave->getBox(); Ogre::Vector3 centro = nave->getCenter(); if (aro[i]->visible && nave->getBox().intersects(aro[i]->getBox()) && aro[i]->adentro(boxNave, centro)) { aro[i]->visible = false; aro[i]->nodoAro->setVisible(false); puntaje+=200; mostrarPuntaje(); } } for (int i = 0; i < num_obstaculo; i++) { if (obstaculo[i]->visible && nave->getBox().intersects(obstaculo[i]->getBox())){ obstaculo[i]->visible = false; obstaculo[i]->nodoObstaculo->setVisible(false); vidas-=1; mostrarPuntaje(); } } nave->animStateDer->addTime(evt.timeSinceLastFrame); nave->animStateIzq->addTime(evt.timeSinceLastFrame); return true; }