Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/SkyBox/include/SkyBox.h @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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