Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/Tutorial/main.cpp @ 12

Last change on this file since 12 was 4, checked in by landauf, 17 years ago
File size: 2.8 KB
Line 
1#include "ExampleApplication.h"
2
3SceneNode *lightNode;
4
5class TutorialFrameListener : public ExampleFrameListener
6{
7public:
8    TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
9        : ExampleFrameListener(win, cam, false, false)
10    {
11    }
12
13    bool frameStarted(const FrameEvent &evt)
14    {
15        lightNode->translate( Vector3(0, -10 * evt.timeSinceLastFrame, 0) );
16
17        return ExampleFrameListener::frameStarted(evt);
18    }
19private:
20};
21
22
23class TutorialApplication : public ExampleApplication
24{
25protected:
26public:
27    TutorialApplication()
28    {
29    }
30
31    ~TutorialApplication()
32    {
33    }
34protected:
35    void createCamera(void)
36    {
37        // create camera
38        mCamera = mSceneMgr->createCamera("PlayerCam");
39        mCamera->setNearClipDistance(5);
40        mCamera->setPosition(Vector3(0,10,500));
41        mCamera->lookAt(Vector3(0,0,0));
42    }
43
44    void createScene(void)
45    {
46        // add tutorial code here
47                mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) );
48                Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
49                SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode", Vector3( 0, 0, 0 ) );
50                node->attachObject( head );
51                mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
52
53        Light *light = mSceneMgr->createLight("Light1");
54        light->setType(Light::LT_POINT);
55        light->setPosition(Vector3(0, -100, 0));
56        light->setDiffuseColour(1.0, 0.0, 0.0);
57        light->setSpecularColour(1.0, 0.0, 0.0);
58
59        BillboardSet *bbs = mSceneMgr->createBillboardSet("bb", 1);
60        bbs->createBillboard(Vector3::ZERO, ColourValue(1.0, 0.0, 0.0));
61        bbs->setMaterialName("Examples/Flare");
62        lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "LightNode", Vector3(0, 100, 0) );
63        lightNode->attachObject(bbs);
64                lightNode->attachObject(light);
65                light->setPosition(0.0, 0.0, 0.0);
66    }
67
68    void createFrameListener(void)
69    {
70        // create frame listener
71        mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr);
72        mRoot->addFrameListener(mFrameListener);
73    }
74};
75
76#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
77#define WIN32_LEAN_AND_MEAN
78#include "windows.h"
79
80INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
81#else
82int main(int argc, char **argv)
83#endif
84{
85    // Create application object
86    TutorialApplication app;
87
88    try {
89        app.go();
90    } catch( Exception& e ) {
91#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
92        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
93#else
94        fprintf(stderr, "An exception has occurred: %s\n",
95                e.getFullDescription().c_str());
96#endif
97    }
98
99    return 0;
100}
Note: See TracBrowser for help on using the repository browser.