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 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 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); } }
void ActorSceneCanvas::OnKeyDown(wxKeyEvent& e) { switch(e.GetKeyCode()) { case 'w': case 'W': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Ogre::Vector3 offsetPos = camera->getDirection() * GetSceneManipulator()->getMoveSpeed(); Ogre::Vector3 newPos = oldPos; newPos.x += offsetPos.x; newPos.z += offsetPos.z; GetSceneManipulator()->setCameraPosition(newPos); e.Skip(false); } break; case 's': case 'S': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Vector3 oldPos = camera->getPosition(); Ogre::Vector3 offsetPos = camera->getDirection() * -(GetSceneManipulator()->getMoveSpeed()); Ogre::Vector3 newPos = oldPos; newPos.x += offsetPos.x; newPos.z += offsetPos.z; GetSceneManipulator()->setCameraPosition(newPos); e.Skip(false); } break; case 'a': case 'A': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Radian yawAngle( GetSceneManipulator()->getRotateSpeed() / 360.0f ); camera->yaw(yawAngle); e.Skip(false); } break; case 'd': case 'D': { Ogre::Camera* camera = GetSceneManipulator()->getCamera(); assert (camera); Ogre::Radian yawAngle( -(GetSceneManipulator()->getRotateSpeed() / 360.0f) ); camera->yaw(yawAngle); e.Skip(false); } break; case 'h': case 'H': { mHideAxis = !mHideAxis; Fairy::CDataManipulator::m_baseNode->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_x->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_y->setVisible(!mHideAxis); Fairy::CDataManipulator::mAxisNode_z->setVisible(!mHideAxis); } break; case 'b': case 'B': { GetDataManipulator()->switchBoundingBox(true); } break; case 't': case 'T': { GetSceneManipulator()->setTerrainVisible(!GetSceneManipulator()->getTerrainVisible()); } break; case 'g': case 'G': { GetSceneManipulator()->setGridVisible(!GetSceneManipulator()->getGridVisible()); } break; case 'r': case 'R': { mRotFirst = !mRotFirst; } break; //case 'C': // case 'c': // { // Fairy::LogicModelManager::getSingleton().showModelBoundingBox(!Fairy::LogicModelManager::getSingleton().isShowBoundingBox()); // } // break; // // case 'y': // case 'Y': // { // mYax = !mYax; // mXax = mZax = false; // } // break; // // case 'z': // case 'Z': // { // mZax = !mZax; // mXax = mYax = false; // } //break; //case 'z': //case 'Z': // { // GetSceneManipulator()->setActiveAction("ManipObjectAction"); // GetSceneManipulator()->setUseAxis(!GetSceneManipulator()->getUseAxis()); // } // e.Skip(false); // break; } }
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::yaw(Ogre::Radian const&) void camera_yaw(CameraHandle handle, coiReal angle) { Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle); const Ogre::Radian r(angle); camera->yaw(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; }