Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

=update

File size: 4.3 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        Terrain.h
18    \brief
19        Specialisation of OGRE's framework application to show the
20        terrain rendering plugin
21*/
22
23#include "ExampleApplication.h"
24
25RaySceneQuery* raySceneQuery = 0;
26
27// Event handler to add ability to alter curvature
28class TerrainFrameListener : public ExampleFrameListener
29{
30public:
31    TerrainFrameListener(RenderWindow* win, Camera* cam)
32        : ExampleFrameListener(win, cam)
33    {
34        // Reduce move speed
35        mMoveSpeed = 50;
36
37    }
38
39    bool frameStarted(const FrameEvent& evt)
40    {
41        if( ExampleFrameListener::frameStarted(evt) == false )
42                return false;
43
44        // clamp to terrain
45        static Ray updateRay;
46        updateRay.setOrigin(mCamera->getPosition());
47        updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
48        raySceneQuery->setRay(updateRay);
49        RaySceneQueryResult& qryResult = raySceneQuery->execute();
50        RaySceneQueryResult::iterator i = qryResult.begin();
51        if (i != qryResult.end() && i->worldFragment)
52        {
53            mCamera->setPosition(mCamera->getPosition().x, 
54                i->worldFragment->singleIntersection.y + 10, 
55                mCamera->getPosition().z);
56        }
57
58        return true;
59
60    }
61
62};
63
64
65
66class TerrainApplication : public ExampleApplication
67{
68public:
69    TerrainApplication() {}
70
71    ~TerrainApplication()
72    {
73        delete raySceneQuery;
74    }
75
76protected:
77
78
79    virtual void chooseSceneManager(void)
80    {
81        // Get the SceneManager, in this case a generic one
82        mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
83    }
84
85    virtual void createCamera(void)
86    {
87        // Create the camera
88        mCamera = mSceneMgr->createCamera("PlayerCam");
89
90        // Position it at 500 in Z direction
91        mCamera->setPosition(Vector3(128,25,128));
92        // Look back along -Z
93        mCamera->lookAt(Vector3(0,0,-300));
94        mCamera->setNearClipDistance( 1 );
95        mCamera->setFarClipDistance( 1000 );
96
97    }
98   
99    // Just override the mandatory create scene method
100    void createScene(void)
101    {
102        Plane waterPlane;
103
104        // Set ambient light
105        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
106
107        // Create a light
108        Light* l = mSceneMgr->createLight("MainLight");
109        // Accept default settings: point light, white diffuse, just set position
110        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
111        //  other objects, but I don't
112        l->setPosition(20,80,50);
113
114        // Fog
115        // NB it's VERY important to set this before calling setWorldGeometry
116        // because the vertex program picked will be different
117        ColourValue fadeColour(0.93, 0.86, 0.76);
118        mSceneMgr->setFog( FOG_LINEAR, fadeColour, .001, 500, 1000);
119        mWindow->getViewport(0)->setBackgroundColour(fadeColour);
120
121        std::string terrain_cfg("terrain.cfg");
122        mSceneMgr -> setWorldGeometry( terrain_cfg );
123        // Infinite far plane?
124        if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
125        {
126            mCamera->setFarClipDistance(0);
127        }
128
129        // Define the required skyplane
130        Plane plane;
131        // 5000 world units from the camera
132        plane.d = 5000;
133        // Above the camera, facing down
134        plane.normal = -Vector3::UNIT_Y;
135
136        // Set a nice viewpoint
137        mCamera->setPosition(707,2500,528);
138        mCamera->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
139        //mRoot -> showDebugOverlay( true );
140
141        raySceneQuery = mSceneMgr->createRayQuery(
142            Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
143
144
145    }
146    // Create new frame listener
147    void createFrameListener(void)
148    {
149        mFrameListener= new TerrainFrameListener(mWindow, mCamera);
150        mRoot->addFrameListener(mFrameListener);
151    }
152
153};
Note: See TracBrowser for help on using the repository browser.