Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/SkyDome/include/SkyDome.h @ 3

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

=update

File size: 4.1 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        SkyDome.h
18    \brief
19        Specialisation of OGRE's framework application to show the
20        skydome feature
21*/
22
23
24#include "ExampleApplication.h"
25
26// Event handler to add ability to alter curvature
27class SkyDomeFrameListener : public ExampleFrameListener
28{
29protected:
30    Real mCurvature;
31    Real mTiling;
32    SceneManager* mSceneMgr;
33public:
34    SkyDomeFrameListener(RenderWindow* win, Camera* cam, SceneManager* mgr)
35        : ExampleFrameListener(win, cam)
36    {
37        mSceneMgr = mgr;
38        mCurvature = 1;
39        mTiling = 15;
40
41    }
42
43    bool frameStarted(const FrameEvent& evt)
44    {
45        // Change curvature / tiling
46        // Delay timer to stop too quick updates of curvature
47        static Real timeDelay = 0;
48
49        bool updateSky;
50        updateSky = false;
51       
52        if(!ExampleFrameListener::frameStarted(evt))
53            return false;
54       
55        if (mKeyboard->isKeyDown(OIS::KC_H) && timeDelay <= 0)
56        {
57            mCurvature += 1;
58            timeDelay = 0.1;
59            updateSky = true;
60        }
61        if (mKeyboard->isKeyDown(OIS::KC_G) && timeDelay <= 0)
62        {
63            mCurvature -= 1;
64            timeDelay = 0.1;
65            updateSky = true;
66        }
67
68        if (mKeyboard->isKeyDown(OIS::KC_U) && timeDelay <= 0)
69        {
70            mTiling += 1;
71            timeDelay = 0.1;
72            updateSky = true;
73        }
74        if (mKeyboard->isKeyDown(OIS::KC_Y) && timeDelay <= 0)
75        {
76            mTiling -= 1;
77            timeDelay = 0.1;
78            updateSky = true;
79        }
80
81        if (timeDelay > 0)
82            timeDelay -= evt.timeSinceLastFrame;
83
84        if (updateSky)
85        {
86            mSceneMgr->setSkyDome(true, "Examples/CloudySky", mCurvature, mTiling);
87        }
88
89        return true;
90
91    }
92};
93
94class SkyDomeApplication : public ExampleApplication
95{
96public:
97    SkyDomeApplication()
98    {
99    }
100
101protected:
102    // Just override the mandatory create scene method
103    void createScene(void)
104    {
105        // Set ambient light
106        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
107
108        // Create a skydome
109        mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
110
111        // Create a light
112        Light* l = mSceneMgr->createLight("MainLight");
113        // Accept default settings: point light, white diffuse, just set position
114        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
115        //  other objects, but I don't
116        l->setPosition(20,80,50);
117
118        Entity *ent;
119
120        // Define a floor plane mesh
121        Plane p;
122        p.normal = Vector3::UNIT_Y;
123        p.d = 200;
124        MeshManager::getSingleton().createPlane("FloorPlane",
125            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
126            p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
127
128        // Create an entity (the floor)
129        ent = mSceneMgr->createEntity("floor", "FloorPlane");
130        ent->setMaterialName("Examples/RustySteel");
131
132        mSceneMgr->getRootSceneNode()->attachObject(ent);
133
134        ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
135        // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
136        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
137
138    }
139    // Create new frame listener
140    void createFrameListener(void)
141    {
142        mFrameListener= new SkyDomeFrameListener(mWindow, mCamera, mSceneMgr);
143        mRoot->addFrameListener(mFrameListener);
144    }
145
146
147    bool setup()
148    {
149        ExampleApplication::setup();
150        LogManager::getSingleton().setLogDetail( LL_BOREME );
151        return true;
152    }
153};
Note: See TracBrowser for help on using the repository browser.