-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameListener.cpp
More file actions
107 lines (79 loc) · 2.86 KB
/
FrameListener.cpp
File metadata and controls
107 lines (79 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <math.h>
#include <boost/shared_ptr.hpp>
#include <Ogre.h>
#include <OgreStringConverter.h>
#include <OgreException.h>
#define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>
#include "Camera.hpp"
#include "FrameListener.hpp"
namespace Game3D {
FrameListener::FrameListener(Ogre::RenderWindow* window, World& world) :
world_(world), window_(window),
inputManager_(0), mouse_(0), keyboard_(0) {
Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
OIS::ParamList pl;
size_t windowHnd = 0;
window->getCustomAttribute("WINDOW", &windowHnd);
std::ostringstream windowHndStr;
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
inputManager_ = OIS::InputManager::createInputSystem(pl);
const bool bufferedKeys = false, bufferedMouse = false;
keyboard_ = static_cast<OIS::Keyboard*>(inputManager_->createInputObject(OIS::OISKeyboard, bufferedKeys));
mouse_ = static_cast<OIS::Mouse*>(inputManager_->createInputObject(OIS::OISMouse, bufferedMouse));
}
// Adjust mouse clipping area.
void FrameListener::windowResized(Ogre::RenderWindow* window) {
unsigned int width, height, depth;
int left, top;
window->getMetrics(width, height, depth, left, top);
const OIS::MouseState& ms = mouse_->getMouseState();
ms.width = width;
ms.height = height;
}
// Unattach OIS before window shutdown (very important under Linux).
void FrameListener::windowClosed(Ogre::RenderWindow* window) {
// Only close for window that created OIS.
if(window == window_) {
if(inputManager_) {
inputManager_->destroyInputObject(mouse_);
inputManager_->destroyInputObject(keyboard_);
OIS::InputManager::destroyInputSystem(inputManager_);
inputManager_ = 0;
}
}
}
bool FrameListener::frameStarted(const Ogre::FrameEvent& evt) {
Event event(Event::FRAME_START, evt, *keyboard_, *mouse_);
keyboard_->capture();
mouse_->capture();
world_.onEvent(event);
return true;
}
bool FrameListener::frameRenderingQueued(const Ogre::FrameEvent& evt) {
if(window_->isClosed()) {
return false;
}
keyboard_->capture();
mouse_->capture();
assert(!keyboard_->buffered());
if(keyboard_->isKeyDown(OIS::KC_ESCAPE) || keyboard_->isKeyDown(OIS::KC_Q)) {
return false;
}
// Advance the animation.
world_.getSceneManager().getEntity("thing")->getAnimationState("my_animation")->addTime(evt.timeSinceLastFrame);
Event event(Event::FRAME_RENDERING, evt, *keyboard_, *mouse_);
world_.onEvent(event);
return true;
}
bool FrameListener::frameEnded(const Ogre::FrameEvent& evt) {
Ogre::SceneNode* busNode = world_.getSceneManager().getSceneNode("bus");
busNode->translate(-0.1, 0.0, 0.0);
keyboard_->capture();
mouse_->capture();
Event event(Event::FRAME_END, evt, *keyboard_, *mouse_);
world_.onEvent(event);
return true;
}
}