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; }
bool mouseMoved(const OIS::MouseEvent &arg) { mCameraAngleH -= Ogre::Degree((Ogre::Real)arg.state.X.rel); mCameraAngleV -= Ogre::Degree((Ogre::Real)arg.state.Y.rel); mCamera->setOrientation(Ogre::Quaternion::IDENTITY); mCamera->yaw(mCameraAngleH*0.1); mCamera->pitch(mCameraAngleV*0.1); mGUI->injectMouseMove(arg); return true; }
//------------------------------------------------------------------------ void TApplySetup_CameraUp::WorkFromThread_Ogre() { Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); nsMathTools::TVector3 point(0,0,0); pCamera->setPosition(point.x, point.y, point.z); pCamera->lookAt(mVCameraUp.x, mVCameraUp.y, mVCameraUp.z); Ogre::Degree degree; degree = 90; Ogre::Radian rad; rad = degree.valueRadians(); pCamera->pitch(rad); }
//--------------------------------------------------------------------------------------------- //void TControlCamera::MouseLeftButtonDown( int x, int y) //{ //mOldX = x; //mOldY = y; //} //--------------------------------------------------------------------------------------------- //void TControlCamera::MouseLeftButtonUp() //{ //flgMovedCamera = false; //} //--------------------------------------------------------------------------------------------- // передавать разницу в координатах! а не сами координаты //void TControlCamera::MoveMouse(int new_x, int new_y) //{ // flgMovedCamera = true; // // Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); // // Ogre::Radian angle; // angle = mOldY - new_y; // pCamera->pitch(MOUSE_Y_AMP*angle); // // angle = mOldX - new_x; // pCamera->yaw(MOUSE_X_AMP*angle); // // mOldX = new_x; // mOldY = new_y; //} //--------------------------------------------------------------------------------------------- void TControlCamera::MoveMouse(int dX, int dY) { //flgMovedCamera = true; Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); Ogre::Radian angle; angle = -dY; pCamera->pitch(MOUSE_Y_AMP*angle); angle = -dX; pCamera->yaw(MOUSE_X_AMP*angle); }
//----------------------------------------------------------------------------------- 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 ); } } }
//----------------------------------------------------------------------------------------- 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 GraphicsImpl::handleMouseEvents(const DataContainer& data) { InputMouseEvent ev = boost::any_cast<InputMouseEvent>(data.data); static bool mouseButtonPressed = false; gui->injectMouseMove(ev.mouseX, ev.mouseY, 0); camera->yaw(Ogre::Degree(-ev.mouseDeltaX * 0.13)); camera->pitch(Ogre::Degree(-ev.mouseDeltaY * 0.13)); MyGUI::MouseButton id; if (ev.type == BUTTON_MOUSE_LEFT) { id = MyGUI::MouseButton::Left; } else if (ev.type == BUTTON_MOUSE_RIGHT) { id = MyGUI::MouseButton::Right; } else { id = MyGUI::MouseButton::Middle; } if (ev.action == BUTTON_PRESSED) { mouseButtonPressed = true; gui->injectMousePress(ev.mouseX, ev.mouseY, id); } else { mouseButtonPressed = false; gui->injectMouseRelease(ev.mouseX, ev.mouseY, id); } }
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::pitch(Ogre::Radian const&) void camera_pitch(CameraHandle handle, coiReal angle) { Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle); const Ogre::Radian r(angle); camera->pitch(r); }
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; }