#include <Ogre.h>
#include <OgreApplicationContext.h>
using namespace Ogre;
class MyTestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
MyTestApp();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
private:
bool frameRenderingQueued(const Ogre::FrameEvent& evt);
Ogre::AnimationState* mAnimationState;
};
//! [constructor]
MyTestApp::MyTestApp() : OgreBites::ApplicationContext("OgreTutorialApp")
{
}
//! [constructor]
//! [key_handler]
bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
return true;
}
//! [key_handler]
//! [setup]
void MyTestApp::setup(void)
{
// do not forget to call the base first
OgreBites::ApplicationContext::setup();
// register for input events
addInputListener(this);
// get a pointer to the already created root
Ogre::Root* root = getRoot();
Ogre::SceneManager* scnMgr = root->createSceneManager();
// register our scene with the RTSS
Ogre::RTShader::ShaderGenerator* shadergen = Ogre::RTShader::ShaderGenerator::getSingletonPtr();
shadergen->addSceneManager(scnMgr);
// set shadow properties
// scnMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
// scnMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
// scnMgr->setShadowTextureSize(1024);
// scnMgr->setShadowTextureCount(1);
//! [lightingsset]
scnMgr->setAmbientLight(ColourValue(0, 0, 0));
scnMgr->setShadowTechnique(ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
// without light we would just get a black screen
Ogre::Light* light = scnMgr->createLight("MainLight");
Ogre::SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(10, 20, 15);
lightNode->attachObject(light);
// also need to tell where we are
Ogre::SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
//camNode->setPosition(0, 0, 15);
//camNode->lookAt(Ogre::Vector3(0, 0, -1), Ogre::Node::TS_PARENT);
camNode->setPosition(0, 8, 30);
camNode->lookAt(Vector3(0, 0, 0), Node::TransformSpace::TS_WORLD);
// create the camera
Ogre::Camera* cam = scnMgr->createCamera("myCam");
cam->setNearClipDistance(5); // specific to this sample
//cam->setAutoAspectRatio(true);
camNode->attachObject(cam);
// and tell it to render into the main window
//getRenderWindow()->addViewport(cam);
//! [addviewport]
Viewport* vp = getRenderWindow()->addViewport(cam);
//! [addviewport]
//! [viewportback]
vp->setBackgroundColour(ColourValue(0, 0, 0));
//! [viewportback]
//! [cameraratio]
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
// finally something to render
Ogre::Entity* ent = scnMgr->createEntity("Sinbad.mesh");
Ogre::SceneNode* node = scnMgr->getRootSceneNode()->createChildSceneNode(Vector3::UNIT_Y * 5);
node->attachObject(ent);
// create a floor mesh resource
Ogre::MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Plane(Vector3::UNIT_Y, 0), 100, 100, 20, 20, true, 1, 5, 5, Vector3::UNIT_Z);
// create a floor entity, give it a material, and place it at the origin
Entity* floor = scnMgr->createEntity("Floor", "floor");
floor->setMaterialName("Examples/Rockwall");
floor->setCastShadows(false);
scnMgr->getRootSceneNode()->attachObject(floor);
mAnimationState = ent->getAnimationState("Dance");
mAnimationState->setEnabled(true);
mAnimationState->setLoop(true);
}
//! [setup]
bool MyTestApp::frameRenderingQueued(const Ogre::FrameEvent& evt) {
mAnimationState->addTime(evt.timeSinceLastFrame);
return true;
}
//! [main]
int main(int argc, char *argv[])
{
MyTestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return 0;
}
//! [main]
Tutorial1: Animation
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 还可以参考这篇:http://www.cnblogs.com/shenfangfang/p/5713564.htm...
- Animate a number (ex: position, opacity, scale) using a s...
- 前言 在游戏开发过程中,动画是一个不可或缺的环节,没有动画变换的人物并不能带给玩家很好的代入感,而Unity作为一...
- UIView Animation 简单动画 对于 UIView 上简单的动画,iOS 提供了很方便的函数: 第一个...
- 本周读Byron Barton的My Bus~主人公 Joe将给大家介绍他的公共汽车. 在读之前,我们来总结下关于...