📄 animblender.h
字号:
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2005 The OGRE Team
Also see acknowledgements in Readme.html
You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.
-----------------------------------------------------------------------------
*/
/*
-----------------------------------------------------------------------------
Filename: AnimBlender.h
Description: A place for me to try out stuff with OGRE.
-----------------------------------------------------------------------------
*/
#ifndef __AnimBlender_h_
#define __AnimBlender_h_
#include "ExampleApplication.h"
#include "..\AnimationBlender.h"
AnimationBlender * blender;
class AnimBlenderFrameListener : public ExampleFrameListener
{
private:
SceneManager* mSceneMgr;
public:
AnimBlenderFrameListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam),
mSceneMgr(sceneMgr)
{
}
bool frameStarted(const FrameEvent& evt)
{
bool ret = ExampleFrameListener::frameStarted(evt);
blender->addTime(evt.timeSinceLastFrame);
return ret;
}
//覆盖父类的键盘输入函数
virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
{
if (mInputDevice->isKeyDown(KC_T))
{
blender->blend("Attack1",AnimationBlender::BlendWhileAnimating,1.0,false);
}
if (mInputDevice->isKeyDown(KC_J))
{
blender->blend("Jump",AnimationBlender::BlendWhileAnimating,1.0,false);
}
if (mInputDevice->isKeyDown(KC_I))
{
blender->blend("Idle1",AnimationBlender::BlendWhileAnimating,1.0,false);
}
//记得调用父类的键盘处理,以使WASD仍然可用
return ExampleFrameListener::processUnbufferedKeyInput(evt);
}
};
class AnimBlenderApp : public ExampleApplication
{
public:
AnimBlenderApp()
{}
~AnimBlenderApp()
{
}
protected:
virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,0,180));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,-300));
mCamera->setNearClipDistance(5);
}
// Just override the mandatory create scene method
virtual void createScene(void)
{
Entity* ninjaHead = mSceneMgr->createEntity("ninja", "ninja.mesh");
SceneNode* ninjaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
ninjaNode->attachObject(ninjaHead);
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
//实例化一个blender并将Entity传入
blender=new AnimationBlender(ninjaHead);
//设置一个初始动作
blender->init("Idle1");
}
// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new AnimBlenderFrameListener(mSceneMgr, mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};
#endif // #ifndef __AnimBlender_h_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -