/////////////////////////////////////////////////////////////////////////// // // Realistic real-time rain simulation program // // Pierre Rousseau // /////////////////////////////////////////////////////////////////////////// #include "CommonRain.h" #include "RainFrameListener.h" /////////////////////////////////////////////////////////////////////////// // global variables /////////////////////////////////////////////////////////////////////////// float startPos[3] = {700, HAUTEUR_OBSERVATEUR, 100 }; // variable to avoid going down through the ground RaySceneQuery* raySceneQuery = 0; /** ** Class : RainApp : the application's starting point ** provided here as an example. ** you should uncomment the #define statements in CommonRain.h if you wish to render streaks or snow or regular raindrops. */ class RainApp : public ExampleApplication { private : SceneNode *mViewNode, *mCameraNode; CloseDropsParticles *mSyst; public: /** Basic constructor */ RainApp() {} /** destructor */ ~RainApp() { delete mSyst; delete raySceneQuery; } protected: /** function creating the scene manager used in the application */ virtual void chooseSceneManager(void) { mSceneMgr = mRoot->createSceneManager( ST_EXTERIOR_CLOSE ); } /** function defining the contents of the scene, objects, and particles */ void createScene(void) { // We set a skybox mSceneMgr->setSkyBox(true, "Examples/StormySkyBox"); mSceneMgr->setWorldGeometry( "terrain.cfg" ); // define a main node used to move the observer. // the main camera will be attached to a child node of this main node. mViewNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("playerView"); mViewNode->setPosition(startPos[0], startPos[1], startPos[2]); // the camera is positionned 1.8m above the ground (human height) mViewNode->yaw(Ogre::Radian(_PI), Ogre::Node::TS_LOCAL); mCameraNode = mViewNode->createChildSceneNode(); mCameraNode->attachObject(mCamera); mCamera->setNearClipDistance( 1 ); mCamera->setFarClipDistance( 10000 ); mCamera->setFOVy(Ogre::Radian(FOVyCam)); // normal FOVy, 60° mCamera->setAspectRatio(4.0f/3.0f); mCamera->setLodBias(1); mCamera->setPosition(Vector3(0, 0, 0)); // definition of the particle system mSyst = new CloseDropsParticles(mSceneMgr, mViewNode, mCameraNode); // collisions with the terrain raySceneQuery = mSceneMgr->createRayQuery(Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y)); raySceneQuery->setQueryMask(0x80000000); } /** function to connect the application to its scene manager */ void createFrameListener(void) { mFrameListener= new RainFrameListener(mWindow, mCamera, mViewNode, mCameraNode, mSyst); mRoot->addFrameListener(mFrameListener); } }; #ifdef WIN32 #include #endif // ---------------------------------------------------------------------------- // Main function, just boots the application // ---------------------------------------------------------------------------- #ifdef WIN32 INT WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,INT) #else int main(int argc, char **argv) #endif { srand(time(NULL)); // Create application object RainApp app; try { app.go(); } catch( Exception& e ) { #ifdef WIN32 MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else fprintf(stderr, "An exception has occured : %s\n", e.getFullDescription().c_str()); #endif } #ifndef WIN32 return 0; #endif }