-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
87 lines (73 loc) · 2.29 KB
/
Copy pathSource.cpp
File metadata and controls
87 lines (73 loc) · 2.29 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
#include "Ogre.h"
#include "Bites/OgreApplicationContext.h"
#include <iostream>
using namespace Ogre;
using namespace OgreBites;
class NinjaSlash : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
private:
Entity* ninjaEntity = NULL;
AnimationState* mAnimationState = NULL;
InputListener* mInputDevice = NULL;
public:
NinjaSlash();
bool mousePressed(const MouseButtonEvent& evt);
void setup();
void frameRendered(const Ogre::FrameEvent& evt);
};
NinjaSlash::NinjaSlash() : OgreBites::ApplicationContext()
{
}
bool NinjaSlash::mousePressed(const MouseButtonEvent& evt)
{
if (evt.button == OgreBites::BUTTON_LEFT)
{
mAnimationState->setLoop(false);
mAnimationState->setEnabled(true);
}
return true;
}
void NinjaSlash::setup()
{
// do not forget to call the base first
OgreBites::ApplicationContext::setup();
Root* root = getRoot();
SceneManager* scnMgr = root->createSceneManager();
scnMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
Light* light = scnMgr->createLight("MainLight");
SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(light);
lightNode->setPosition(20, 80, 50);
SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
Camera* cam = scnMgr->createCamera("myCam");
cam->setNearClipDistance(5);
cam->setAutoAspectRatio(true);
camNode->attachObject(cam);
camNode->setPosition(0, 100, 400);
getRenderWindow()->addViewport(cam);
ninjaEntity = scnMgr->createEntity("ninja.mesh");
SceneNode* ogreNode = scnMgr->getRootSceneNode()->createChildSceneNode();
ogreNode->attachObject(ninjaEntity);
ogreNode->yaw(Degree(180));
mAnimationState = ninjaEntity->getAnimationState("Attack3");
addInputListener(this);
}
void NinjaSlash::frameRendered(const Ogre::FrameEvent& evt)
{
if (mAnimationState->getEnabled())
{
mAnimationState->addTime(evt.timeSinceLastFrame);
if (mAnimationState->getLength() == mAnimationState->getTimePosition())
{
mAnimationState->setTimePosition(0);
mAnimationState->setEnabled(false);
}
}
}
int main()
{
NinjaSlash app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
}