include ExampleApplication include ExampleFrameListener class Tutorial

 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
#include "ExampleApplication.h"
#include "ExampleFrameListener.h"
class TutorialFrameListener : public ExampleFrameListener
{
public:
TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
: ExampleFrameListener(win, cam, false, false)
{
// состояние клавиатуры и мыши
mMouseDown = false;
mToggle = 0.0;
// Заполним контейнеры камеры и sceneManager-а
mCamNode = cam->getParentSceneNode( )->getParentSceneNode( );
mSceneMgr = sceneMgr;
// установим скорость вращения и движения
mRotate = 0.13;
mMove = 250;
}
// Overriding the default processUnbufferedKeyInput so the key updates we define
// later on work as intended.
bool processUnbufferedKeyInput(const FrameEvent& evt)
{
return true;
}
// Overriding the default processUnbufferedMouseInput so the Mouse updates we define
// later on work as intended.
bool processUnbufferedMouseInput(const FrameEvent& evt)
{
return true;
}
bool frameStarted(const FrameEvent &evt)
{
mMouse->capture();
mKeyboard->capture();
using namespace OIS;
const MouseState &ms = mMouse->getMouseState();
if( ms.buttonDown( MB_Left ) )
{
Light *light = mSceneMgr->getLight( "Light1" );
light->setVisible(! light->isVisible() );
} // if
return ExampleFrameListener::frameStarted(evt);
if ( mToggle >= 0.0f )
mToggle -= evt.timeSinceLastFrame;
if ( (mToggle < 0.0f) && mKeyboard->isKeyDown( KC_1 ) )
{
mToggle = 1.0f;
mCamera->getParentSceneNode()->detachObject( mCamera );
mCamNode = mSceneMgr->getSceneNode( "CamNode1" );
mSceneMgr->getSceneNode( "PitchNode1" )->attachObject( mCamera );
}
else if ( (mToggle < 0.0f) && mKeyboard->isKeyDown( KC_2 ) )
{
mToggle = 1.0f;
mCamera->getParentSceneNode()->detachObject( mCamera );
mCamNode = mSceneMgr->getSceneNode( "CamNode2" );
mSceneMgr->getSceneNode( "PitchNode2" )->attachObject( mCamera );
}
}