本文整理汇总了C++中ois::Mouse类的典型用法代码示例。如果您正苦于以下问题:C++ Mouse类的具体用法?C++ Mouse怎么用?C++ Mouse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mouse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: capture
void InputHandler::capture()
{
if (keyboard == 0 && mouse == 0)
{
try {
keyboard = static_cast<OIS::Keyboard*>
(ois->createInputObject(OIS::OISKeyboard, true));
keyboard->setEventCallback(this);
mouse = static_cast<OIS::Mouse*>
(ois->createInputObject(OIS::OISMouse, true));
mouse->setEventCallback(this);
cout << "[libclois-lane] Keyboard and mouse acquired!" << endl;
} catch (OIS::Exception &e) {
cout << "[libclois-lane] " << e.eText << endl;
}
}
else
{
try {
keyboard->capture();
mouse->capture();
} catch (OIS::Exception &e) {
cout << "[libclois-lane] " << e.eText << endl;
keyboard = 0;
mouse = 0;
}
}
}
示例2: frameStarted
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;
}
示例3: Update
///
/// @inheritDoc
///
void CursorInputObject::Update(float DeltaTime) {
OIS::Mouse* mouse = OISB::System::getSingleton().getOISMouse();
m_velocity.x = mouse->getMouseState().X.abs;
m_velocity.y = mouse->getMouseState().Y.abs;
//if (m_velocity != Math::Vector3::Zero) {
// TODO change
//PostChanges(System::Changes::Input::Velocity);
//}
if (mouse->getMouseState().buttonDown(OIS::MB_Left)) {
//PostChanges(System::Changes::Input::Action);
}
}
示例4: frameStarted
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;
}
示例5: setWindowExtents
void InputHandler::setWindowExtents(int width, int height)
{
if (mouse) // might not be initialised yet
{
// Set mouse region. If window resizes, we should alter this as well.
const OIS::MouseState &ms = mouse->getMouseState();
ms.height = height;
ms.width = width;
}
}
示例6: windowResized
void application::windowResized (Ogre::RenderWindow* wnd)
{
unsigned width, height, depth;
int left, top;
wnd->getMetrics (width, height, depth, left, top);
OIS::MouseState const& ms = mouse->getMouseState();
ms.width = width;
ms.height = height;
}
示例7: update
void CGUITouchButton::update(Ogre::Real tpf) {
m_bHitOnce = false;
// update input
OIS::Mouse *pMouse = CGame::getSingleton().getInputContext().mMouse;
if (pMouse) {
processInput(Vector2f(pMouse->getMouseState().X.abs,
pMouse->getMouseState().Y.abs));
}
OIS::MultiTouch *pMultiTouch = CGame::getSingleton().getInputContext().mMultiTouch;
if (pMultiTouch) {
const std::vector<OIS::MultiTouchState> &mts = pMultiTouch->getMultiTouchStates();
for (auto &state : mts) {
if (state.touchType == OIS::MT_Moved || state.touchType == OIS::MT_Pressed) {
processInput(Vector2f(state.X.abs, state.Y.abs));
}
}
}
handleButtonPress(m_bHitOnce);
}
示例8: main
int main(int argc, char **argv)
#endif
{
//-----------------------------------------------------
// 1 enter ogre
//-----------------------------------------------------
Root* root = new Root;
//-----------------------------------------------------
// 2 configure resource paths
//-----------------------------------------------------
// Load resource paths from config file
// File format is:
// [ResourceGroupName]
// ArchiveType=Path
// .. repeat
// For example:
// [General]
// FileSystem=media/
// Zip=packages/level1.zip
ConfigFile cf;
cf.load("./resources.cfg");
// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();
String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
//-----------------------------------------------------
// 3 Configures the application and creates the window
//-----------------------------------------------------
if(!root->showConfigDialog())
{
//Ogre
delete root;
return false; // Exit the application on cancel
}
RenderWindow* window = root->initialise(true, "Simple Ogre App");
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
//-----------------------------------------------------
// 4 Create the SceneManager
//
// ST_GENERIC = octree
// ST_EXTERIOR_CLOSE = simple terrain
// ST_EXTERIOR_FAR = nature terrain (depreciated)
// ST_EXTERIOR_REAL_FAR = paging landscape
// ST_INTERIOR = Quake3 BSP
//-----------------------------------------------------
SceneManager* sceneMgr = root->createSceneManager(ST_GENERIC);
//-----------------------------------------------------
// 5 Create the camera
//-----------------------------------------------------
Camera* camera = sceneMgr->createCamera("SimpleCamera");
//-----------------------------------------------------
// 6 Create one viewport, entire window
//-----------------------------------------------------
Viewport* viewPort = window->addViewport(camera);
//----------------------------------------------------
// 7 add OIS input handling
//----------------------------------------------------
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
//tell OIS about the Ogre window
window->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
//setup the manager, keyboard and mouse to handle input
OIS::InputManager* inputManager = OIS::InputManager::createInputSystem(pl);
OIS::Keyboard* keyboard = static_cast<OIS::Keyboard*>(inputManager->createInputObject(OIS::OISKeyboard, true));
OIS::Mouse* mouse = static_cast<OIS::Mouse*>(inputManager->createInputObject(OIS::OISMouse, true));
//tell OIS about the window's dimensions
unsigned int width, height, depth;
int top, left;
window->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = mouse->getMouseState();
ms.width = width;
//.........这里部分代码省略.........
示例9: frameStarted
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();
}
//.........这里部分代码省略.........
示例10: tick
void HeadsUpDisplay::tick(Ogre::Real timeDelta)
{
// window dimensions may have changed
Application &app = Application::getSingleton();
Ogre::Real windowWidth = (Ogre::Real)app.getWindowWidth();
Ogre::Real windowHeight = (Ogre::Real)app.getWindowHeight();
// get mouse cursor and update absolute position from relative change
OIS::Mouse *mouse = app.getMouse();
if (mouse != nullptr)
{
OIS::MouseState mouseState = mouse->getMouseState();
m_cursorX += mouseState.X.rel;
m_cursorY += mouseState.Y.rel;
m_cursorX = Math::clamp(m_cursorX, 0, windowWidth);
m_cursorY = Math::clamp(m_cursorY, 0, windowHeight);
// normalize cursor position and size from 0 to 1
Ogre::Real cursorX = m_cursorX / windowWidth;
Ogre::Real cursorY = m_cursorY / windowHeight;
m_cursorContainer->setPosition(cursorX, cursorY);
m_cursorContainer->setWidth(CURSOR_WIDTH / windowWidth);
m_cursorContainer->setHeight(CURSOR_HEIGHT / windowHeight);
m_cursorContainer->show();
// project cursor ray into scene and get query results
if (!m_mouseLeftLastDown && mouseState.buttonDown(OIS::MouseButtonID::MB_Left))
{
Ogre::Ray mouseRay;
getCamera()->getCameraToViewportRay(cursorX, cursorY, &mouseRay);
m_rayQuery->setRay(mouseRay);
m_objectFound = false;
m_rayQuery->execute(this);
if (!m_objectFound && (m_currentSelection != nullptr))
{
// user selected nothing so clear current selection
m_currentSelection->onDeselect();
}
}
if ((m_currentSelection != nullptr) && !m_mouseRightLastDown && mouseState.buttonDown(OIS::MouseButtonID::MB_Right))
{
Ogre::Ray mouseRay;
getCamera()->getCameraToViewportRay(cursorX, cursorY, &mouseRay);
Ogre::Plane plane(Ogre::Vector3(0, 1, 0), Ogre::Vector3::ZERO);
auto intersectResult = mouseRay.intersects(plane);
if (intersectResult.first)
{
Ogre::Vector3 destination = mouseRay.getPoint(intersectResult.second);
m_currentSelection->onMoveOrder(destination);
}
}
m_mouseLeftLastDown = mouseState.buttonDown(OIS::MouseButtonID::MB_Left);
m_mouseRightLastDown = mouseState.buttonDown(OIS::MouseButtonID::MB_Right);
}
else
{
m_cursorContainer->hide();
}
}
示例11: Init
void EditorFrameHandler::Init()
{
Ogre::SceneManager *scene_manager = CommonDeclarations::GetSceneManager();
EditorCamera = scene_manager->createCamera("EditorCamera");
EditorCamera->setNearClipDistance(5);
EditorCamera->setFarClipDistance(0);
EditorCamera->setPosition(CommonDeclarations::GetCamera()->GetOgreCamera()->getWorldPosition());
CommonDeclarations::GetApplication()->SetCurrentCamera(EditorCamera);
/*CommonDeclarations::ObjectsPool *objects = CommonDeclarations::GetEditableObjects();
for (CommonDeclarations::ObjectsPool::ListNode *pos = objects->GetBegin();pos!=NULL;pos=pos->Next)
{
SEditableObject obj;
obj.Object = pos->Value;
IScenable *scen = pos->Value->GetScenable();
if (scen)
{
obj.EditNode = NULL;
obj.EditEntity = NULL;
ICollidable *collid = pos->Value->GetCollidable();
if (collid)
{
obj.CollisionModel = collid->GetCollisionModel();
} else
{
const char *modelname = scen->GetModelName();
if (NULL == modelname)
modelname = AAUtilities::StringCopy("cube.mesh");
obj.CollisionModel = GetCollisionModel(modelname);
}
} else
{
obj.EditNode = scene_manager->getRootSceneNode()->createChildSceneNode();
char *buffer = CommonDeclarations::GenGUID();
obj.EditEntity = scene_manager->createEntity(buffer, "cube.mesh");
delete [] buffer;
obj.EditNode->attachObject(obj.EditEntity);
obj.CollisionModel = GetCollisionModel("cube.mesh");
}
EditableObjects.PushBack(obj);
}
delete objects;*/
//
CommonDeclarations::ObjectsPool *objects = CommonDeclarations::GetEditableObjects();
const char *str;
TiXmlElement *node = 0, *nodes, *env;
env = SceneRootElement->FirstChildElement("environment");
if (env)
{
node = env->FirstChildElement("skyBox");
if (node)
{
SEditableDescription descr;
descr.EditNode = NULL;
descr.EditElement = node;
EditorNodes.insert(std::make_pair("SkyBox", descr));
}
}
nodes = SceneRootElement->FirstChildElement("nodes");
if (nodes)
{
node = nodes->FirstChildElement("node");
Ogre::Node::ChildNodeIterator iFirst = scene_manager->getRootSceneNode()->getChildIterator(), iPos = iFirst;
while (node)
{
str = node->Attribute("name");
SEditableDescription descr;
Ogre::Node *t = NULL;
iPos = iFirst;
while (iPos.hasMoreElements())
{
t = iPos.getNext();
if (t->getName()==str)
{
descr.EditNode = t;
break;
}
}
descr.EditElement = node;
EditorNodes.insert(std::make_pair(str, descr));
node = node->NextSiblingElement("node");
}
}
delete objects;
//
MyGUI::Gui *gui = GUISystem::GetInstance()->GetGui();
OIS::Mouse *mouse = EditorFrameListener::GetInstance()->GetMouse();
//.........这里部分代码省略.........
示例12: processInputs
bool OgreAppLogic::processInputs(Ogre::Real deltaTime)
{
const Degree ROT_SCALE = Degree(40.0f);
const Real MOVE_SCALE = 5.0f;
Vector3 translateVector(Vector3::ZERO);
Degree rotX(0);
Degree rotY(0);
OIS::Keyboard *keyboard = mApplication->getKeyboard();
OIS::Mouse *mouse = mApplication->getMouse();
if(keyboard->isKeyDown(OIS::KC_ESCAPE))
{
return false;
}
//////// moves //////
// keyboard moves
if(keyboard->isKeyDown(OIS::KC_A))
translateVector.x = -MOVE_SCALE; // Move camera left
if(keyboard->isKeyDown(OIS::KC_D))
translateVector.x = +MOVE_SCALE; // Move camera RIGHT
if(keyboard->isKeyDown(OIS::KC_UP) || keyboard->isKeyDown(OIS::KC_W) )
translateVector.z = -MOVE_SCALE; // Move camera forward
if(keyboard->isKeyDown(OIS::KC_DOWN) || keyboard->isKeyDown(OIS::KC_S) )
translateVector.z = +MOVE_SCALE; // Move camera backward
if(keyboard->isKeyDown(OIS::KC_PGUP))
translateVector.y = +MOVE_SCALE; // Move camera up
if(keyboard->isKeyDown(OIS::KC_PGDOWN))
translateVector.y = -MOVE_SCALE; // Move camera down
if(keyboard->isKeyDown(OIS::KC_RIGHT))
rotX -= ROT_SCALE; // Turn camera right
if(keyboard->isKeyDown(OIS::KC_LEFT))
rotX += ROT_SCALE; // Turn camea left
rotX *= deltaTime;
rotY *= deltaTime;
translateVector *= deltaTime;
// mouse moves
const OIS::MouseState &ms = mouse->getMouseState();
if (ms.buttonDown(OIS::MB_Right))
{
translateVector.x += ms.X.rel * 0.003f * MOVE_SCALE; // Move camera horizontaly
translateVector.y -= ms.Y.rel * 0.003f * MOVE_SCALE; // Move camera verticaly
}
else
{
rotX += Degree(-ms.X.rel * 0.003f * ROT_SCALE); // Rotate camera horizontaly
rotY += Degree(-ms.Y.rel * 0.003f * ROT_SCALE); // Rotate camera verticaly
}
mCamera->moveRelative(translateVector);
mCamera->yaw(rotX);
mCamera->pitch(rotY);
return true;
}
示例13: frameStarted
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;
}
示例14: processInput
void World::processInput()
{
using namespace OIS;
static Ogre::Timer timer;
static unsigned long lastTime = 0;
unsigned long currentTime = timer.getMilliseconds();
//Calculate the amount of time passed since the last frame
Real timeScale = (currentTime - lastTime) * 0.001f;
if (timeScale < 0.001f)
timeScale = 0.001f;
lastTime = currentTime;
//Get the current state of the keyboard and mouse
keyboard->capture();
mouse->capture();
const OIS::MouseState &ms = mouse->getMouseState();
//[NOTE] When the left mouse button is pressed, add trees
if (ms.buttonDown(MB_Left)){
//Choose a random tree rotation
Degree yaw = Degree(Math::RangeRandom(0, 360));
//Choose a random scale
Real scale = Math::RangeRandom(0.5f, 0.6f);
//Calculate a position
Ogre::Vector3 centerPos = camera->getPosition() + (camera->getOrientation() * Ogre::Vector3(0, 0, -50));
Radian rndAng = Radian(Math::RangeRandom(0, Math::TWO_PI));
Real rndLen = Math::RangeRandom(0, 20);
centerPos.x += Math::Sin(rndAng) * rndLen;
centerPos.z += Math::Cos(rndAng) * rndLen;
//And add the tree
treeLoader->addTree(myTree, centerPos, yaw, scale);
//[NOTE] Dynamic trees are very easy, as you can see. No additional setup is required for
//the dynamic addition / removal of trees to work. Simply call addTree(), etc. as needed.
}
//[NOTE] When the right mouse button is pressed, delete trees
if (ms.buttonDown(MB_Right)){
//Calculate a position in front of the camera
Ogre::Vector3 centerPos = camera->getPosition() + (camera->getOrientation() * Ogre::Vector3(0, 0, -50));
//Delete trees within 20 units radius of the center position
treeLoader->deleteTrees(centerPos, 20);
//[NOTE] Dynamic trees are very easy, as you can see. No additional setup is required for
//the dynamic addition / removal of trees to work. Simply call deleteTrees(), etc. as needed.
}
//Always exit if ESC is pressed
if (keyboard->isKeyDown(KC_ESCAPE))
running = false;
//Reload the scene if R is pressed
static bool reloadedLast = false;
if (keyboard->isKeyDown(KC_R) && !reloadedLast){
unload();
load();
reloadedLast = true;
}
else {
reloadedLast = false;
}
//Update camera rotation based on the mouse
camYaw += Radian(-ms.X.rel / 200.0f);
camPitch += Radian(-ms.Y.rel / 200.0f);
camera->setOrientation(Quaternion::IDENTITY);
camera->pitch(camPitch);
camera->yaw(camYaw);
//Allow the camera to move around with the arrow/WASD keys
Ogre::Vector3 trans(0, 0, 0);
if (keyboard->isKeyDown(KC_UP) || keyboard->isKeyDown(KC_W))
trans.z = -1;
if (keyboard->isKeyDown(KC_DOWN) || keyboard->isKeyDown(KC_S))
trans.z = 1;
if (keyboard->isKeyDown(KC_RIGHT) || keyboard->isKeyDown(KC_D))
trans.x = 1;
if (keyboard->isKeyDown(KC_LEFT) || keyboard->isKeyDown(KC_A))
trans.x = -1;
if (keyboard->isKeyDown(KC_PGUP) || keyboard->isKeyDown(KC_E))
trans.y = 1;
if (keyboard->isKeyDown(KC_PGDOWN) || keyboard->isKeyDown(KC_Q))
trans.y = -1;
//Shift = speed boost
if (keyboard->isKeyDown(KC_LSHIFT) || keyboard->isKeyDown(KC_RSHIFT))
trans *= 2;
trans *= 100;
camera->moveRelative(trans * timeScale);
//Make sure the camera doesn't go under the terrain
Ogre::Vector3 camPos = camera->getPosition();
float terrY = HeightFunction::getTerrainHeight(camPos.x, camPos.z);
if (camPos.y < terrY + 5 || keyboard->isKeyDown(KC_SPACE)){ //Space = walk
camPos.y = terrY + 5;
camera->setPosition(camPos);
//.........这里部分代码省略.........
示例15: processInput
void World::processInput()
{
using namespace OIS;
static Ogre::Timer timer;
static unsigned long lastTime = 0;
unsigned long currentTime = timer.getMilliseconds();
//Calculate the amount of time passed since the last frame
Real timeScale = (currentTime - lastTime) * 0.001f;
if (timeScale < 0.001f)
timeScale = 0.001f;
lastTime = currentTime;
//Get the current state of the keyboard and mouse
keyboard->capture();
mouse->capture();
//Always exit if ESC is pressed
if (keyboard->isKeyDown(OIS::KC_ESCAPE))
running = false;
//Reload the scene if R is pressed
static bool reloadedLast = false;
if (keyboard->isKeyDown(OIS::KC_R) && !reloadedLast){
unload();
load();
reloadedLast = true;
}
else {
reloadedLast = false;
}
//Get mouse movement
const OIS::MouseState &ms = mouse->getMouseState();
//Update camera rotation based on the mouse
camYaw += Radian(-ms.X.rel / 200.0f);
camPitch += Radian(-ms.Y.rel / 200.0f);
camera->setOrientation(Quaternion::IDENTITY);
camera->pitch(camPitch);
camera->yaw(camYaw);
//Allow the camera to move around with the arrow/WASD keys
Ogre::Vector3 trans(0, 0, 0);
if (keyboard->isKeyDown(KC_UP) || keyboard->isKeyDown(KC_W))
trans.z = -1;
if (keyboard->isKeyDown(KC_DOWN) || keyboard->isKeyDown(KC_S))
trans.z = 1;
if (keyboard->isKeyDown(KC_RIGHT) || keyboard->isKeyDown(KC_D))
trans.x = 1;
if (keyboard->isKeyDown(KC_LEFT) || keyboard->isKeyDown(KC_A))
trans.x = -1;
if (keyboard->isKeyDown(KC_PGUP) || keyboard->isKeyDown(KC_E))
trans.y = 1;
if (keyboard->isKeyDown(KC_PGDOWN) || keyboard->isKeyDown(KC_Q))
trans.y = -1;
//Shift = speed boost
if (keyboard->isKeyDown(KC_LSHIFT) || keyboard->isKeyDown(KC_RSHIFT))
trans *= 4;
else
trans *= 0.5f;
trans *= 30;
camera->moveRelative(trans * timeScale);
//Make sure the camera doesn't go under the terrain
Ogre::Vector3 camPos = camera->getPosition();
float terrY = HeightFunction::getTerrainHeight(camPos.x, camPos.z);
if (camPos.y < terrY + 1.5 || !keyboard->isKeyDown(KC_SPACE)){ //Space = walk
camPos.y = terrY + 1.5;
camera->setPosition(camPos);
}
}