OGER SDK研究之四 Demo_SkyBox 天空盒
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OGER SDK研究之四 Demo_SkyBox 天空盒相关的知识,希望对你有一定的参考价值。
SkyBox.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-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.htmlYou may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.-----------------------------------------------------------------------------
*//**
/file
SkyBox.h 天空盒
/brief
Specialisation of OGREs framework application to show the
skybox feature where a wrap-around environment is projected
onto a cube around the camera.
//加入一个天空盒
*/#include "ExampleApplication.h"
ParticleSystem *pThrusters; //粒子系统
class SkyBoxFrameListener : public ExampleFrameListener
private:
static float fDefDim;
static float fDefVel;public:
SkyBoxFrameListener(RenderWindow* win, Camera* cam) : ExampleFrameListener( win, cam )
//每一帧开始前的处理
bool frameStarted( const FrameEvent& evt )
if( ExampleFrameListener::frameStarted( evt ) == false )
return false; if( mKeyboard->isKeyDown( OIS::KC_N ) )
//如果按键N 设置粒子系统的尺寸增大
pThrusters->setDefaultDimensions( fDefDim + 0.25, fDefDim + 0.25 );
fDefDim += 0.25;
if( mKeyboard->isKeyDown( OIS::KC_M ) )
//如果按键M 设置粒子系统的尺寸减小
pThrusters->setDefaultDimensions( fDefDim - 0.25, fDefDim - 0.25 );
fDefDim -= 0.25;
if( mKeyboard->isKeyDown( OIS::KC_H ) )
//如果按键H 设置粒子系统的速度增加
pThrusters->getEmitter( 0 )->setParticleVelocity( fDefVel + 1 );
pThrusters->getEmitter( 1 )->setParticleVelocity( fDefVel + 1 );
fDefVel += 1;
if( mKeyboard->isKeyDown( OIS::KC_J ) && !( fDefVel < 0.0f ) )
//如果按键J 设置粒子系统的速度减缓
pThrusters->getEmitter( 0 )->setParticleVelocity( fDefVel - 1 );
pThrusters->getEmitter( 1 )->setParticleVelocity( fDefVel - 1 );
fDefVel -= 1;
return true;
;float SkyBoxFrameListener::fDefDim = 25.0f;
float SkyBoxFrameListener::fDefVel = 50.0f;class SkyBoxApplication : public ExampleApplication
public:
SkyBoxApplication() protected:
virtual void createFrameListener(void)
//创建自定义帧监听器并连接
mFrameListener= new SkyBoxFrameListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
// Just override the mandatory create scene method
// 创建场景
void createScene(void)
// Set ambient light
// 设置环境光
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5)); // Create a skybox
// 设置天空盒
mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 50 ); // Create a light
// 创建一个灯光
Light* l = mSceneMgr->createLight("MainLight");
// Accept default settings: point light, white diffuse, just set position
// NB I could attach the light to a SceneNode if I wanted it to move automatically with
// other objects, but I dont
//设置自创建灯光的位置
l->setPosition(20,80,50); // Also add a nice starship in
// 由模型文件创建一个实体
Entity *ent = mSceneMgr->createEntity( "razor", "razor.mesh" ); //将实体加入到主场景中
mSceneMgr->getRootSceneNode()->attachObject( ent ); //创建一个粒子系统
pThrusters = mSceneMgr->createParticleSystem( "ParticleSys1", 200 ); //设置粒子系统的材质
pThrusters ->setMaterialName( "Examples/Flare" );
//设置粒子的大小
pThrusters ->setDefaultDimensions( 25, 25 ); //创建两个点粒子发射器
ParticleEmitter *pEmit1 = pThrusters ->addEmitter( "Point" );
ParticleEmitter *pEmit2 = pThrusters ->addEmitter( "Point" ); // Thruster 1
//第一发射器参数设置(角度,生命时长,衰减速率,运动速度,方向,色彩)
pEmit1->setAngle( Degree(3) );
pEmit1->setTimeToLive( 0.2 );
pEmit1->setEmissionRate( 70 );
pEmit1->setParticleVelocity( 50 ); pEmit1->setDirection(- Vector3::UNIT_Z);
pEmit1->setColour( ColourValue::White, ColourValue::Red); // Thruster 2
//第二发射器参数设置(角度,生命时长,衰减速率,运动速度,方向,色彩)
pEmit2->setAngle( Degree(3) );
pEmit2->setTimeToLive( 0.2 );
pEmit2->setEmissionRate( 70 ); pEmit2->setParticleVelocity( 50 );
pEmit2->setDirection( -Vector3::UNIT_Z );
pEmit2->setColour( ColourValue::White, ColourValue::Red ); // Set the position of the thrusters
//设置发射器的位置
pEmit1->setPosition( Vector3( 5.7f, 0.0f, 0.0f ) );
pEmit2->setPosition( Vector3( -18.0f, 0.0f, 0.0f ) ); //将粒子系统加入到场景中
mSceneMgr->getRootSceneNode()->createChildSceneNode( Vector3( 0.0f, 6.5f, -67.0f ) )
->attachObject(pThrusters);
;
SkyBox.cpp:
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.htmlYou may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.
-----------------------------------------------------------------------------
*//**
/file
SkyBox.cpp
/brief
Shows OGREs skybox feature where a wrap-around environment is projected
onto a cube around the camera.
*/#include "SkyBox.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif#ifdef __cplusplus
extern "C"
#endif#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
// Create application object
SkyBoxApplication app; try
app.go();
catch( Ogre::Exception& e )
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
return 0;
#ifdef __cplusplus
#endif
以上是关于OGER SDK研究之四 Demo_SkyBox 天空盒的主要内容,如果未能解决你的问题,请参考以下文章
Oracle Spatial分区应用研究之四:不同分区粒度+全局空间索引效率对比