#include <string>
#include "ExampleApplication.h"
class Example25FrameListener:public Ogre::FrameListener
{
public:
Example25FrameListener(Ogre::SceneNode* node,RenderWindow* win,Ogre::Camera* cam,Ogre::Entity* ent):
_node(node),_cam(cam),_PolygonMode(Ogre::PolygonMode::PM_SOLID),_ent(ent),_WalkingSpeed(50.0f),_rotation(0.0f)
{
size_t windowHnd=0;
std::stringstream windowHndStr;
win->getCustomAttribute("WINDOW",&windowHnd);
windowHndStr<<windowHnd;
OIS::ParamList pl;
pl.insert(std::make_pair(std::string("WINDOW"),windowHndStr.str()));
_man=OIS::InputManager::createInputSystem(pl);
_key=static_cast<OIS::Keyboard*>(_man->createInputObject(OIS::OISKeyboard,false));
_mouse=static_cast<OIS::Mouse*>(_man->createInputObject(OIS::OISMouse,false));
bRPressed=false;
_aniState=_ent->getAnimationState("RunBase");
_aniState->setLoop(false);
_aniStateTop=_ent->getAnimationState("RunTop");
_aniStateTop->setLoop(false);
}
~Example25FrameListener()
{
_man->destroyInputObject(_key);
_man->destroyInputObject(_mouse);
OIS::InputManager::destroyInputSystem(_man);
}
bool frameStarted(const Ogre::FrameEvent& evt)
{
bool walked=false;
Ogre::Vector3 SinbadTranslate(0,0,0);
_key->capture();
if(_key->isKeyDown(OIS::KC_ESCAPE))
return false;
if(_key->isKeyDown(OIS::KC_UP))
{
SinbadTranslate+=Ogre::Vector3(0,0,-1);
_rotation=3.14f;
walked=true;
}
if(_key->isKeyDown(OIS::KC_DOWN))
{
SinbadTranslate+=Ogre::Vector3(0,0,1);
_rotation=0.0f;
walked=true;
}
if(_key->isKeyDown(OIS::KC_LEFT))
{
SinbadTranslate+=Ogre::Vector3(-1,0,0);
_rotation=-1.57f;
walked=true;
}
if(_key->isKeyDown(OIS::KC_RIGHT))
{
SinbadTranslate+=Ogre::Vector3(1,0,0);
_rotation=1.57f;
walked=true;
}
Ogre::Vector3 translate=Ogre::Vector3(0,0,0);
Real Speed=1;
if(_key->isKeyDown(OIS::KC_LSHIFT))
{
Speed=10;
}
if(_key->isKeyDown(OIS::KC_W))
{
translate+=Ogre::Vector3(0,0,-10);
}
if(_key->isKeyDown(OIS::KC_S))
{
translate+=Ogre::Vector3(0,0,10);
}
if(_key->isKeyDown(OIS::KC_A))
{
translate+=Ogre::Vector3(-10,0,0);
}
if(_key->isKeyDown(OIS::KC_D))
{
translate+=Ogre::Vector3(10,0,0);
}
if(_key->isKeyDown(OIS::KC_LCONTROL) && _key->isKeyDown(OIS::KC_C))
translate+=Ogre::Vector3(0,10,0);
if(_key->isKeyDown(OIS::KC_R) && !bRPressed)
{
bRPressed=true;
if(_PolygonMode==PM_SOLID)
_PolygonMode=Ogre::PolygonMode::PM_WIREFRAME;
else if(_PolygonMode==PM_WIREFRAME)
_PolygonMode=Ogre::PolygonMode::PM_POINTS;
else if(_PolygonMode==PM_POINTS)
_PolygonMode=Ogre::PolygonMode::PM_SOLID;
}
if(bRPressed && !_key->isKeyDown(OIS::KC_R))
bRPressed=false;
_mouse->capture();
float rotX=_mouse->getMouseState().X.rel*evt.timeSinceLastFrame*-1;
float rotY=_mouse->getMouseState().Y.rel*evt.timeSinceLastFrame*-1;
_cam->yaw(Ogre::Radian(rotX));
_cam->pitch(Ogre::Radian(rotY));
_cam->moveRelative(translate*evt.timeSinceLastFrame*Speed);
_cam->setPolygonMode(_PolygonMode);
if(walked)
{
_aniState->setEnabled(true);
_aniStateTop->setEnabled(true);
if(_aniState->hasEnded())
_aniState->setTimePosition(0.0f);
if(_aniStateTop->hasEnded())
_aniStateTop->setTimePosition(0.0f);
}
else
{
_aniState->setTimePosition(0.0f);
_aniState->setEnabled(false);
_aniStateTop->setTimePosition(0.0f);
_aniStateTop->setEnabled(false);
}
_aniState->addTime(evt.timeSinceLastFrame);
_aniStateTop->addTime(evt.timeSinceLastFrame);
_node->translate(SinbadTranslate*evt.timeSinceLastFrame*_WalkingSpeed);
_node->resetOrientation();
_node->yaw(Ogre::Radian(_rotation));
return true;
}
private:
Ogre::SceneNode* _node;
OIS::InputManager* _man;
OIS::Keyboard* _key;
Ogre::Camera* _cam;
OIS::Mouse* _mouse;
Ogre::PolygonMode _PolygonMode;
bool bRPressed;
Ogre::Entity* _ent;
Ogre::AnimationState* _aniState;
Ogre::AnimationState* _aniStateTop;
float _WalkingSpeed;
float _rotation;
};
class Example1:public ExampleApplication
{
public:
Example1()
{
FrameListener=NULL;
}
~Example1()
{
if(FrameListener)
{
delete FrameListener;
}
}
void createScene()
{
Ogre::Plane plane(Vector3::UNIT_Y,-10);
Ogre::MeshManager::getSingleton().createPlane("planemesh",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,plane,1500,1500,200,200,true,1,5,5,Vector3::UNIT_Z);
Ogre::Entity* LightPlane=mSceneMgr->createEntity("LightPlane","planemesh");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(LightPlane);
LightPlane->setMaterialName("Examples/BeachStones");
Ogre::Light* DirectionalLight=mSceneMgr->createLight("MyDirectionalLight");
DirectionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
DirectionalLight->setDirection(Ogre::Vector3(1,-1,0));
Ogre::SceneNode* SubNodeRoot=mSceneMgr->getRootSceneNode()->createChildSceneNode("SubNodeRoot");
_SinbadEnt=mSceneMgr->createEntity("Sinbad","Sinbad.mesh");
_SinbadNode=SubNodeRoot->createChildSceneNode("SinbadNode");
_SinbadNode->setPosition(Ogre::Vector3(0.0f,4.0f,0.0f));
_SinbadNode->setScale(3.0f,3.0f,3.0f);
_SinbadNode->attachObject(_SinbadEnt);
//1 begin
/*
Ogre::ParticleSystem* partSystem=mSceneMgr->createParticleSystem("Smoke","Examples/Smoke");
_SinbadNode->attachObject(partSystem);*/
//1 end
//2|1 begin
/*Ogre::ParticleSystem* partSystem=mSceneMgr->createParticleSystem("Smoke","MySmoke1");
_SinbadNode->attachObject(partSystem);
*/
//2|1 end
//15|2 begin
Ogre::ParticleSystem* partSystem1=mSceneMgr->createParticleSystem("Firework1","Firework");
Ogre::ParticleSystem* partSystem2=mSceneMgr->createParticleSystem("Firework2","Firework");
Ogre::ParticleSystem* partSystem3=mSceneMgr->createParticleSystem("Firework3","Firework");
Ogre::ParticleSystem* partSystem4=mSceneMgr->createParticleSystem("Firework4","Firework");
Ogre::ParticleSystem* partSystem5=mSceneMgr->createParticleSystem("Firework5","Firework");
Ogre::SceneNode* node1=mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,10,0));
Ogre::SceneNode* node2=mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(10,11,0));
Ogre::SceneNode* node3=mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(20,9,0));
Ogre::SceneNode* node4=mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-10,11,0));
Ogre::SceneNode* node5=mSceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(-20,19,0));
node1->attachObject(partSystem1);
node2->attachObject(partSystem2);
node3->attachObject(partSystem3);
node4->attachObject(partSystem4);
node5->attachObject(partSystem5);
//15|2 end
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
Ogre::Entity* sword1=mSceneMgr->createEntity("Sword1","Sword.mesh");
Ogre::Entity* sword2=mSceneMgr->createEntity("Sword2","Sword.mesh");
_SinbadEnt->attachObjectToBone("Handle.L",sword1);
_SinbadEnt->attachObjectToBone("Handle.R",sword2);
}
void createCamera()
{
mCamera=mSceneMgr->createCamera("MyCamera1");
mCamera->setPosition(Ogre::Vector3(0,100,200));
mCamera->lookAt(0,0,0);
mCamera->setNearClipDistance(5);
}
void createFrameListener()
{
FrameListener=new Example25FrameListener(_SinbadNode,mWindow,mCamera,_SinbadEnt);
mRoot->addFrameListener(FrameListener);
}
private:
Ogre::SceneNode* _SinbadNode;
Ogre::FrameListener* FrameListener;
Ogre::Entity* _SinbadEnt;
};
int main()
{
Example1 app;
app.go();
return 0;
}
Seamanj_Ogre3DBeginnersGuide.particle 文件
particle_system MySmoke1
{
material Examples/Smoke
particle_width 10
particle_height 10
quota 500//到最大粒子数时,发射器将不再发射粒子
billboard_type point
//0.1 begin
//emitter Point
//{
emission_rate 3
direction 1 0 0
velocity 20
//3 begin
//angle 30
//time_to_live 10
//The parameter time_to_live sets the lifetime of each particle.The default is 5.
//colour 1 0 0 1
//3 end
//4|3 begin
//angle 30
//time_to_live_min 1
//time_to_live_max 10
//colour_range_start 1 0 0
//colour_range_end 0 0 1
//4|3 end
//5|4 begin
//duration 1//持续发射时间
//repeat_delay 1//离下一次发射的间隔时间
//5|4 end
//}
//0.1 end
//6|0.1 begin
/*emitter Point
{
emission_rate 30
direction 1 0 0
velocity 20
time_to_live 100
}*/
//6|0.1 end
//6.1 begin
/*
affector Scaler
{
rate 5//粒子每秒变大5倍
}
*/
//6.1 end
//7|6.1 begin
/*affector ColourFader//注意affector的名字不能随便变
{
red -0.25
green -0.25
blue -0.25
}*/
//7|6.1 end
//8|7 begin
/*affector ColourFader
{
green -0.25
blue -0.25
}*/
//8|7 end
//9|all begin
/*emitter Point
{
emission_rate 30
direction 1 0 0
velocity 20
time_to_live 4
}*/
//9.1 begin
/*affector ColourFader2
{
red1 -1
green1 -1
blue1 -1
state_change 2
red2 +1
green2 +1
blue2 +1
}*/
//9.1 end
//9|allend
//10|9.1 begin
affector ColourInterpolator
{
time0 0//timeX and ColorX,where X must between 0 and 5
colour0 1 1 1
time1 0.25
colour1 1 0 0
time2 0.5
colour2 0 1 0
time3 0.75
colour3 0 0 1
time4 1
colour4 1 1 1
}
//10|9.1 end
//11|10 begin
/*affector DirectionRandomiser
{
randomness 100
scope 1//how many of our particles should be affected each time the affector is applied.
//1.0 stands for 100 percent and 0 for 0 percent.
keep_velocity true
}*/
//11|10 end
//12|all begin 平面反弹
/*emitter Point
{
emission_rate 30
direction 0 1 0
velocity 20
time_to_live 4
angle 30
}
affector DeflectorPlane
{
plane_point 0 20 0
plane_normal 0 -1 0
bounce 1.0
}*/
//12|all end
//13_10|12 begin 盒子发射器
/*emitter Box
{
height 50
width 50
depth 50
emission_rate 10
direction 0 1 0
velocity 20
}*/
//13_10|12 end
//14_10|13 begin 环发射器
emitter Ring
{
//Ring的椭圆长宽的最大值
height 50
width 50
//内部部分不发射粒子区域百分比
inner_height 0.9
inner_width 0.9
emission_rate 10
direction 0 1 0
velocity 20
}
//14_10|13 end
}
//15 begin
particle_system Firework
{
material Examples/Smoke
particle_width 10
particle_height 10
quota 500
billboard_type point
emitter Point
{
emission_rate 100
direction 0 0 -1
velocity 50
angle 30
duration 0.1
repeat_delay 1
colour_range_start 0 0 0
colour_range_end 1 1 1
}
}
//15 end
此时这本书顺利完成,最后放点烟花庆祝一下