source: GTP/trunk/App/Demos/Illum/Rain/src/main.cpp @ 2221

Revision 2221, 3.7 KB checked in by plemenos, 17 years ago (diff)
  • Property svn:executable set to *
Line 
1///////////////////////////////////////////////////////////////////////////
2//
3//              Realistic real-time rain simulation program
4//
5//              Pierre Rousseau
6//
7///////////////////////////////////////////////////////////////////////////
8
9
10
11#include "CommonRain.h"
12#include "RainFrameListener.h"
13
14
15
16///////////////////////////////////////////////////////////////////////////
17// global variables
18///////////////////////////////////////////////////////////////////////////
19
20float startPos[3]            = {700, HAUTEUR_OBSERVATEUR, 100 };
21
22// variable to avoid going down through the ground
23RaySceneQuery* raySceneQuery = 0;
24
25
26
27
28
29
30/**
31 ** Class : RainApp : the application's starting point
32 ** provided here as an example.
33 ** you should uncomment the #define statements in CommonRain.h if you wish to render streaks or snow or regular raindrops.
34 */
35
36class RainApp : public ExampleApplication
37{
38
39private :
40    SceneNode *mViewNode, *mCameraNode;
41    CloseDropsParticles *mSyst;
42
43public:
44    /** Basic constructor */
45    RainApp()
46    {}
47
48    /** destructor */
49    ~RainApp()
50    {
51        delete mSyst;
52        delete raySceneQuery;
53    }
54
55protected:
56
57    /** function creating the scene manager used in the application */
58    virtual void chooseSceneManager(void)
59    {
60        mSceneMgr = mRoot->createSceneManager( ST_EXTERIOR_CLOSE );
61    }
62
63    /** function defining the contents of the scene, objects, and particles */
64    void createScene(void)
65    {
66        // We set a skybox
67        mSceneMgr->setSkyBox(true, "Examples/StormySkyBox");
68
69        mSceneMgr->setWorldGeometry( "terrain.cfg" );
70
71        // define a main node used to move the observer.
72        // the main camera will be attached to a child node of this main node.
73        mViewNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("playerView");
74
75        mViewNode->setPosition(startPos[0], startPos[1], startPos[2]); // the camera is positionned 1.8m above the ground (human height)
76
77        mViewNode->yaw(Ogre::Radian(_PI), Ogre::Node::TS_LOCAL);
78        mCameraNode = mViewNode->createChildSceneNode();
79        mCameraNode->attachObject(mCamera);
80
81        mCamera->setNearClipDistance( 1 );
82        mCamera->setFarClipDistance( 10000 );
83        mCamera->setFOVy(Ogre::Radian(FOVyCam));  // normal FOVy, 60°
84        mCamera->setAspectRatio(4.0f/3.0f);
85        mCamera->setLodBias(1);
86        mCamera->setPosition(Vector3(0, 0, 0));
87
88        // definition of the particle system
89        mSyst = new CloseDropsParticles(mSceneMgr, mViewNode, mCameraNode);
90
91        // collisions with the terrain
92        raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
93        raySceneQuery->setQueryMask(0x80000000);
94    }
95
96    /** function to connect the application to its scene manager */
97    void createFrameListener(void)
98    {
99        mFrameListener= new RainFrameListener(mWindow, mCamera, mViewNode, mCameraNode, mSyst);
100        mRoot->addFrameListener(mFrameListener);
101    }
102};
103
104
105
106
107
108
109
110
111#ifdef WIN32
112#include <windows.h>
113#endif
114
115// ----------------------------------------------------------------------------
116// Main function, just boots the application
117// ----------------------------------------------------------------------------
118#ifdef WIN32
119INT WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,INT)
120#else
121int main(int argc, char **argv)
122#endif
123{
124    srand(time(NULL));
125    // Create application object
126    RainApp app;
127
128    try
129    {
130        app.go();
131    }
132    catch( Exception& e )
133    {
134#ifdef WIN32
135        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!",
136                    MB_OK | MB_ICONERROR | MB_TASKMODAL);
137#else
138
139        fprintf(stderr, "An exception has occured : %s\n", e.getFullDescription().c_str());
140#endif
141
142    }
143#ifndef WIN32
144    return 0;
145#endif
146}
Note: See TracBrowser for help on using the repository browser.