[74] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | * License notice: |
---|
| 6 | * |
---|
| 7 | * This program is free software: you can redistribute it and/or modify |
---|
| 8 | * it under the terms of the GNU General Public License as published by |
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 10 | * (at your option) any later version. |
---|
| 11 | * |
---|
| 12 | * This program is distributed in the hope that it will be useful, |
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | * GNU General Public License for more details. |
---|
| 16 | * |
---|
| 17 | * You should have received a copy of the GNU General Public License |
---|
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | * |
---|
| 20 | * |
---|
| 21 | * Author: |
---|
| 22 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
| 23 | * Co-authors: |
---|
| 24 | * ... |
---|
| 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
[142] | 28 | /** |
---|
| 29 | @file orxonox.cc |
---|
| 30 | @brief Orxonox Main File |
---|
| 31 | */ |
---|
| 32 | |
---|
[137] | 33 | #include <Ogre.h> |
---|
| 34 | #include <OIS/OIS.h> |
---|
[399] | 35 | //#include <CEGUI/CEGUI.h> |
---|
| 36 | //#include <OgreCEGUIRenderer.h> |
---|
[74] | 37 | |
---|
[164] | 38 | #include <string> |
---|
| 39 | #include <iostream> |
---|
[483] | 40 | #include "Universe.h" |
---|
[164] | 41 | |
---|
[137] | 42 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
| 43 | #include <CoreFoundation/CoreFoundation.h> |
---|
[428] | 44 | #include "windows.h" |
---|
[74] | 45 | |
---|
[428] | 46 | |
---|
[137] | 47 | // This function will locate the path to our application on OS X, |
---|
| 48 | // unlike windows you can not rely on the curent working directory |
---|
| 49 | // for locating your configuration files and resources. |
---|
| 50 | std::string macBundlePath() |
---|
[74] | 51 | { |
---|
[137] | 52 | char path[1024]; |
---|
| 53 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
---|
| 54 | assert(mainBundle); |
---|
| 55 | |
---|
| 56 | CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle); |
---|
| 57 | assert(mainBundleURL); |
---|
| 58 | |
---|
| 59 | CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle); |
---|
| 60 | assert(cfStringRef); |
---|
| 61 | |
---|
| 62 | CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII); |
---|
| 63 | |
---|
| 64 | CFRelease(mainBundleURL); |
---|
| 65 | CFRelease(cfStringRef); |
---|
| 66 | |
---|
| 67 | return std::string(path); |
---|
| 68 | } |
---|
| 69 | #endif |
---|
| 70 | |
---|
[399] | 71 | namespace orxonox |
---|
[137] | 72 | { |
---|
[428] | 73 | Ogre::RenderWindow * mWindow; |
---|
| 74 | Ogre::SceneManager *mgr; |
---|
[483] | 75 | int stopper = 0; |
---|
[74] | 76 | |
---|
[399] | 77 | class OrxApplication |
---|
| 78 | { |
---|
| 79 | public: |
---|
| 80 | void go() |
---|
| 81 | { |
---|
| 82 | createRoot(); |
---|
| 83 | defineResources(); |
---|
| 84 | setupRenderSystem(); |
---|
| 85 | createRenderWindow(); |
---|
| 86 | initializeResourceGroups(); |
---|
| 87 | createScene(); |
---|
| 88 | setupScene(); |
---|
[483] | 89 | createUniverse(); |
---|
[399] | 90 | setupInputSystem(); |
---|
| 91 | setupCEGUI(); |
---|
| 92 | createFrameListener(); |
---|
| 93 | startRenderLoop(); |
---|
| 94 | } |
---|
[74] | 95 | |
---|
[428] | 96 | OrxApplication() |
---|
| 97 | { |
---|
| 98 | OrxApplication::pointer_s = this; |
---|
| 99 | this->x = 0; |
---|
| 100 | } |
---|
| 101 | |
---|
[399] | 102 | ~OrxApplication() |
---|
| 103 | { |
---|
| 104 | mInputManager->destroyInputObject(mKeyboard); |
---|
| 105 | OIS::InputManager::destroyInputSystem(mInputManager); |
---|
[137] | 106 | |
---|
[399] | 107 | delete mListener; |
---|
| 108 | delete mRoot; |
---|
| 109 | } |
---|
[137] | 110 | |
---|
| 111 | |
---|
[399] | 112 | void createRoot() |
---|
| 113 | { |
---|
[137] | 114 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
[399] | 115 | mRoot = new Ogre::Root(macBundlePath() + "/Contents/Resources/plugins.cfg"); |
---|
[137] | 116 | #else |
---|
[399] | 117 | mRoot = new Ogre::Root(); |
---|
[137] | 118 | #endif |
---|
[399] | 119 | } |
---|
[74] | 120 | |
---|
[399] | 121 | void defineResources() |
---|
| 122 | { |
---|
| 123 | Ogre::String secName, typeName, archName; |
---|
| 124 | Ogre::ConfigFile cf; |
---|
[137] | 125 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
[399] | 126 | cf.load(macBundlePath() + "/Contents/Resources/resources.cfg"); |
---|
[137] | 127 | #else |
---|
[399] | 128 | cf.load("resources.cfg"); |
---|
[137] | 129 | #endif |
---|
[74] | 130 | |
---|
[399] | 131 | Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); |
---|
| 132 | while (seci.hasMoreElements()) |
---|
[137] | 133 | { |
---|
[399] | 134 | secName = seci.peekNextKey(); |
---|
| 135 | Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); |
---|
| 136 | Ogre::ConfigFile::SettingsMultiMap::iterator i; |
---|
| 137 | for (i = settings->begin(); i != settings->end(); ++i) |
---|
| 138 | { |
---|
| 139 | typeName = i->first; |
---|
| 140 | archName = i->second; |
---|
[137] | 141 | #if OGRE_PLATFORM == OGRE_PLATFORM_APPLE |
---|
[399] | 142 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( String(macBundlePath() + "/" + archName), typeName, secName); |
---|
[137] | 143 | #else |
---|
[399] | 144 | Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); |
---|
[137] | 145 | #endif |
---|
[399] | 146 | } |
---|
[137] | 147 | } |
---|
| 148 | } |
---|
[74] | 149 | |
---|
[399] | 150 | void setupRenderSystem() |
---|
| 151 | { |
---|
| 152 | if (!mRoot->restoreConfig() && !mRoot->showConfigDialog()) |
---|
| 153 | throw Ogre::Exception(52, "User canceled the config dialog!", "OrxApplication::setupRenderSystem()"); |
---|
| 154 | } |
---|
[74] | 155 | |
---|
[399] | 156 | void createRenderWindow() |
---|
| 157 | { |
---|
[428] | 158 | mWindow = mRoot->initialise(true, "Ogre Render Window"); |
---|
[399] | 159 | } |
---|
[74] | 160 | |
---|
[399] | 161 | void initializeResourceGroups() |
---|
| 162 | { |
---|
| 163 | Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); |
---|
| 164 | Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); |
---|
| 165 | } |
---|
[74] | 166 | |
---|
[399] | 167 | void createScene(void) |
---|
| 168 | { |
---|
[164] | 169 | |
---|
[399] | 170 | } |
---|
[74] | 171 | |
---|
[399] | 172 | void setupScene() |
---|
| 173 | { |
---|
[483] | 174 | mgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "Default SceneManager"); |
---|
| 175 | cam = mgr->createCamera("Camera"); |
---|
| 176 | cam->setPosition(Ogre::Vector3(0,0,0)); |
---|
| 177 | cam->lookAt(Ogre::Vector3(0,0,0)); |
---|
| 178 | //cam->setFOVy(Ogre::Degree(90)); |
---|
| 179 | Ogre::Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); |
---|
[428] | 180 | |
---|
[483] | 181 | Ogre::ColourValue fadeColour(0.0, 0.0, 0.0); |
---|
| 182 | vp->setBackgroundColour(fadeColour); |
---|
| 183 | mgr->setFog(Ogre::FOG_EXP, fadeColour, 0.0, 10000, 38000); |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | //mgr->setSkyBox(true, "Examples/SpaceSkybox"); |
---|
| 187 | //mgr->setSkyBox(true, "MySky"); |
---|
| 188 | |
---|
| 189 | mgr->setAmbientLight(Ogre::ColourValue(0.1, 1.0, 0.1)); |
---|
| 190 | /*Ogre::Light *light = mgrtemp->createLight(lightnames); |
---|
| 191 | light->setType(Ogre::Light::LT_POINT); |
---|
| 192 | light->setPosition(Ogre::Vector3(0, 0, 0)); |
---|
[428] | 193 | |
---|
[483] | 194 | light->setDiffuseColour(1.0, 0.0, 0.0); |
---|
| 195 | light->setSpecularColour(1.0, 0.0, 0.0); |
---|
| 196 | */ |
---|
| 197 | |
---|
[428] | 198 | |
---|
[399] | 199 | } |
---|
[74] | 200 | |
---|
[399] | 201 | void setupInputSystem() |
---|
| 202 | { |
---|
| 203 | size_t windowHnd = 0; |
---|
| 204 | std::ostringstream windowHndStr; |
---|
| 205 | OIS::ParamList pl; |
---|
| 206 | Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
[74] | 207 | |
---|
[399] | 208 | win->getCustomAttribute("WINDOW", &windowHnd); |
---|
| 209 | windowHndStr << windowHnd; |
---|
| 210 | pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); |
---|
| 211 | mInputManager = OIS::InputManager::createInputSystem(pl); |
---|
| 212 | |
---|
| 213 | try |
---|
| 214 | { |
---|
| 215 | mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject(OIS::OISKeyboard, false)); |
---|
| 216 | mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject(OIS::OISMouse, false)); |
---|
| 217 | } |
---|
| 218 | catch (const OIS::Exception &e) |
---|
| 219 | { |
---|
| 220 | throw new Ogre::Exception(42, e.eText, "OrxApplication::setupInputSystem"); |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | void setupCEGUI() |
---|
[137] | 225 | { |
---|
[399] | 226 | Ogre::SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); |
---|
| 227 | Ogre::RenderWindow *win = mRoot->getAutoCreatedWindow(); |
---|
[137] | 228 | } |
---|
[428] | 229 | |
---|
| 230 | void screenShots() |
---|
| 231 | { |
---|
[399] | 232 | |
---|
[483] | 233 | /*unsigned int indice = 1; |
---|
[428] | 234 | char filename[30]; |
---|
| 235 | char fn[1]; |
---|
| 236 | // generate new names... |
---|
| 237 | //sprintf(filename, "screenshot_%d.png", ++indice); |
---|
| 238 | //sprintf(filename, fn, ++indice); |
---|
[483] | 239 | */ |
---|
[428] | 240 | |
---|
| 241 | if(stopper == 1){ |
---|
[483] | 242 | //sprintf(filename, "stevecube_FR.bmp"); |
---|
| 243 | mWindow->writeContentsToFile("MySky_FR.bmp"); |
---|
[428] | 244 | } |
---|
| 245 | else if(stopper == 2){ |
---|
[483] | 246 | //sprintf(filename, "stevecube_LF.bmp"); |
---|
| 247 | cam->pitch(Ogre::Degree(90)); |
---|
| 248 | mWindow->writeContentsToFile("MySky_LF.bmp"); |
---|
[428] | 249 | } |
---|
| 250 | else if(stopper == 3){ |
---|
[483] | 251 | //sprintf(filename, "stevecube_BK.bmp"); |
---|
| 252 | cam->pitch(Ogre::Degree(90)); |
---|
| 253 | mWindow->writeContentsToFile("MySky_BK.bmp"); |
---|
[428] | 254 | } |
---|
| 255 | else if(stopper == 4){ |
---|
[483] | 256 | //sprintf(filename, "stevecube_RT.bmp"); |
---|
| 257 | cam->pitch(Ogre::Degree(90)); |
---|
| 258 | mWindow->writeContentsToFile("MySky_RT.bmp"); |
---|
[428] | 259 | } |
---|
| 260 | else if(stopper == 5){ |
---|
[483] | 261 | //sprintf(filename, "stevecube_UP.bmp"); |
---|
| 262 | cam->yaw(Ogre::Degree(90)); |
---|
| 263 | mWindow->writeContentsToFile("MySky_UP.bmp"); |
---|
[428] | 264 | } |
---|
| 265 | else if(stopper == 6){ |
---|
[483] | 266 | cam->yaw(Ogre::Degree(-90)); |
---|
| 267 | mWindow->writeContentsToFile("MySky_DN.bmp"); |
---|
[428] | 268 | } |
---|
| 269 | |
---|
| 270 | stopper+=1; |
---|
| 271 | if(stopper >= 7) |
---|
| 272 | stopper = 1; |
---|
| 273 | } |
---|
| 274 | |
---|
[483] | 275 | |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | void createUniverse() |
---|
| 279 | { |
---|
| 280 | |
---|
| 281 | // UNIVERSE-CLASS |
---|
| 282 | std::cout << "1_1\n"; |
---|
| 283 | Universe::Universe myUni = Universe(77000); |
---|
| 284 | std::cout << "1_2\n"; |
---|
| 285 | myUni.createCoordinates(); |
---|
| 286 | std::cout << "1_3\n"; |
---|
| 287 | myUni.createBillboards(mgr, cam, mRoot); |
---|
| 288 | std::cout << "1_4\n"; |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | |
---|
[428] | 296 | class OrxExitListener : public Ogre::FrameListener |
---|
| 297 | { |
---|
| 298 | public: |
---|
| 299 | OrxExitListener(OIS::Keyboard *keyboard) |
---|
| 300 | : mKeyboard(keyboard) |
---|
| 301 | { |
---|
| 302 | } |
---|
| 303 | bool frameEnded(const Ogre::FrameEvent& evt) |
---|
| 304 | { |
---|
| 305 | if(mKeyboard->isKeyDown(OIS::KC_RETURN) or stopper > 1){ |
---|
| 306 | OrxApplication::pointer_s->screenShots(); |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | return true; |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | bool frameStarted(const Ogre::FrameEvent& evt) |
---|
| 313 | { |
---|
| 314 | mKeyboard->capture(); |
---|
| 315 | return !mKeyboard->isKeyDown(OIS::KC_ESCAPE); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | |
---|
| 319 | private: |
---|
| 320 | OIS::Keyboard *mKeyboard; |
---|
| 321 | }; |
---|
| 322 | |
---|
[399] | 323 | void createFrameListener() |
---|
[137] | 324 | { |
---|
[399] | 325 | mListener = new OrxExitListener(mKeyboard); |
---|
| 326 | mRoot->addFrameListener(mListener); |
---|
[137] | 327 | } |
---|
[74] | 328 | |
---|
[399] | 329 | void startRenderLoop() |
---|
| 330 | { |
---|
| 331 | mRoot->startRendering(); |
---|
| 332 | } |
---|
[428] | 333 | |
---|
| 334 | |
---|
| 335 | private: |
---|
| 336 | Ogre::Root *mRoot; |
---|
| 337 | OIS::Keyboard *mKeyboard; |
---|
| 338 | OIS::Mouse *mMouse; |
---|
| 339 | OIS::InputManager *mInputManager; |
---|
| 340 | // CEGUI::OgreCEGUIRenderer *mRenderer; |
---|
| 341 | // CEGUI::System *mSystem; |
---|
| 342 | OrxExitListener *mListener; |
---|
| 343 | Ogre::Camera * cam; |
---|
| 344 | double x; |
---|
| 345 | |
---|
| 346 | public: |
---|
| 347 | static OrxApplication* pointer_s; |
---|
[399] | 348 | }; |
---|
[428] | 349 | |
---|
| 350 | OrxApplication* OrxApplication::pointer_s = 0; |
---|
[399] | 351 | } |
---|
[137] | 352 | |
---|
[399] | 353 | using namespace Ogre; |
---|
[137] | 354 | |
---|
| 355 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
[74] | 356 | #define WIN32_LEAN_AND_MEAN |
---|
| 357 | #include "windows.h" |
---|
| 358 | |
---|
[137] | 359 | INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) |
---|
[74] | 360 | #else |
---|
[137] | 361 | int main(int argc, char **argv) |
---|
[74] | 362 | #endif |
---|
| 363 | { |
---|
[483] | 364 | srand(time(NULL)); |
---|
[137] | 365 | try |
---|
| 366 | { |
---|
[399] | 367 | orxonox::OrxApplication orxonox; |
---|
[74] | 368 | orxonox.go(); |
---|
[137] | 369 | } |
---|
| 370 | catch(Exception& e) |
---|
| 371 | { |
---|
| 372 | #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32 |
---|
| 373 | MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL); |
---|
[74] | 374 | #else |
---|
| 375 | fprintf(stderr, "An exception has occurred: %s\n", |
---|
| 376 | e.getFullDescription().c_str()); |
---|
| 377 | #endif |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | return 0; |
---|
| 381 | } |
---|
[137] | 382 | |
---|