1 | #include "ExampleApplication.h" |
---|
2 | |
---|
3 | SceneNode *lightNode; |
---|
4 | |
---|
5 | class TutorialFrameListener : public ExampleFrameListener |
---|
6 | { |
---|
7 | public: |
---|
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 | // add tutorial code here: |
---|
16 | // ... |
---|
17 | lightNode->translate(Vector3(0, -10 * evt.timeSinceLastFrame, 0)); |
---|
18 | |
---|
19 | return ExampleFrameListener::frameStarted(evt); |
---|
20 | } |
---|
21 | private: |
---|
22 | }; |
---|
23 | |
---|
24 | |
---|
25 | class TutorialApplication : public ExampleApplication |
---|
26 | { |
---|
27 | protected: |
---|
28 | public: |
---|
29 | TutorialApplication() |
---|
30 | { |
---|
31 | } |
---|
32 | |
---|
33 | ~TutorialApplication() |
---|
34 | { |
---|
35 | } |
---|
36 | protected: |
---|
37 | void createCamera(void) |
---|
38 | { |
---|
39 | // create camera |
---|
40 | mCamera = mSceneMgr->createCamera("PlayerCam"); |
---|
41 | mCamera->setNearClipDistance(5); |
---|
42 | mCamera->setPosition(Vector3(0,10,500)); |
---|
43 | mCamera->lookAt(Vector3(0,0,0)); |
---|
44 | } |
---|
45 | |
---|
46 | void createScene(void) |
---|
47 | { |
---|
48 | // add tutorial code here: |
---|
49 | // ... |
---|
50 | mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) ); |
---|
51 | Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh"); |
---|
52 | |
---|
53 | Entity* head2 = mSceneMgr->createEntity("head2", "ogrehead.mesh"); |
---|
54 | |
---|
55 | SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode", Vector3( 0, 0, 0 ) ); |
---|
56 | node->attachObject( head ); |
---|
57 | |
---|
58 | SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "OgreHeadNode2", Vector3( 50, 0, 0 ) ); |
---|
59 | node2->attachObject( head2 ); |
---|
60 | |
---|
61 | |
---|
62 | mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox"); |
---|
63 | |
---|
64 | Light *light = mSceneMgr->createLight("Light1"); |
---|
65 | light->setType(Light::LT_POINT); |
---|
66 | light->setPosition(Vector3(0, 100, 0)); |
---|
67 | light->setDiffuseColour(0.5, 0.5, 0.0); |
---|
68 | light->setSpecularColour(0.5, 0.5, 0.0); |
---|
69 | |
---|
70 | BillboardSet *bbs = mSceneMgr->createBillboardSet("bb", 1); |
---|
71 | bbs->createBillboard(Vector3::ZERO, ColourValue(1.0, 0.0, 0.0)); |
---|
72 | bbs->setMaterialName("Examples/Flare"); |
---|
73 | |
---|
74 | lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LightNode", Vector3(0, 100, 0)); |
---|
75 | lightNode->attachObject(bbs); |
---|
76 | lightNode->attachObject(light); |
---|
77 | light->setPosition(0.0, 0.0, 0.0); |
---|
78 | } |
---|
79 | |
---|
80 | void createFrameListener(void) |
---|
81 | { |
---|
82 | // create frame listener |
---|
83 | mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr); |
---|
84 | mRoot->addFrameListener(mFrameListener); |
---|
85 | } |
---|
86 | }; |
---|
87 | |
---|
88 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
89 | #define WIN32_LEAN_AND_MEAN |
---|
90 | #include "windows.h" |
---|
91 | |
---|
92 | INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) |
---|
93 | #else |
---|
94 | int main(int argc, char **argv) |
---|
95 | #endif |
---|
96 | { |
---|
97 | // Create application object |
---|
98 | TutorialApplication app; |
---|
99 | |
---|
100 | try { |
---|
101 | app.go(); |
---|
102 | } catch( Exception& e ) { |
---|
103 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
104 | MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
105 | #else |
---|
106 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
107 | e.getFullDescription().c_str()); |
---|
108 | #endif |
---|
109 | } |
---|
110 | |
---|
111 | return 0; |
---|
112 | } |
---|