-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExampleApplication.cpp
103 lines (84 loc) · 2.68 KB
/
ExampleApplication.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "ExampleApplication.h"
#include <iostream>
#include <OgreCamera.h>
#include <OgreOptionsFile.h>
#include <OgreEntity.h>
#include <OgreException.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreViewport.h>
#include <OgreWindowEventUtilities.h>
#include <OgreSceneNode.h>
ExampleApplication::ExampleApplication()
{
}
ExampleApplication::~ExampleApplication()
{
}
//-------------------------------------------------------------------------------------
void ExampleApplication::createScene()
{
// Create SceneManager.
mSceneMgr = mRoot->createSceneManager("DefaultSceneManager");
// Create a camera.
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setPosition(Ogre::Vector3(0, 0, 80));
mCamera->lookAt(Ogre::Vector3(0, 0, -3));
mCamera->setNearClipDistance(5);
mCamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("CamNode");
mCamNode->attachObject(mCamera);
// Set control parameters.
mRotationSpeed = 0.13;
mMaxSpeed = 1000;
mSlowMaxSpeed = mMaxSpeed / 15;
mAccelerationRate = 100;
// Create one viewport, entire window.
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
// vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
// Set camera aspect ratio to match viewport.
mCamera->setAspectRatio(
Ogre::Real(vp->getActualWidth() / Ogre::Real(vp->getActualHeight())));
// Add lighting.
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20, 80, 50);
// Add meshes.
Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
Ogre::SceneNode* headNode =
mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->attachObject(ogreHead);
}
//==============================================================================
// Cross-platform boilerplate main()
//==============================================================================
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
ExampleApplication app;
try {
app.go();
} catch (Ogre::Exception& e) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.getFullDescription().c_str(),
"An exception has occured!",
MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<
e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
#ifdef __cplusplus
}
#endif