source: OGRE/trunk/ogrenew/Samples/SkyDome/include/SkyDome.h @ 692

Revision 692, 4.2 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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 (mInputDevice->isKeyDown(KC_H) && timeDelay <= 0)
56        {
57            mCurvature += 1;
58            timeDelay = 0.1;
59            updateSky = true;
60        }
61        if (mInputDevice->isKeyDown(KC_G) && timeDelay <= 0)
62        {
63            mCurvature -= 1;
64            timeDelay = 0.1;
65            updateSky = true;
66        }
67
68        if (mInputDevice->isKeyDown(KC_U) && timeDelay <= 0)
69        {
70            mTiling += 1;
71            timeDelay = 0.1;
72            updateSky = true;
73        }
74        if (mInputDevice->isKeyDown(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
94
95
96};
97
98class SkyDomeApplication : public ExampleApplication
99{
100public:
101    SkyDomeApplication()
102    {
103    }
104
105protected:
106    // Just override the mandatory create scene method
107    void createScene(void)
108    {
109        // Set ambient light
110        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
111
112        // Create a skydome
113        mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
114
115        // Create a light
116        Light* l = mSceneMgr->createLight("MainLight");
117        // Accept default settings: point light, white diffuse, just set position
118        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
119        //  other objects, but I don't
120        l->setPosition(20,80,50);
121
122        Entity *ent;
123
124        // Define a floor plane mesh
125        Plane p;
126        p.normal = Vector3::UNIT_Y;
127        p.d = 200;
128        MeshManager::getSingleton().createPlane("FloorPlane",
129            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
130            p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
131
132        // Create an entity (the floor)
133        ent = mSceneMgr->createEntity("floor", "FloorPlane");
134        ent->setMaterialName("Examples/RustySteel");
135
136        mSceneMgr->getRootSceneNode()->attachObject(ent);
137
138        ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
139        // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
140        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
141
142    }
143    // Create new frame listener
144    void createFrameListener(void)
145    {
146        mFrameListener= new SkyDomeFrameListener(mWindow, mCamera, mSceneMgr);
147        mRoot->addFrameListener(mFrameListener);
148    }
149
150
151    bool setup()
152    {
153        ExampleApplication::setup();
154        LogManager::getSingleton().setLogDetail( LL_BOREME );
155        return true;
156    }
157};
Note: See TracBrowser for help on using the repository browser.