参考Sample中的角色类,使用ExampleApplication.h改写,只编译了release,debug在配置文件名字上有不同

遗留一个问题

mBodyEnt->getSkeleton()获取骨骼获取到的为null值,不解。不设置动画方式为混合不影响程序运行。原因以后调试源码解决

3个类

NMain.cpp:入口类

#include "stdafx.h"
#include <iostream>
#include "ExampleApplication.h"
using namespace std; INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
ExampleApplication game;
try {
game.go();
} catch(Ogre::Exception& e) { }
}

ExampleApplication.h:初始化,(角色,摄像机)更新逻辑

#ifndef __ExampleApplication_H__
#define __ExampleApplication_H__
#include "Ogre.h"
#include "OgreConfigFile.h"
#include "ExampleFrameListener.h"
using namespace Ogre; #define NUM_ANIMS 13 // number of animations the character has
#define CHAR_HEIGHT 5 // height of character's center of mass above ground
#define CAM_HEIGHT 2 // height of camera above character's center of mass
#define RUN_SPEED 17 // character running speed in units per second
#define TURN_SPEED 500.0f // character turning in degrees per second
#define ANIM_FADE_SPEED 7.5f // animation crossfade speed in % of full weight per second
#define JUMP_ACCEL 30.0f // character jump acceleration in upward units per squared second
#define GRAVITY 90.0f // gravity in downward units per squared second class ExampleFrameListener;
class ExampleApplication
{
public:
ExampleApplication()
{
mFrameListener = 0;
mRoot = 0;
mResourcePath = "";
mConfigPath = mResourcePath;
}
virtual ~ExampleApplication()
{
if (mFrameListener)
delete mFrameListener;
if (mRoot)
OGRE_DELETE mRoot; }
virtual void go(void)
{ if (!setup())
return;
mRoot->startRendering();
destroyScene();
}
void update(Real deltaTime)
{
updateBody(deltaTime);
updateAnimations(deltaTime);
updateCamera(deltaTime);
} ExampleFrameListener* mFrameListener; Root *mRoot;
Ogre::String mResourcePath;//资源路径
Ogre::String mConfigPath;//配置文件路径 SceneManager* mSceneMgr;//场景管理器
RenderWindow* mWindow;//渲染窗口
Camera* mCamera;//摄像机及相关节点
SceneNode* mCameraPivot;
SceneNode* mCameraGoal;
SceneNode* mCameraNode;
Real mPivotPitch; SceneNode* mBodyNode;//角色节点
Entity* mBodyEnt;//角色实体 bool mSwordsDrawn;//角色武器
RibbonTrail* mSwordTrail;
Entity* mSword1;
Entity* mSword2; //角色动画
AnimationState* mAnims[NUM_ANIMS]; // master animation list
bool mFadingIn[NUM_ANIMS]; // which animations are fading in
bool mFadingOut[NUM_ANIMS]; // which animations are fading out
enum AnimID
{
ANIM_IDLE_BASE,
ANIM_IDLE_TOP,
ANIM_RUN_BASE,
ANIM_RUN_TOP,
ANIM_HANDS_CLOSED,
ANIM_HANDS_RELAXED,
ANIM_DRAW_SWORDS,
ANIM_SLICE_VERTICAL,
ANIM_SLICE_HORIZONTAL,
ANIM_DANCE,
ANIM_JUMP_START,
ANIM_JUMP_LOOP,
ANIM_JUMP_END,
ANIM_NONE
}; Vector3 mKeyDirection; // player's local intended direction based on WASD keys
Vector3 mGoalDirection; // actual intended direction in world-space
Real mTimer; // general timer to see how long animations have been playing
AnimID mBaseAnimID; // current base (full- or lower-body) animation
AnimID mTopAnimID; // current top (upper-body) animation
Real mVerticalVelocity; // for jumping virtual bool setup(void)
{
createRoot();//Step1----创建ROOT
bool carryOn = configure();//Step2----创建窗口(启动配置页面)
if (!carryOn)
return false; setupResources();//Step3----定位资源
loadResources();//Step4----导入资源,需要在窗口创建后?
TextureManager::getSingleton().setDefaultNumMipmaps(5);
createSceneManager();//Step5----创建(选择)场景管理器
setupCamera();//Step6----创建摄像机
createViewports();//Step7----创建视口
setupBody(mSceneMgr);//Step8----安装角色
setupAnimations();//Step9----安装角色动画
createFrameListener();//Step10----监听帧事件
return true; } void createRoot(void)
{
String pluginsPath;
pluginsPath = mResourcePath + "plugins.cfg";
mRoot = OGRE_NEW Root(pluginsPath,
mConfigPath + "ogre.cfg", mResourcePath + "Ogre.log");
}
virtual bool configure(void)
{
if(mRoot->showConfigDialog())
{
mWindow = mRoot->initialise(true);
return true;
}
else
{
return false;
}
}
virtual void createSceneManager(void)
{
mSceneMgr = mRoot->createSceneManager(ST_GENERIC, "nafiosm");
}
virtual void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setPosition(Vector3(0,200,500));
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5); }
virtual void createFrameListener(void)
{
mFrameListener= new ExampleFrameListener(this,mWindow);
mRoot->addFrameListener(mFrameListener);
}
virtual void destroyScene(void)
{ }
virtual void createViewports(void)
{
Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(ColourValue(0,0,0));
mCamera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight())); }
virtual void setupResources(void)
{
ConfigFile cf;
cf.load(mResourcePath + "resources.cfg");
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); }
}
}
virtual void loadResources(void)
{
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
void setupBody(SceneManager* sceneMgr)
{
// create main model
mBodyNode = sceneMgr->getRootSceneNode()->createChildSceneNode(Vector3::UNIT_Y * CHAR_HEIGHT);
mBodyEnt = sceneMgr->createEntity("SinbadBody", "Sinbad.mesh");
mBodyNode->attachObject(mBodyEnt); Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50); //创建地表
MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Plane(Vector3::UNIT_Y, 0), 100, 100, 10, 10, true, 1, 10, 10, Vector3::UNIT_Z);
Entity* floor = mSceneMgr->createEntity("Floor", "floor");
floor->setMaterialName("Examples/Rockwall");
floor->setCastShadows(false);
mSceneMgr->getRootSceneNode()->attachObject(floor); mKeyDirection = Vector3::ZERO;
mVerticalVelocity = 0; }
void setupCamera()
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCameraPivot = mCamera->getSceneManager()->getRootSceneNode()->createChildSceneNode(); mCameraGoal = mCameraPivot->createChildSceneNode(Vector3(0, 0, 15));
mCameraNode = mCamera->getSceneManager()->getRootSceneNode()->createChildSceneNode();
mCameraNode->setPosition(mCameraPivot->getPosition() + mCameraGoal->getPosition()); mCameraPivot->setFixedYawAxis(true);
mCameraGoal->setFixedYawAxis(true);
mCameraNode->setFixedYawAxis(true); mCamera->setNearClipDistance(0.1);
mCamera->setFarClipDistance(100);
mCameraNode->attachObject(mCamera); mPivotPitch = 0;
}
void setupAnimations()
{
//mBodyEnt->getSkeleton()->setBlendMode(ANIMBLEND_CUMULATIVE);//nafio_temp 为什么不能设置动画混合方式
String animNames[] =
{"IdleBase", "IdleTop", "RunBase", "RunTop", "HandsClosed", "HandsRelaxed", "DrawSwords",
"SliceVertical", "SliceHorizontal", "Dance", "JumpStart", "JumpLoop", "JumpEnd"};
// populate our animation list
for (int i = 0; i < NUM_ANIMS; i++)
{
mAnims[i] = mBodyEnt->getAnimationState(animNames[i]);
mAnims[i]->setLoop(true);
mFadingIn[i] = false;
mFadingOut[i] = false;
}
setBaseAnimation(ANIM_IDLE_BASE);
setTopAnimation(ANIM_IDLE_TOP); mAnims[ANIM_HANDS_RELAXED]->setEnabled(true); mSwordsDrawn = false;
}
void setBaseAnimation(AnimID id, bool reset = false)
{
if (mBaseAnimID >= 0 && mBaseAnimID < NUM_ANIMS)
{
// if we have an old animation, fade it out
mFadingIn[mBaseAnimID] = false;
mFadingOut[mBaseAnimID] = true;
} mBaseAnimID = id; if (id != ANIM_NONE)
{
// if we have a new animation, enable it and fade it in
mAnims[id]->setEnabled(true);
mAnims[id]->setWeight(0);
mFadingOut[id] = false;
mFadingIn[id] = true;
if (reset) mAnims[id]->setTimePosition(0);
}
}
void setTopAnimation(AnimID id, bool reset = false)
{
if (mTopAnimID >= 0 && mTopAnimID < NUM_ANIMS)
{
// if we have an old animation, fade it out
mFadingIn[mTopAnimID] = false;
mFadingOut[mTopAnimID] = true;
} mTopAnimID = id; if (id != ANIM_NONE)
{
// if we have a new animation, enable it and fade it in
mAnims[id]->setEnabled(true);
mAnims[id]->setWeight(0);
mFadingOut[id] = false;
mFadingIn[id] = true;
if (reset) mAnims[id]->setTimePosition(0);
}
}
void updateCamera(Real deltaTime)
{
// place the camera pivot roughly at the character's shoulder
mCameraPivot->setPosition(mBodyNode->getPosition() + Vector3::UNIT_Y * CAM_HEIGHT);
// move the camera smoothly to the goal
Vector3 goalOffset = mCameraGoal->_getDerivedPosition() - mCameraNode->getPosition();
mCameraNode->translate(goalOffset * deltaTime * 9.0f);
// always look at the pivot
mCameraNode->lookAt(mCameraPivot->_getDerivedPosition(), Node::TS_WORLD);
}
void updateBody(Real deltaTime)
{
mGoalDirection = Vector3::ZERO; // we will calculate this if (mKeyDirection != Vector3::ZERO && mBaseAnimID != ANIM_DANCE)
{
// calculate actually goal direction in world based on player's key directions
mGoalDirection += mKeyDirection.z * mCameraNode->getOrientation().zAxis();
mGoalDirection += mKeyDirection.x * mCameraNode->getOrientation().xAxis();
mGoalDirection.y = 0;
mGoalDirection.normalise(); Quaternion toGoal = mBodyNode->getOrientation().zAxis().getRotationTo(mGoalDirection); // calculate how much the character has to turn to face goal direction
Real yawToGoal = toGoal.getYaw().valueDegrees();
// this is how much the character CAN turn this frame
Real yawAtSpeed = yawToGoal / Math::Abs(yawToGoal) * deltaTime * TURN_SPEED;
// reduce "turnability" if we're in midair
if (mBaseAnimID == ANIM_JUMP_LOOP) yawAtSpeed *= 0.2f; // turn as much as we can, but not more than we need to
if (yawToGoal < 0) yawToGoal = std::min<Real>(0, std::max<Real>(yawToGoal, yawAtSpeed)); //yawToGoal = Math::Clamp<Real>(yawToGoal, yawAtSpeed, 0);
else if (yawToGoal > 0) yawToGoal = std::max<Real>(0, std::min<Real>(yawToGoal, yawAtSpeed)); //yawToGoal = Math::Clamp<Real>(yawToGoal, 0, yawAtSpeed); mBodyNode->yaw(Degree(yawToGoal)); // move in current body direction (not the goal direction)
mBodyNode->translate(0, 0, deltaTime * RUN_SPEED * mAnims[mBaseAnimID]->getWeight(),
Node::TS_LOCAL);
} if (mBaseAnimID == ANIM_JUMP_LOOP)
{
// if we're jumping, add a vertical offset too, and apply gravity
mBodyNode->translate(0, mVerticalVelocity * deltaTime, 0, Node::TS_LOCAL);
mVerticalVelocity -= GRAVITY * deltaTime; Vector3 pos = mBodyNode->getPosition();
if (pos.y <= CHAR_HEIGHT)
{
// if we've hit the ground, change to landing state
pos.y = CHAR_HEIGHT;
mBodyNode->setPosition(pos);
setBaseAnimation(ANIM_JUMP_END, true);
mTimer = 0;
}
}
}
void updateAnimations(Real deltaTime)
{
Real baseAnimSpeed = 1;
Real topAnimSpeed = 1; mTimer += deltaTime; if (mTopAnimID == ANIM_DRAW_SWORDS)
{
// flip the draw swords animation if we need to put it back
topAnimSpeed = mSwordsDrawn ? -1 : 1; // half-way through the animation is when the hand grasps the handles...
if (mTimer >= mAnims[mTopAnimID]->getLength() / 2 &&
mTimer - deltaTime < mAnims[mTopAnimID]->getLength() / 2)
{
// so transfer the swords from the sheaths to the hands
mBodyEnt->detachAllObjectsFromBone();
mBodyEnt->attachObjectToBone(mSwordsDrawn ? "Sheath.L" : "Handle.L", mSword1);
mBodyEnt->attachObjectToBone(mSwordsDrawn ? "Sheath.R" : "Handle.R", mSword2);
// change the hand state to grab or let go
mAnims[ANIM_HANDS_CLOSED]->setEnabled(!mSwordsDrawn);
mAnims[ANIM_HANDS_RELAXED]->setEnabled(mSwordsDrawn); // toggle sword trails
if (mSwordsDrawn)
{
mSwordTrail->setVisible(false);
mSwordTrail->removeNode(mSword1->getParentNode());
mSwordTrail->removeNode(mSword2->getParentNode());
}
else
{
mSwordTrail->setVisible(true);
mSwordTrail->addNode(mSword1->getParentNode());
mSwordTrail->addNode(mSword2->getParentNode());
}
} if (mTimer >= mAnims[mTopAnimID]->getLength())
{
// animation is finished, so return to what we were doing before
if (mBaseAnimID == ANIM_IDLE_BASE) setTopAnimation(ANIM_IDLE_TOP);
else
{
setTopAnimation(ANIM_RUN_TOP);
mAnims[ANIM_RUN_TOP]->setTimePosition(mAnims[ANIM_RUN_BASE]->getTimePosition());
}
mSwordsDrawn = !mSwordsDrawn;
}
}
else if (mTopAnimID == ANIM_SLICE_VERTICAL || mTopAnimID == ANIM_SLICE_HORIZONTAL)
{
if (mTimer >= mAnims[mTopAnimID]->getLength())
{
// animation is finished, so return to what we were doing before
if (mBaseAnimID == ANIM_IDLE_BASE) setTopAnimation(ANIM_IDLE_TOP);
else
{
setTopAnimation(ANIM_RUN_TOP);
mAnims[ANIM_RUN_TOP]->setTimePosition(mAnims[ANIM_RUN_BASE]->getTimePosition());
}
} // don't sway hips from side to side when slicing. that's just embarrassing.
if (mBaseAnimID == ANIM_IDLE_BASE) baseAnimSpeed = 0;
}
else if (mBaseAnimID == ANIM_JUMP_START)
{
if (mTimer >= mAnims[mBaseAnimID]->getLength())
{
// takeoff animation finished, so time to leave the ground!
setBaseAnimation(ANIM_JUMP_LOOP, true);
// apply a jump acceleration to the character
mVerticalVelocity = JUMP_ACCEL;
}
}
else if (mBaseAnimID == ANIM_JUMP_END)
{
if (mTimer >= mAnims[mBaseAnimID]->getLength())
{
// safely landed, so go back to running or idling
if (mKeyDirection == Vector3::ZERO)
{
setBaseAnimation(ANIM_IDLE_BASE);
setTopAnimation(ANIM_IDLE_TOP);
}
else
{
setBaseAnimation(ANIM_RUN_BASE, true);
setTopAnimation(ANIM_RUN_TOP, true);
}
}
} // increment the current base and top animation times
if (mBaseAnimID != ANIM_NONE) mAnims[mBaseAnimID]->addTime(deltaTime * baseAnimSpeed);
if (mTopAnimID != ANIM_NONE) mAnims[mTopAnimID]->addTime(deltaTime * topAnimSpeed); // apply smooth transitioning between our animations
fadeAnimations(deltaTime);
}
void fadeAnimations(Real deltaTime)
{
for (int i = 0; i < NUM_ANIMS; i++)
{
if (mFadingIn[i])
{
// slowly fade this animation in until it has full weight
Real newWeight = mAnims[i]->getWeight() + deltaTime * ANIM_FADE_SPEED;
mAnims[i]->setWeight(Math::Clamp<Real>(newWeight, 0, 1));
if (newWeight >= 1) mFadingIn[i] = false;
}
else if (mFadingOut[i])
{
// slowly fade this animation out until it has no weight, and then disable it
Real newWeight = mAnims[i]->getWeight() - deltaTime * ANIM_FADE_SPEED;
mAnims[i]->setWeight(Math::Clamp<Real>(newWeight, 0, 1));
if (newWeight <= 0)
{
mAnims[i]->setEnabled(false);
mFadingOut[i] = false;
}
}
}
} //----按键,鼠标事件处理
void injectKeyDown(const OIS::KeyEvent& evt)
{
if (evt.key == OIS::KC_Q && (mTopAnimID == ANIM_IDLE_TOP || mTopAnimID == ANIM_RUN_TOP))
{
// take swords out (or put them back, since it's the same animation but reversed)
setTopAnimation(ANIM_DRAW_SWORDS, true);
mTimer = 0;
}
else if (evt.key == OIS::KC_E && !mSwordsDrawn)
{
if (mTopAnimID == ANIM_IDLE_TOP || mTopAnimID == ANIM_RUN_TOP)
{
// start dancing
setBaseAnimation(ANIM_DANCE, true);
setTopAnimation(ANIM_NONE);
// disable hand animation because the dance controls hands
mAnims[ANIM_HANDS_RELAXED]->setEnabled(false);
}
else if (mBaseAnimID == ANIM_DANCE)
{
// stop dancing
setBaseAnimation(ANIM_IDLE_BASE);
setTopAnimation(ANIM_IDLE_TOP);
// re-enable hand animation
mAnims[ANIM_HANDS_RELAXED]->setEnabled(true);
}
} // keep track of the player's intended direction
else if (evt.key == OIS::KC_W) mKeyDirection.z = -1;
else if (evt.key == OIS::KC_A) mKeyDirection.x = -1;
else if (evt.key == OIS::KC_S) mKeyDirection.z = 1;
else if (evt.key == OIS::KC_D) mKeyDirection.x = 1; else if (evt.key == OIS::KC_SPACE && (mTopAnimID == ANIM_IDLE_TOP || mTopAnimID == ANIM_RUN_TOP))
{
// jump if on ground
setBaseAnimation(ANIM_JUMP_START, true);
setTopAnimation(ANIM_NONE);
mTimer = 0;
} if (!mKeyDirection.isZeroLength() && mBaseAnimID == ANIM_IDLE_BASE)
{
// start running if not already moving and the player wants to move
setBaseAnimation(ANIM_RUN_BASE, true);
if (mTopAnimID == ANIM_IDLE_TOP) setTopAnimation(ANIM_RUN_TOP, true);
}
}
void injectKeyUp(const OIS::KeyEvent& evt)
{
// keep track of the player's intended direction
if (evt.key == OIS::KC_W && mKeyDirection.z == -1) mKeyDirection.z = 0;
else if (evt.key == OIS::KC_A && mKeyDirection.x == -1) mKeyDirection.x = 0;
else if (evt.key == OIS::KC_S && mKeyDirection.z == 1) mKeyDirection.z = 0;
else if (evt.key == OIS::KC_D && mKeyDirection.x == 1) mKeyDirection.x = 0; if (mKeyDirection.isZeroLength() && mBaseAnimID == ANIM_RUN_BASE)
{
// stop running if already moving and the player doesn't want to move
setBaseAnimation(ANIM_IDLE_BASE);
if (mTopAnimID == ANIM_RUN_TOP) setTopAnimation(ANIM_IDLE_TOP);
}
}
void injectMouseMove(const OIS::MouseEvent& evt)
{
// update camera goal based on mouse movement
updateCameraGoal(-0.05f * evt.state.X.rel, -0.05f * evt.state.Y.rel, -0.0005f * evt.state.Z.rel);
}
void injectMouseDown(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
if (mSwordsDrawn && (mTopAnimID == ANIM_IDLE_TOP || mTopAnimID == ANIM_RUN_TOP))
{
// if swords are out, and character's not doing something weird, then SLICE!
if (id == OIS::MB_Left) setTopAnimation(ANIM_SLICE_VERTICAL, true);
else if (id == OIS::MB_Right) setTopAnimation(ANIM_SLICE_HORIZONTAL, true);
mTimer = 0;
}
} private:
void updateCameraGoal(Real deltaYaw, Real deltaPitch, Real deltaZoom)
{
mCameraPivot->yaw(Degree(deltaYaw), Node::TS_WORLD); // bound the pitch
if (!(mPivotPitch + deltaPitch > 25 && deltaPitch > 0) &&
!(mPivotPitch + deltaPitch < -60 && deltaPitch < 0))
{
mCameraPivot->pitch(Degree(deltaPitch), Node::TS_LOCAL);
mPivotPitch += deltaPitch;
} Real dist = mCameraGoal->_getDerivedPosition().distance(mCameraPivot->_getDerivedPosition());
Real distChange = deltaZoom * dist; // bound the zoom
if (!(dist + distChange < 8 && distChange < 0) &&
!(dist + distChange > 25 && distChange > 0))
{
mCameraGoal->translate(0, 0, distChange, Node::TS_LOCAL);
}
}
}; #endif

ExampleFrameListener.h:帧事件,输入事件监听

#ifndef __ExampleFrameListener_H__
#define __ExampleFrameListener_H__ #include "Ogre.h"
#include "OgreStringConverter.h"
#include "OgreException.h" #define OIS_DYNAMIC_LIB
#include <OIS/OIS.h>
using namespace Ogre; class ExampleApplication; class ExampleFrameListener: public FrameListener, public WindowEventListener,public OIS::KeyListener,
public OIS::MouseListener
{
protected: public: ExampleApplication *eapp; //渲染窗体,输入设备需要
RenderWindow* mWindow; //输入设备
OIS::InputManager* mInputManager;
OIS::Mouse* mMouse;
OIS::Keyboard* mKeyboard; ExampleFrameListener(ExampleApplication *ea,RenderWindow* win, bool bufferedKeys = false, bool bufferedMouse = false,
bool bufferedJoy = false ) :
mWindow(win), mInputManager(0), mMouse(0), mKeyboard(0)
{
eapp = ea;
LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
setupInput();
WindowEventUtilities::addWindowEventListener(mWindow, this);
}
virtual ~ExampleFrameListener()
{
WindowEventUtilities::removeWindowEventListener(mWindow, this);
windowClosed(mWindow);
} //帧事件
bool frameRenderingQueued(const FrameEvent& evt);
bool frameStarted(const FrameEvent& evt)
{
mKeyboard->capture();
mMouse->capture();
return true;
}
bool frameEnded(const FrameEvent& evt)
{
return true;
} //窗口事件
virtual void windowResized(Ogre::RenderWindow* rw)
{
const OIS::MouseState& ms = mMouse->getMouseState();
ms.width = rw->getWidth();
ms.height = rw->getHeight();
}
virtual void windowClosed(RenderWindow* rw)
{
if( rw == mWindow )
{
if( mInputManager )
{
mInputManager->destroyInputObject( mMouse );
mInputManager->destroyInputObject( mKeyboard );
OIS::InputManager::destroyInputSystem(mInputManager);
mInputManager = 0;
}
}
} //安装输入
virtual void setupInput(bool nograb = false)
{
OIS::ParamList pl;
size_t winHandle = 0;
std::ostringstream winHandleStr; mWindow->getCustomAttribute("WINDOW", &winHandle);
winHandleStr << winHandle;
pl.insert(std::make_pair("WINDOW", winHandleStr.str())); if (nograb)
{
pl.insert(std::make_pair("x11_keyboard_grab", "false"));
pl.insert(std::make_pair("x11_mouse_grab", "false"));
pl.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
pl.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
pl.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
pl.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
} mInputManager = OIS::InputManager::createInputSystem(pl); createInputDevices(); // create the specific input devices mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this); windowResized(mWindow); // do an initial adjustment of mouse area } //按键事件
virtual bool keyPressed(const OIS::KeyEvent& evt);
virtual bool keyReleased(const OIS::KeyEvent& evt);
virtual bool mouseMoved(const OIS::MouseEvent& evt);
virtual bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id);
virtual bool mouseReleased(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
//if (mCurrentSample && !mSamplePaused) return mCurrentSample->mouseReleased(evt, id);
return true;
} protected: private:
virtual void createInputDevices()
{
OIS::Object* obj = mInputManager->createInputObject(OIS::OISKeyboard, true);
mKeyboard = static_cast<OIS::Keyboard*>(obj);
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, true)); mKeyboard->setEventCallback(this); mMouse->setEventCallback(this); } }; #endif

ExampleFrameListener.cpp

#include "StdAfx.h"
#include "ExampleApplication.h" bool ExampleFrameListener::frameRenderingQueued(const FrameEvent& evt)
{
if(mWindow->isClosed()) return false;
eapp->update(evt.timeSinceLastFrame);
return true;
} bool ExampleFrameListener::keyPressed(const OIS::KeyEvent& evt)
{
eapp->injectKeyDown(evt);
return true;
} bool ExampleFrameListener::keyReleased(const OIS::KeyEvent& evt)
{
eapp->injectKeyUp(evt);
return true;
} bool ExampleFrameListener::mouseMoved(const OIS::MouseEvent& evt)
{
eapp->injectMouseMove(evt);
return true;
} bool ExampleFrameListener::mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id)
{
eapp->injectMouseDown(evt,id);
return true;
}

Ogre 简易角色Demo的更多相关文章

  1. Maven - settings.xml简易配置Demo

    前言 这里贴一下settings.xml的一个简易配置demo,就是简单配置了:本地的仓库地址.阿里云镜像.指定使用jdk1.8进行编译. 这里使用的Maven是3.5.0版本的. 配置文件demo ...

  2. Node.js学习之(第三章:简易小demo)

    前言 我们前面已经学习完了Node中一些核心模块还有如何正确配置响应头的Content-Type,今天我们来实现一个简单的demo,巩固下之前学习的内容. 需求 我们平时访问百度或者其他大的门户网站的 ...

  3. 使用angular.js开发的一个简易todo demo

    前沿 在CVTE实习考察的一周里,接触到了angular,并在最后的一天任务里要求使用angular做一个功能主要包括创建.编辑.恢复.删除以及留言的todo demo,并支持响应式布局.因为之前没怎 ...

  4. spring boot 对某个接口进行次数限制,防刷。简易版。demo。

    一般的项目 如果没有做防刷 容易被人爆接口 或者就是说没有做token防刷过滤. 容易被人用正常的token刷接口.有些token非一次性. 用户登录之后生成token会有一个过期时间,但一般没有做频 ...

  5. 微信小程序导航:官方工具+精品教程+DEMO集合(1月7更新)

    1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=14764346784612:简易教程:https://mp.weixin.qq.com/debug ...

  6. spring security入门demo

    一.前言 因项目需要引入spring security权限框架,而之前也没接触过这个一门,于是就花了点时间弄了个小demo出来,说实话,刚开始接触这个确实有点懵,看网上资料写的权限大都是静态,即就是在 ...

  7. 我做的一个websocket的demo(php server)

    notice: 通过命令行执行php文件  如 php -q c:\path\server.php 通过本地web服务器访问 http://127.0.0.1/websocket/index.php即 ...

  8. 一个websocket的demo(php server)

    notice: 通过命令行执行php文件  如 php -q c:\path\server.php 通过本地web服务器访问 http://127.0.0.1/websocket/index.php即 ...

  9. Asp.Net Core 中IdentityServer4 实战之角色授权详解

    一.前言 前几篇文章分享了IdentityServer4密码模式的基本授权及自定义授权等方式,最近由于改造一个网关服务,用到了IdentityServer4的授权,改造过程中发现比较适合基于Role角 ...

随机推荐

  1. 关于wpf中popup跟随鼠标移动显示

    最近在做一个画图工具,里面有一个功能是需要实现,当鼠标移动的时候在,鼠标的旁边显示坐标信息. 第一反应是想到了tooltip,但是tooltip有许多的限制,查询资料的过程中看到了popup,popu ...

  2. unity3d从零開始(五):了解摄像机

    1.简单介绍         Unity的摄像机是用来将游戏世界呈现给玩家的,游戏场景中至少有一台摄像机.也能够有多台. 2.类型         Unity中支持两种类型的摄像机,各自是Perspe ...

  3. 虚拟化(五):vsphere高可用群集与容错(存储DRS是一种可用于将多个数据存储作为单个数据存储群集进行管理的功能)

    vsphere高级功能需要vcenter server和共享存储的支持才能实现.vsphere的高级功能有 vmotion.storage vmotion.vsphere HA.vsphere DRS ...

  4. HttpURLConnection访问网络

    HttpURLConnection是一个抽象类,获取HttpURLConnection对象HttpURLConnection urlConnection=new URL(http://www.baid ...

  5. 怎样把word直接转换成ppt

  6. 剑指Offer:重建二叉树【7】

    剑指Offer:重建二叉树[7] 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5 ...

  7. go 客户端服务端通信

    client.go package main import ( "bufio" "encoding/json" "fmt" "ha ...

  8. HDU-2255(KM算法)

    HDU-2255 题目意思转化之后就是,给你一个二分图(也称 二部图) ,要求选择一些边让左边的点都对应左边的某一个点!该问题也叫做二分图最大匹配.所以可以用KM算法来做这道题.KM前提你要理解匈牙利 ...

  9. reactjs的一些笔记

    1.使用虚拟DOM作为其不同的实现.同时可以由服务器node.js渲染,从而不需要过重的浏览器DOM支持.   2.虚拟DOM:在浏览器端用javascript实现了一套DOM API.用react开 ...

  10. 点分治 [IOI2011]Race

    BZOJ2599. 放板子.利用agc009-D 代码简洁了很多 #include <bits/stdc++.h> #define N 200005 using namespace std ...