1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | You may use this sample code for anything you like, it is not covered by the
|
---|
11 | LGPL like the rest of the engine.
|
---|
12 | -----------------------------------------------------------------------------
|
---|
13 | */
|
---|
14 |
|
---|
15 | /**
|
---|
16 | \file
|
---|
17 | SkyBox.h
|
---|
18 | \brief
|
---|
19 | Specialisation of OGRE's framework application to show the
|
---|
20 | skybox feature where a wrap-around environment is projected
|
---|
21 | onto a cube around the camera.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "ExampleApplication.h"
|
---|
25 |
|
---|
26 | ParticleSystem *pThrusters;
|
---|
27 |
|
---|
28 | class SkyBoxFrameListener : public ExampleFrameListener
|
---|
29 | {
|
---|
30 | private:
|
---|
31 | static float fDefDim;
|
---|
32 | static float fDefVel;
|
---|
33 |
|
---|
34 | public:
|
---|
35 | SkyBoxFrameListener(RenderWindow* win, Camera* cam) : ExampleFrameListener( win, cam )
|
---|
36 | {
|
---|
37 | }
|
---|
38 |
|
---|
39 | bool frameStarted( const FrameEvent& evt )
|
---|
40 | {
|
---|
41 | bool bOK = ExampleFrameListener::frameStarted( evt );
|
---|
42 |
|
---|
43 | if( mInputDevice->isKeyDown( KC_N ) )
|
---|
44 | {
|
---|
45 | pThrusters->setDefaultDimensions( fDefDim + 0.25, fDefDim + 0.25 );
|
---|
46 | fDefDim += 0.25;
|
---|
47 | }
|
---|
48 |
|
---|
49 | if( mInputDevice->isKeyDown( KC_M ) )
|
---|
50 | {
|
---|
51 | pThrusters->setDefaultDimensions( fDefDim - 0.25, fDefDim - 0.25 );
|
---|
52 | fDefDim -= 0.25;
|
---|
53 | }
|
---|
54 |
|
---|
55 | if( mInputDevice->isKeyDown( KC_H ) )
|
---|
56 | {
|
---|
57 | pThrusters->getEmitter( 0 )->setParticleVelocity( fDefVel + 1 );
|
---|
58 | pThrusters->getEmitter( 1 )->setParticleVelocity( fDefVel + 1 );
|
---|
59 | fDefVel += 1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | if( mInputDevice->isKeyDown( KC_J ) && !( fDefVel < 0.0f ) )
|
---|
63 | {
|
---|
64 | pThrusters->getEmitter( 0 )->setParticleVelocity( fDefVel - 1 );
|
---|
65 | pThrusters->getEmitter( 1 )->setParticleVelocity( fDefVel - 1 );
|
---|
66 | fDefVel -= 1;
|
---|
67 | }
|
---|
68 |
|
---|
69 | return bOK;
|
---|
70 | }
|
---|
71 | };
|
---|
72 |
|
---|
73 | float SkyBoxFrameListener::fDefDim = 25.0f;
|
---|
74 | float SkyBoxFrameListener::fDefVel = 50.0f;
|
---|
75 |
|
---|
76 | class SkyBoxApplication : public ExampleApplication
|
---|
77 | {
|
---|
78 | public:
|
---|
79 | SkyBoxApplication() {}
|
---|
80 |
|
---|
81 | protected:
|
---|
82 | virtual void createFrameListener(void)
|
---|
83 | {
|
---|
84 | mFrameListener= new SkyBoxFrameListener(mWindow, mCamera);
|
---|
85 | mRoot->addFrameListener(mFrameListener);
|
---|
86 | }
|
---|
87 |
|
---|
88 | // Just override the mandatory create scene method
|
---|
89 | void createScene(void)
|
---|
90 | {
|
---|
91 | // Set ambient light
|
---|
92 | mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
|
---|
93 |
|
---|
94 | // Create a skybox
|
---|
95 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 50 );
|
---|
96 |
|
---|
97 | // Create a light
|
---|
98 | Light* l = mSceneMgr->createLight("MainLight");
|
---|
99 | // Accept default settings: point light, white diffuse, just set position
|
---|
100 | // NB I could attach the light to a SceneNode if I wanted it to move automatically with
|
---|
101 | // other objects, but I don't
|
---|
102 | l->setPosition(20,80,50);
|
---|
103 |
|
---|
104 | // Also add a nice starship in
|
---|
105 | Entity *ent = mSceneMgr->createEntity( "razor", "razor.mesh" );
|
---|
106 |
|
---|
107 | mSceneMgr->getRootSceneNode()->attachObject( ent );
|
---|
108 |
|
---|
109 | pThrusters = mSceneMgr->createParticleSystem( "ParticleSys1", 200 );
|
---|
110 |
|
---|
111 | pThrusters ->setMaterialName( "Examples/Flare" );
|
---|
112 | pThrusters ->setDefaultDimensions( 25, 25 );
|
---|
113 |
|
---|
114 | ParticleEmitter *pEmit1 = pThrusters ->addEmitter( "Point" );
|
---|
115 | ParticleEmitter *pEmit2 = pThrusters ->addEmitter( "Point" );
|
---|
116 |
|
---|
117 | // Thruster 1
|
---|
118 | pEmit1->setAngle( Degree(3) );
|
---|
119 | pEmit1->setTimeToLive( 0.2 );
|
---|
120 | pEmit1->setEmissionRate( 70 );
|
---|
121 |
|
---|
122 | pEmit1->setParticleVelocity( 50 );
|
---|
123 |
|
---|
124 | pEmit1->setDirection(- Vector3::UNIT_Z);
|
---|
125 | pEmit1->setColour( ColourValue::White, ColourValue::Red);
|
---|
126 |
|
---|
127 | // Thruster 2
|
---|
128 | pEmit2->setAngle( Degree(3) );
|
---|
129 | pEmit2->setTimeToLive( 0.2 );
|
---|
130 | pEmit2->setEmissionRate( 70 );
|
---|
131 |
|
---|
132 | pEmit2->setParticleVelocity( 50 );
|
---|
133 |
|
---|
134 | pEmit2->setDirection( -Vector3::UNIT_Z );
|
---|
135 | pEmit2->setColour( ColourValue::White, ColourValue::Red );
|
---|
136 |
|
---|
137 | // Set the position of the thrusters
|
---|
138 | pEmit1->setPosition( Vector3( 5.7f, 0.0f, 0.0f ) );
|
---|
139 | pEmit2->setPosition( Vector3( -18.0f, 0.0f, 0.0f ) );
|
---|
140 |
|
---|
141 | mSceneMgr->getRootSceneNode()->createChildSceneNode( Vector3( 0.0f, 6.5f, -67.0f ) )
|
---|
142 | ->attachObject(pThrusters);
|
---|
143 | }
|
---|
144 |
|
---|
145 | };
|
---|