Changeset 1502 for code/trunk/src/orxonox
- Timestamp:
- Jun 1, 2008, 3:54:20 PM (17 years ago)
- Location:
- code/trunk/src/orxonox
- Files:
-
- 1 deleted
- 43 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/CMakeLists.txt
r1407 r1502 9 9 hud/RadarOverlayElement.cc 10 10 hud/RadarObject.cc 11 hud/Navigation.cc 11 12 particle/ParticleInterface.cc 12 13 tolua/tolua_bind.cc … … 24 25 objects/NPC.cc 25 26 objects/Projectile.cc 27 objects/RotatingProjectile.cc 26 28 objects/Skybox.cc 27 29 objects/SpaceShip.cc 30 objects/SpaceShipAI.cc 28 31 objects/WorldEntity.cc 29 32 -
code/trunk/src/orxonox/GraphicsEngine.cc
r1349 r1502 45 45 #include "core/Debug.h" 46 46 #include "core/CommandExecutor.h" 47 47 #include "core/TclBind.h" 48 #include "console/InGameConsole.h" 49 50 #include "core/ConsoleCommand.h" 51 #include <OgreSceneManager.h> 52 #include <OgreCompositorManager.h> 53 #include <OgreViewport.h> 48 54 49 55 namespace orxonox { 50 51 56 /** 52 57 @brief Returns the singleton instance and creates it the first time. … … 83 88 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 84 89 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 90 91 TclBind::getInstance().setDataPath(this->dataPath_); 85 92 } 86 93 … … 137 144 #endif 138 145 139 /* // create a logManager 146 // TODO: LogManager doesn't work on specific systems. The why is unknown yet. 147 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 148 // create a logManager 140 149 // note: If there's already a logManager, Ogre will complain by a failed assertation. 141 150 // but that shouldn't happen, since this is the first time to create a logManager.. … … 148 157 myLog = logger->createLog("ogre.log", true, false, true); 149 158 else 150 159 myLog = logger->createLog(this->ogreLogfile_, true, false, false); 151 160 CCOUT(4) << "Ogre Log created" << std::endl; 152 161 153 162 myLog->setLogDetail(Ogre::LL_BOREME); 154 myLog->addListener(this);*/ 163 myLog->addListener(this); 164 #endif 155 165 156 166 // Root will detect that we've already created a Log 157 167 CCOUT(4) << "Creating Ogre Root..." << std::endl; 158 root_ = new Ogre::Root(plugin_filename); 168 169 root_ = new Ogre::Root(plugin_filename, "ogre.cfg", this->ogreLogfile_); 170 171 #if ORXONOX_PLATFORM != ORXONOX_PLATFORM_WIN32 172 // tame the ogre ouput so we don't get all the mess in the console 173 Ogre::Log* defaultLog = Ogre::LogManager::getSingleton().getDefaultLog(); 174 defaultLog->setDebugOutputEnabled(false); 175 defaultLog->setLogDetail(Ogre::LL_BOREME); 176 defaultLog->addListener(this); 177 #endif 178 159 179 CCOUT(4) << "Creating Ogre Root done" << std::endl; 160 180 … … 241 261 bool GraphicsEngine::createNewScene() 242 262 { 243 CCOUT(4) << "Creating new SceneManager " << std::endl;263 CCOUT(4) << "Creating new SceneManager..." << std::endl; 244 264 if (scene_) 245 265 { … … 291 311 else 292 312 return 0; 313 } 314 315 /** 316 @brief Returns the window aspect ratio height/width. 317 @return The ratio 318 */ 319 float GraphicsEngine::getWindowAspectRatio() const 320 { 321 if (this->renderWindow_) 322 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); 323 else 324 return 1.0f; 293 325 } 294 326 … … 345 377 int h = rw->getHeight(); 346 378 InputManager::setWindowExtents(w, h); 379 InGameConsole::getInstance().resize(); 347 380 } 348 381 … … 365 398 CommandExecutor::execute("exit", false); 366 399 } 400 401 //HACK!! 402 /*SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOn).setAccessLevel(AccessLevel::User); 403 SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOn).setAccessLevel(AccessLevel::User); 404 SetConsoleCommandShortcut(GraphicsEngine, CompositorBloomOff).setAccessLevel(AccessLevel::User); 405 SetConsoleCommandShortcut(GraphicsEngine, CompositorMotionBlurOff).setAccessLevel(AccessLevel::User); 406 void GraphicsEngine::CompositorBloomOn() 407 { 408 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 409 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 410 Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom"); 411 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", true); 412 } 413 void GraphicsEngine::CompositorBloomOff() 414 { 415 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 416 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 417 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Bloom", false); 418 } 419 420 void GraphicsEngine::CompositorMotionBlurOn() 421 { 422 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 423 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 424 Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur"); 425 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", true); 426 } 427 void GraphicsEngine::CompositorMotionBlurOff() 428 { 429 Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 430 Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 431 Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "MotionBlur", false); 432 }*/ 367 433 } -
code/trunk/src/orxonox/GraphicsEngine.h
r1293 r1502 72 72 int getWindowWidth() const; 73 73 int getWindowHeight() const; 74 float getWindowAspectRatio() const; 75 float getAverageFPS() const 76 { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; } 74 77 75 78 void windowMoved (Ogre::RenderWindow* rw); … … 80 83 static GraphicsEngine& getSingleton(); 81 84 static GraphicsEngine* getSingletonPtr() { return &getSingleton(); } 85 86 //HACK!!! 87 //void static CompositorBloomOn(); 88 //void static CompositorBloomOff(); 89 //void static CompositorMotionBlurOn(); 90 //void static CompositorMotionBlurOff(); 91 82 92 83 93 private: -
code/trunk/src/orxonox/Main.cc
r1293 r1502 36 36 #include <exception> 37 37 38 #include " OrxonoxPlatform.h"38 #include "util/OrxonoxPlatform.h" 39 39 #include "core/SignalHandler.h" 40 40 #include "Orxonox.h" -
code/trunk/src/orxonox/Orxonox.cc
r1407 r1502 51 51 //#include "util/Sleep.h" 52 52 #include "util/ArgReader.h" 53 #include "util/ExprParser.h"54 53 55 54 // core … … 57 56 #include "core/ConsoleCommand.h" 58 57 #include "core/Debug.h" 59 #include "core/Factory.h"60 58 #include "core/Loader.h" 61 59 #include "core/Tickable.h" 62 #include "core/InputBuffer.h"63 60 #include "core/InputManager.h" 64 61 #include "core/TclBind.h" … … 72 69 73 70 // objects and tools 74 #include "tools/Timer.h"75 71 #include "hud/HUD.h" 76 #include "console/InGameConsole.h" 72 #include <Ogre.h> 73 74 #include "GraphicsEngine.h" 77 75 78 76 // FIXME: is this really file scope? … … 83 81 namespace orxonox 84 82 { 85 ConsoleCommandShortcut(Orxonox, exit, AccessLevel::None).setKeybindMode(KeybindMode::OnPress); 86 ConsoleCommandShortcut(Orxonox, slomo, AccessLevel::Offline).setDefaultValue(0, 1.0) 87 .setAxisParamIndex(0).setIsAxisRelative(false); 88 ConsoleCommandShortcut(Orxonox, setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0); 89 ConsoleCommandShortcut(Orxonox, activateConsole, AccessLevel::None); 90 class Testconsole : public InputBufferListener 91 { 92 public: 93 Testconsole(InputBuffer* ib) : ib_(ib) {} 94 void listen() const 95 { 96 std::cout << "> " << this->ib_->get() << std::endl; 97 } 98 void execute() const 99 { 100 std::cout << ">> " << this->ib_->get() << std::endl; 101 if (!CommandExecutor::execute(this->ib_->get())) 102 std::cout << "Error" << std::endl; 103 this->ib_->clear(); 104 } 105 void hintandcomplete() const 106 { 107 std::cout << CommandExecutor::hint(this->ib_->get()) << std::endl; 108 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 109 } 110 void clear() const 111 { 112 this->ib_->clear(); 113 } 114 void removeLast() const 115 { 116 this->ib_->removeLast(); 117 } 118 void exit() const 119 { 120 InputManager::setInputState(InputManager::IS_NORMAL); 121 } 122 123 private: 124 InputBuffer* ib_; 125 }; 126 127 class Calculator 128 { 129 public: 130 static float calculate(const std::string& calculation) 131 { 132 ExprParser expr(calculation); 133 if (expr.getSuccess()) 134 { 135 if (expr.getResult() == 42.0) 136 std::cout << "Greetings from the restaurant at the end of the universe." << std::endl; 137 // FIXME: insert modifier to display in full precision 138 std::cout << "Result is: " << expr.getResult() << std::endl; 139 if (expr.getRemains() != "") 140 std::cout << "Warning: Expression could not be parsed to the end! Remains: '" 141 << expr.getRemains() << "'" << std::endl; 142 return expr.getResult(); 143 } 144 else 145 { 146 std::cout << "Cannot calculate expression: Parse error" << std::endl; 147 return 0; 148 } 149 } 150 }; 151 ConsoleCommandShortcut(Calculator, calculate, AccessLevel::None); 83 SetConsoleCommandShortcut(Orxonox, exit).setKeybindMode(KeybindMode::OnPress); 84 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 85 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 152 86 153 87 /** … … 165 99 // turn on frame smoothing by setting a value different from 0 166 100 frameSmoothingTime_(0.0f), 167 orxonoxConsole_(0),168 101 orxonoxHUD_(0), 169 102 bAbort_(false), 170 103 timefactor_(1.0f), 171 104 mode_(STANDALONE), 172 serverIp_("") 105 serverIp_(""), 106 serverPort_(NETWORK_PORT) 173 107 { 174 108 } … … 180 114 { 181 115 // keep in mind: the order of deletion is very important! 182 if (this->orxonoxHUD_)183 delete this->orxonoxHUD_;116 // if (this->orxonoxHUD_) 117 // delete this->orxonoxHUD_; 184 118 Loader::close(); 185 119 InputManager::destroy(); … … 244 178 ar.checkArgument("data", dataPath, false); 245 179 ar.checkArgument("ip", serverIp_, false); 180 ar.checkArgument("port", serverPort_, false); 246 181 if(ar.errorHandling()) 247 182 return false; … … 251 186 else if (mode == "server") 252 187 mode_ = SERVER; 188 else if (mode == "dedicated") 189 mode_ = DEDICATED; 253 190 else 254 191 { … … 265 202 // procedure until the GUI is identical 266 203 267 TclBind::getInstance().setDataPath(dataPath);268 204 ConfigFileManager::getSingleton()->setFile(CFT_Settings, "orxonox.ini"); 269 205 Factory::createClassHierarchy(); … … 281 217 bool Orxonox::start() 282 218 { 283 //if (mode == DEDICATED) 284 // do something else 285 //else 286 287 if (!ogre_->loadRenderer()) // creates the render window 288 return false; 289 290 // Calls the InputManager which sets up the input devices. 291 // The render window width and height are used to set up the mouse movement. 292 if (!InputManager::initialise(ogre_->getWindowHandle(), 293 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 294 return false; 295 296 // TODO: Spread this so that this call only initialises things needed for the GUI 297 if (!ogre_->initialiseResources()) 298 return false; 299 300 // TOOD: load the GUI here 301 // set InputManager to GUI mode 302 InputManager::setInputState(InputManager::IS_GUI); 303 // TODO: run GUI here 304 305 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 306 307 InputManager::setInputState(InputManager::IS_NONE); 308 309 if (!loadPlayground()) 310 return false; 219 if (mode_ == DEDICATED) 220 { 221 // do something else 222 } 223 else 224 { // not dedicated server 225 if (!ogre_->loadRenderer()) // creates the render window 226 return false; 227 228 // Calls the InputManager which sets up the input devices. 229 // The render window width and height are used to set up the mouse movement. 230 if (!InputManager::initialise(ogre_->getWindowHandle(), 231 ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true)) 232 return false; 233 234 // TODO: Spread this so that this call only initialises things needed for the GUI 235 if (!ogre_->initialiseResources()) 236 return false; 237 238 // TOOD: load the GUI here 239 // set InputManager to GUI mode 240 InputManager::setInputState(InputManager::IS_GUI); 241 // TODO: run GUI here 242 243 // The following lines depend very much on the GUI output, so they're probably misplaced here.. 244 245 InputManager::setInputState(InputManager::IS_NONE); 246 247 // create Ogre SceneManager 248 ogre_->createNewScene(); 249 250 if (!loadPlayground()) 251 return false; 252 } 311 253 312 254 switch (mode_) … … 320 262 return false; 321 263 break; 264 case DEDICATED: 265 if (!serverLoad()) 266 return false; 267 break; 322 268 default: 323 269 if (!standaloneLoad()) … … 336 282 bool Orxonox::loadPlayground() 337 283 { 338 ogre_->createNewScene(); 339 340 // Init audio 284 // Init audio 341 285 //auMan_ = new audio::AudioManager(); 342 286 //auMan_->ambientAdd("a1"); … … 348 292 // Load the HUD 349 293 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 350 orxonoxHUD_ = new HUD(1); 351 352 COUT(3) << "Orxonox: Loading Console..." << std::endl; 353 InputBuffer* ib = dynamic_cast<InputBuffer*>(InputManager::getKeyHandler("buffer")); 354 /* 355 Testconsole* console = new Testconsole(ib); 356 ib->registerListener(console, &Testconsole::listen, true); 357 ib->registerListener(console, &Testconsole::execute, '\r', false); 358 ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true); 359 ib->registerListener(console, &Testconsole::clear, '§', true); 360 ib->registerListener(console, &Testconsole::removeLast, '\b', true); 361 ib->registerListener(console, &Testconsole::exit, (char)0x1B, true); 362 */ 363 orxonoxConsole_ = new InGameConsole(ib); 364 ib->registerListener(orxonoxConsole_, &InGameConsole::listen, true); 365 ib->registerListener(orxonoxConsole_, &InGameConsole::execute, '\r', false); 366 ib->registerListener(orxonoxConsole_, &InGameConsole::hintandcomplete, '\t', true); 367 ib->registerListener(orxonoxConsole_, &InGameConsole::clear, '§', true); 368 ib->registerListener(orxonoxConsole_, &InGameConsole::removeLast, '\b', true); 369 ib->registerListener(orxonoxConsole_, &InGameConsole::exit, (char)0x1B, true); 370 294 orxonoxHUD_ = &HUD::getSingleton(); 371 295 return true; 372 296 } … … 379 303 COUT(2) << "Loading level in server mode" << std::endl; 380 304 381 server_g = new network::Server( );305 server_g = new network::Server(serverPort_); 382 306 383 307 if (!loadScene()) … … 399 323 client_g = network::Client::createSingleton(); 400 324 else 401 client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT); 402 403 client_g->establishConnection(); 325 326 client_g = network::Client::createSingleton(serverIp_, serverPort_); 327 328 if(!client_g->establishConnection()) 329 return false; 404 330 client_g->tick(0); 405 331 … … 427 353 Level* startlevel = new Level("levels/sample.oxw"); 428 354 Loader::open(startlevel); 429 355 356 // HACK: shader stuff for presentation 357 /*Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 358 mSceneMgr->setAmbientLight(ColourValue(0.4,0.4,0.4)); 359 Ogre::Light* dirlight = mSceneMgr->createLight("Light1"); 360 361 dirlight->setType(Ogre::Light::LT_DIRECTIONAL); 362 dirlight->setDirection(Vector3( 0, 1, 5 )); 363 dirlight->setDiffuseColour(ColourValue(0.6, 0.6, 0.4)); 364 dirlight->setSpecularColour(ColourValue(1.0, 1.0, 1.0));*/ 365 430 366 return true; 431 367 } … … 453 389 // Contains the times of recently fired events 454 390 // eventTimes[4] is the list for the times required for the fps counter 455 std::deque<unsigned long> eventTimes[ 4];391 std::deque<unsigned long> eventTimes[3]; 456 392 // Clear event times 457 for (int i = 0; i < 4; ++i)393 for (int i = 0; i < 3; ++i) 458 394 eventTimes[i].clear(); 459 // fill the fps time list with zeros460 for (int i = 0; i < 50; i++)461 eventTimes[3].push_back(0);462 395 463 396 // use the ogre timer class to measure time. … … 466 399 timer_->reset(); 467 400 401 float renderTime = 0.0f; 402 float frameTime = 0.0f; 403 clock_t time = 0; 404 405 //Ogre::SceneManager* mSceneMgr = GraphicsEngine::getSingleton().getSceneManager(); 406 //Ogre::Viewport* mViewport = mSceneMgr->getCurrentViewport(); 407 408 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Bloom"); 409 //Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "MotionBlur"); 410 468 411 COUT(3) << "Orxonox: Starting the main loop." << std::endl; 469 while (!bAbort_) 470 { 471 // Pump messages in all registered RenderWindows 472 // This calls the WindowEventListener objects. 473 Ogre::WindowEventUtilities::messagePump(); 474 412 while (!bAbort_) 413 { 475 414 // get current time 476 415 unsigned long now = timer_->getMilliseconds(); 477 eventTimes[3].push_back(now);478 eventTimes[3].erase(eventTimes[3].begin());479 416 480 417 // create an event to pass to the frameStarted method in ogre … … 482 419 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 483 420 evt.timeSinceLastFrame = calculateEventTime(now, eventTimes[1]); 421 frameTime += evt.timeSinceLastFrame; 484 422 485 423 // show the current time in the HUD 486 // orxonoxHUD_->setTime((int)now, 0); 487 // orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber()); 488 if (eventTimes[3].back() - eventTimes[3].front() != 0) 489 // orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 490 491 // Iterate through all Tickables and call their tick(dt) function 424 // HUD::getSingleton().setTime(now); 425 if (mode_ != DEDICATED && frameTime > 0.4f) 426 { 427 HUD::getSingleton().setRenderTimeRatio(renderTime / frameTime); 428 frameTime = 0.0f; 429 renderTime = 0.0f; 430 } 431 432 // Call those objects that need the real time 433 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 434 it->tick((float)evt.timeSinceLastFrame); 435 // Call the scene objects 492 436 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 493 437 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 494 // Iterate through all TickableReals and call their tick(dt) function495 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it)496 it->tick((float)evt.timeSinceLastFrame);497 orxonoxConsole_->tick((float)evt.timeSinceLastFrame);498 438 499 439 // don't forget to call _fireFrameStarted in ogre to make sure … … 501 441 ogreRoot._fireFrameStarted(evt); 502 442 503 // server still renders at the moment504 //if (mode_ != SERVER)505 ogreRoot._updateAllRenderTargets(); // only render in non-server mode506 507 443 // get current time 508 444 now = timer_->getMilliseconds(); 445 calculateEventTime(now, eventTimes[2]); 446 447 if (mode_ != DEDICATED) 448 { 449 // Pump messages in all registered RenderWindows 450 // This calls the WindowEventListener objects. 451 Ogre::WindowEventUtilities::messagePump(); 452 453 // render 454 ogreRoot._updateAllRenderTargets(); 455 } 456 457 // get current time 458 now = timer_->getMilliseconds(); 509 459 510 460 // create an event to pass to the frameEnded method in ogre 511 461 evt.timeSinceLastEvent = calculateEventTime(now, eventTimes[0]); 512 evt.timeSinceLastFrame= calculateEventTime(now, eventTimes[2]);462 renderTime += calculateEventTime(now, eventTimes[2]); 513 463 514 464 // again, just to be sure ogre works fine 515 465 ogreRoot._fireFrameEnded(evt); 516 } 517 518 if(mode_==CLIENT) 466 //msleep(200); 467 } 468 469 if (mode_ == CLIENT) 519 470 network::Client::getSingleton()->closeConnection(); 520 else if (mode_==SERVER)471 else if (mode_ == SERVER) 521 472 server_g->close(); 473 522 474 return true; 523 475 } … … 560 512 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 561 513 } 562 563 /**564 * Static function that shows the console in game mode.565 */566 void Orxonox::activateConsole()567 {568 // currently, the console shows itself when feeded with input.569 InputManager::setInputState(InputManager::IS_CONSOLE);570 }571 514 } -
code/trunk/src/orxonox/Orxonox.h
r1293 r1502 50 50 SERVER, 51 51 CLIENT, 52 STANDALONE 52 STANDALONE, 53 DEDICATED 53 54 }; 54 55 … … 70 71 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 71 72 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 72 static inline void activateConsole();73 73 74 74 private: … … 97 97 // TODO: make this a config-value by creating a config class for orxonox 98 98 float frameSmoothingTime_; 99 InGameConsole* orxonoxConsole_;100 99 HUD* orxonoxHUD_; 101 100 bool bAbort_; //!< aborts the render loop if true … … 105 104 gameMode mode_; 106 105 std::string serverIp_; 106 int serverPort_; 107 107 108 108 static Orxonox *singletonRef_s; -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r1214 r1502 35 35 #define _OrxonoxPrereqs_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 //----------------------------------------------------------------------- … … 74 74 class Skybox; 75 75 class SpaceShip; 76 class SpaceShipAI; 76 77 class WorldEntity; 77 78 … … 95 96 96 97 // hud 98 class BarOverlayElement; 97 99 class HUD; 100 class Navigation; 101 class RadarObject; 102 class RadarOverlayElement; 103 98 104 //console 99 105 class InGameConsole; -
code/trunk/src/orxonox/OrxonoxStableHeaders.h
r1219 r1502 35 35 #define _OrxonoxStableHeaders_H__ 36 36 37 #include " OrxonoxPlatform.h"37 #include "util/OrxonoxPlatform.h" 38 38 39 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC … … 109 109 #include "network/Synchronisable.h" 110 110 111 #include "OrxonoxPlatform.h"112 111 #include "OrxonoxPrereqs.h" 113 112 #include "tools/Timer.h" -
code/trunk/src/orxonox/console/InGameConsole.cc
r1362 r1502 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 40 40 #include "core/Debug.h" 41 41 #include "core/CoreIncludes.h" 42 #include "core/ConfigValueIncludes.h" 42 43 #include "core/ConsoleCommand.h" 43 44 #include "core/InputManager.h" 45 #include "util/Math.h" 44 46 #include "GraphicsEngine.h" 45 47 46 #define LINES 20 48 #define LINES 30 49 #define CHAR_WIDTH1 7.78 //34 // fix this please - determine the char-width dynamically 50 #define CHAR_WIDTH2 8.28 // fix this please - determine the char-width dynamically 51 #define CHAR_WIDTH3 7.80 //78 // fix this please - determine the char-width dynamically 47 52 48 53 namespace orxonox 49 54 { 55 SetConsoleCommand(InGameConsole, openConsole, true); 56 SetConsoleCommand(InGameConsole, closeConsole, true); 57 50 58 using namespace Ogre; 51 59 52 const float REL_WIDTH = 0.8; 53 const float REL_HEIGHT = 0.4; 54 const float BLINK = 0.25; 55 56 InGameConsole::InGameConsole(InputBuffer* ib) : 57 windowW(0), windowH(0), 58 scroll(0), scrollTimer(0.0f), 59 cursor(0.0f), 60 active(false), 61 ib_(ib), 62 om(0), 63 consoleOverlay(0), 64 consoleOverlayContainer(0), 65 consoleOverlayNoise(0), 66 consoleOverlayBorder(0), 67 consoleOverlayTextAreas(0) 68 { 69 //RegisterObject(InGameConsole); 70 init(); 71 } 72 73 InGameConsole::~InGameConsole(void){ 74 for(int i=0; i<LINES; i++) delete consoleOverlayTextAreas[i]; 75 delete consoleOverlayTextAreas; 76 } 77 78 void InGameConsole::listen(){ 79 if(!active) activate(); 80 print(convert2UTF(this->ib_->get())); 81 } 82 83 void InGameConsole::execute(){ 84 newline(); 85 if (!CommandExecutor::execute(this->ib_->get())){ 86 print("Error"); 87 newline(); 88 } 89 this->ib_->clear(); 90 } 91 92 void InGameConsole::hintandcomplete(){ 93 print(CommandExecutor::hint(this->ib_->get())); 94 newline(); 95 this->ib_->set(CommandExecutor::complete(this->ib_->get())); 96 print(convert2UTF(this->ib_->get())); 97 } 98 99 void InGameConsole::clear(){ 100 this->ib_->clear(); 101 } 102 103 void InGameConsole::removeLast(){ 104 this->ib_->removeLast(); 105 } 106 107 void InGameConsole::exit(){ 108 clear(); 109 deactivate(); 110 InputManager::setInputState(InputManager::IS_NORMAL); 111 } 112 113 /** 114 @brief called once by constructor 115 */ 116 void InGameConsole::init(){ 60 float InGameConsole::REL_WIDTH = 0.8; 61 float InGameConsole::REL_HEIGHT = 0.4; 62 float InGameConsole::BLINK = 0.5; 63 64 /** 65 @brief Constructor: Creates and initializes the InGameConsole. 66 */ 67 InGameConsole::InGameConsole() : 68 om_(0), consoleOverlay_(0), consoleOverlayContainer_(0), 69 consoleOverlayNoise_(0), consoleOverlayBorder_(0), consoleOverlayTextAreas_(0) 70 { 71 RegisterObject(InGameConsole); 72 73 this->active_ = false; 74 this->cursor_ = 0.0; 75 this->cursorSymbol_ = '|'; 76 this->inputWindowStart_ = 0; 77 this->numLinesShifted_ = LINES - 1; 78 79 this->init(); 80 this->setConfigValues(); 81 82 Shell::getInstance().addOutputLevel(true); 83 } 84 85 /** 86 @brief Destructor: Destroys the TextAreas. 87 */ 88 InGameConsole::~InGameConsole(void) 89 { 90 /*for (int i = 0; i < LINES; i++) 91 if (this->consoleOverlayTextAreas_[i]) 92 om_->destroyOverlayElement(this->consoleOverlayTextAreas_[i]); 93 94 if (this->consoleOverlayTextAreas_) 95 delete[] this->consoleOverlayTextAreas_;*/ 96 } 97 98 /** 99 @brief Returns a reference to the only existing instance of InGameConsole. 100 */ 101 InGameConsole& InGameConsole::getInstance() 102 { 103 static InGameConsole instance; 104 return instance; 105 } 106 107 /** 108 @brief Sets the config values, describing the size of the console. 109 */ 110 void InGameConsole::setConfigValues() 111 { 112 SetConfigValue(REL_WIDTH, 0.8); 113 SetConfigValue(REL_HEIGHT, 0.4); 114 SetConfigValue(BLINK, 0.5); 115 } 116 117 /** 118 @brief Called if all output-lines have to be redrawn. 119 */ 120 void InGameConsole::linesChanged() 121 { 122 std::list<std::string>::const_iterator it = Shell::getInstance().getNewestLineIterator(); 123 int max = 0; 124 for (int i = 1; i < LINES; ++i) 125 { 126 if (it != Shell::getInstance().getEndIterator()) 127 { 128 ++it; 129 max = i; 130 } 131 else 132 break; 133 } 134 135 for (int i = LINES - 1; i > max; --i) 136 this->print("", i, true); 137 138 for (int i = max; i >= 1; --i) 139 { 140 --it; 141 this->print(*it, i, true); 142 } 143 } 144 145 /** 146 @brief Called if only the last output-line has changed. 147 */ 148 void InGameConsole::onlyLastLineChanged() 149 { 150 if (LINES > 1) 151 this->print(*Shell::getInstance().getNewestLineIterator(), 1); 152 } 153 154 /** 155 @brief Called if a new output-line was added. 156 */ 157 void InGameConsole::lineAdded() 158 { 159 this->numLinesShifted_ = 0; 160 this->shiftLines(); 161 this->onlyLastLineChanged(); 162 } 163 164 /** 165 @brief Called if the text in the input-line has changed. 166 */ 167 void InGameConsole::inputChanged() 168 { 169 if (LINES > 0) 170 this->print(Shell::getInstance().getInput(), 0); 171 172 if (Shell::getInstance().getInput() == "" || Shell::getInstance().getInput().size() == 0) 173 this->inputWindowStart_ = 0; 174 } 175 176 /** 177 @brief Called if the position of the cursor in the input-line has changed. 178 */ 179 void InGameConsole::cursorChanged() 180 { 181 /*std::string input = Shell::getInstance().getInput(); 182 input.insert(Shell::getInstance().getCursorPosition(), 1, this->cursorSymbol_); 183 if (LINES > 0) 184 this->print(input, 0);*/ 185 this->setCursorPosition(Shell::getInstance().getCursorPosition() - inputWindowStart_); 186 } 187 188 /** 189 @brief Called if the console gets closed. 190 */ 191 void InGameConsole::exit() 192 { 193 this->deactivate(); 194 } 195 196 /** 197 @brief Called once by constructor, initializes the InGameConsole. 198 */ 199 void InGameConsole::init() 200 { 117 201 // for the beginning, don't scroll 118 scroll= 0;119 scrollTimer= 0;120 cursor= 0;202 this->scroll_ = 0; 203 this->scrollTimer_ = 0; 204 this->cursor_ = 0; 121 205 122 206 // create overlay and elements 123 om= &Ogre::OverlayManager::getSingleton();207 this->om_ = &Ogre::OverlayManager::getSingleton(); 124 208 125 209 // create a container 126 consoleOverlayContainer = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", "container"));127 consoleOverlayContainer->setMetricsMode(Ogre::GMM_RELATIVE);128 consoleOverlayContainer->setPosition((1-REL_WIDTH)/2, 0);129 consoleOverlayContainer->setDimensions(REL_WIDTH,REL_HEIGHT);210 this->consoleOverlayContainer_ = static_cast<OverlayContainer*>(this->om_->createOverlayElement("Panel", "InGameConsoleContainer")); 211 this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE); 212 this->consoleOverlayContainer_->setPosition((1 - InGameConsole::REL_WIDTH) / 2, 0); 213 this->consoleOverlayContainer_->setDimensions(InGameConsole::REL_WIDTH, InGameConsole::REL_HEIGHT); 130 214 131 215 // create BorderPanel 132 consoleOverlayBorder = static_cast<BorderPanelOverlayElement*>(om->createOverlayElement("BorderPanel", "borderPanel"));133 consoleOverlayBorder->setMetricsMode(Ogre::GMM_PIXELS);134 consoleOverlayBorder->setMaterialName("ConsoleCenter");216 this->consoleOverlayBorder_ = static_cast<BorderPanelOverlayElement*>(this->om_->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel")); 217 this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS); 218 this->consoleOverlayBorder_->setMaterialName("ConsoleCenter"); 135 219 // set parameters for border 136 consoleOverlayBorder->setBorderSize(16, 16, 0, 16);137 consoleOverlayBorder->setBorderMaterialName("ConsoleBorder");138 consoleOverlayBorder->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);139 consoleOverlayBorder->setRightBorderUV(0.5, 0.49, 1.0, 0.5);140 consoleOverlayBorder->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);141 consoleOverlayBorder->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);142 consoleOverlayBorder->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);220 this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16); 221 this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder"); 222 this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51); 223 this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5); 224 this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0); 225 this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0); 226 this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0); 143 227 144 228 // create the text lines 145 consoleOverlayTextAreas = new TextAreaOverlayElement*[LINES]; 146 for(int i = 0; i<LINES; i++){ 147 consoleOverlayTextAreas[i] = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "textArea"+Ogre::StringConverter::toString(i))); 148 consoleOverlayTextAreas[i]->setMetricsMode(Ogre::GMM_PIXELS); 149 consoleOverlayTextAreas[i]->setFontName("Console"); 150 consoleOverlayTextAreas[i]->setCharHeight(20); 151 consoleOverlayTextAreas[i]->setParameter("colour_top", "0.21 0.69 0.21"); 152 consoleOverlayTextAreas[i]->setLeft(8); 153 consoleOverlayTextAreas[i]->setCaption(""); 229 this->consoleOverlayTextAreas_ = new TextAreaOverlayElement*[LINES]; 230 for (int i = 0; i < LINES; i++) 231 { 232 this->consoleOverlayTextAreas_[i] = static_cast<TextAreaOverlayElement*>(this->om_->createOverlayElement("TextArea", "InGameConsoleTextArea" + Ogre::StringConverter::toString(i))); 233 this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS); 234 this->consoleOverlayTextAreas_[i]->setFontName("Console"); 235 this->consoleOverlayTextAreas_[i]->setCharHeight(18); 236 this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21"); 237 this->consoleOverlayTextAreas_[i]->setLeft(8); 238 this->consoleOverlayTextAreas_[i]->setCaption(""); 154 239 } 155 240 156 241 // create noise 157 consoleOverlayNoise = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "noise")); 158 consoleOverlayNoise->setMetricsMode(Ogre::GMM_PIXELS); 159 consoleOverlayNoise->setPosition(5,0); 160 consoleOverlayNoise->setMaterialName("ConsoleNoise"); 161 162 consoleOverlay = om->create("Console"); 163 consoleOverlay->add2D(consoleOverlayContainer); 164 consoleOverlayContainer->addChild(consoleOverlayBorder); 165 //comment following line to disable noise 166 consoleOverlayContainer->addChild(consoleOverlayNoise); 167 for(int i = 0; i<LINES; i++) consoleOverlayContainer->addChild(consoleOverlayTextAreas[i]); 168 resize(); 242 this->consoleOverlayNoise_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleNoise")); 243 this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS); 244 this->consoleOverlayNoise_->setPosition(5,0); 245 this->consoleOverlayNoise_->setMaterialName("ConsoleNoise"); 246 247 // create cursor 248 this->consoleOverlayCursor_ = static_cast<PanelOverlayElement*>(this->om_->createOverlayElement("Panel", "InGameConsoleCursor")); 249 this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS); 250 this->consoleOverlayCursor_->setPosition(5,219); 251 this->consoleOverlayCursor_->setDimensions(1, 14); 252 this->consoleOverlayCursor_->setMaterialName("Orxonox/GreenDot"); 253 254 this->consoleOverlay_ = this->om_->create("InGameConsoleConsole"); 255 this->consoleOverlay_->add2D(this->consoleOverlayContainer_); 256 this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_); 257 this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_); 258 //comment following line to disable noise 259 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 260 for (int i = 0; i < LINES; i++) 261 this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]); 262 263 this->resize(); 169 264 170 265 // move overlay "above" the top edge of the screen 171 266 // we take -1.2 because the border mkes the panel bigger 172 consoleOverlayContainer->setTop(-1.2*REL_HEIGHT);267 this->consoleOverlayContainer_->setTop(-1.2 * InGameConsole::REL_HEIGHT); 173 268 // show overlay 174 consoleOverlay->show(); 175 176 COUT(3) << "Info: InGameConsole initialized" << std::endl; 177 } 178 179 /** 180 @brief used to control the actual scrolling and cursor 181 */ 182 void InGameConsole::tick(float dt){ 183 scrollTimer += dt; 184 if(scrollTimer >= 0.01){ 185 float top = consoleOverlayContainer->getTop(); 186 scrollTimer = 0; 187 if(scroll!=0){ 269 this->consoleOverlay_->show(); 270 271 COUT(4) << "Info: InGameConsole initialized" << std::endl; 272 } 273 274 /** 275 @brief Resizes the console elements. Call if window size changes. 276 */ 277 void InGameConsole::resize() 278 { 279 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 280 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 281 this->consoleOverlayBorder_->setWidth((int) this->windowW_* InGameConsole::REL_WIDTH); 282 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT); 283 this->consoleOverlayNoise_->setWidth((int) this->windowW_ * InGameConsole::REL_WIDTH - 10); 284 this->consoleOverlayNoise_->setHeight((int) this->windowH_ * InGameConsole::REL_HEIGHT - 5); 285 286 // now adjust the text lines... 287 this->desiredTextWidth_ = (int) (this->windowW_ * InGameConsole::REL_WIDTH) - 12; 288 289 if (LINES > 0) 290 this->maxCharsPerLine_ = max((unsigned int)10, (unsigned int) ((float)this->desiredTextWidth_ / CHAR_WIDTH3)); 291 else 292 this->maxCharsPerLine_ = 10; 293 294 for (int i = 0; i < LINES; i++) 295 { 296 this->consoleOverlayTextAreas_[i]->setWidth(this->desiredTextWidth_); 297 this->consoleOverlayTextAreas_[i]->setTop((int) this->windowH_ * InGameConsole::REL_HEIGHT - 24 - 14*i); 298 } 299 300 this->linesChanged(); 301 } 302 303 /** 304 @brief Used to control the actual scrolling and the cursor. 305 */ 306 void InGameConsole::tick(float dt) 307 { 308 this->scrollTimer_ += dt; 309 if (this->scrollTimer_ >= 0.01) 310 { 311 float top = this->consoleOverlayContainer_->getTop(); 312 float timePassed = scrollTimer_; 313 this->scrollTimer_ = 0; 314 if (this->scroll_ != 0) 315 { 188 316 // scroll 189 top = top + 0.02*scroll;190 consoleOverlayContainer->setTop(top);317 top = top + timePassed * this->scroll_; 318 this->consoleOverlayContainer_->setTop(top); 191 319 } 192 if(top <= -1.2*REL_HEIGHT){ 320 if (top <= -1.2 * InGameConsole::REL_HEIGHT) 321 { 193 322 // window has completely scrolled up 194 scroll = 0; 195 consoleOverlay->hide(); 196 active = false; 323 this->scroll_ = 0; 324 this->consoleOverlay_->hide(); 325 this->active_ = false; 326 Shell::getInstance().unregisterListener(this); 197 327 } 198 if(top >= 0){ 328 if (top >= 0) 329 { 199 330 // window has completely scrolled down 200 scroll= 0;201 consoleOverlayContainer->setTop(0);202 active= true;331 this->scroll_ = 0; 332 this->consoleOverlayContainer_->setTop(0); 333 this->active_ = true; 203 334 } 204 335 } 205 336 206 cursor += dt; 207 if(cursor >= 2*BLINK) cursor = 0; 208 print(convert2UTF(this->ib_->get())); 209 210 // this creates a flickering effect 211 consoleOverlayNoise->setTiling(1, rand()%5+1); 212 } 213 214 /** 215 @brief resizes the console elements. call if window size changes 216 */ 217 void InGameConsole::resize(){ 218 windowW = GraphicsEngine::getSingleton().getWindowWidth(); 219 windowH = GraphicsEngine::getSingleton().getWindowHeight(); 220 consoleOverlayBorder->setWidth((int) windowW*REL_WIDTH); 221 consoleOverlayBorder->setHeight((int) windowH*REL_HEIGHT); 222 consoleOverlayNoise->setWidth((int) windowW*REL_WIDTH - 10); 223 consoleOverlayNoise->setHeight((int) windowH*REL_HEIGHT - 5); 224 // now adjust the text lines... 225 for(int i = 0; i<LINES; i++){ 226 consoleOverlayTextAreas[i]->setWidth(windowW*REL_WIDTH); 227 consoleOverlayTextAreas[i]->setTop((int)windowH*REL_HEIGHT - 24 - 16*i); 228 } 229 } 230 231 /** 232 @brief shows console 233 */ 234 void InGameConsole::activate(){ 235 consoleOverlay->show(); 337 this->cursor_ += dt; 338 if (this->cursor_ >= InGameConsole::BLINK) 339 { 340 this->cursor_ = 0; 341 bShowCursor_ = !bShowCursor_; 342 if (bShowCursor_) 343 this->consoleOverlayCursor_->show(); 344 else 345 this->consoleOverlayCursor_->hide(); 346 } 347 348 /*if (this->cursor_ >= 2 * InGameConsole::BLINK) 349 this->cursor_ = 0; 350 351 if (this->cursor_ >= InGameConsole::BLINK && this->cursorSymbol_ == '|') 352 { 353 this->cursorSymbol_ = ' '; 354 this->cursorChanged(); 355 } 356 else if (this->cursor_ < InGameConsole::BLINK && this->cursorSymbol_ == ' ') 357 { 358 this->cursorSymbol_ = '|'; 359 this->cursorChanged(); 360 }*/ 361 362 // this creates a flickering effect 363 this->consoleOverlayNoise_->setTiling(1, rand() % 5 + 1); 364 } 365 366 /** 367 @brief Shows the InGameConsole. 368 */ 369 void InGameConsole::activate() 370 { 371 InputManager::setInputState(InputManager::IS_CONSOLE); 372 Shell::getInstance().registerListener(this); 373 this->linesChanged(); 374 375 this->consoleOverlay_->show(); 236 376 // just in case window size has changed... 237 resize();377 this->resize(); 238 378 // scroll down 239 scroll= 1;379 this->scroll_ = 1; 240 380 // the rest is done by tick 241 381 } 242 382 243 383 /** 244 @brief hides console 245 */ 246 void InGameConsole::deactivate(){ 384 @brief Hides the InGameConsole. 385 */ 386 void InGameConsole::deactivate() 387 { 247 388 // scroll up 248 scroll= -1;389 this->scroll_ = -1; 249 390 // the rest is done by tick 250 } 251 252 /** 253 @brief prints string to bottom line 254 @param s string to be printed 255 */ 256 void InGameConsole::print(Ogre::UTFString s){ 257 if(cursor>BLINK) consoleOverlayTextAreas[0]->setCaption(">" + s); 258 else consoleOverlayTextAreas[0]->setCaption(">" + s + "_"); 259 } 260 261 /** 262 @brief shifts all lines up and clears the bottom line 263 */ 264 void InGameConsole::newline(){ 265 Ogre::UTFString line; 266 for(int i = LINES-1; i>=1; i--){ 267 line = consoleOverlayTextAreas[i-1]->getCaption(); 268 // don't copy the cursor... 269 int l = line.length(); 270 if(!line.empty() && line.substr(l-1) == "_") line.erase(l-1); 271 consoleOverlayTextAreas[i]->setCaption(line); 272 } 273 consoleOverlayTextAreas[0]->setCaption(">"); 274 } 275 276 Ogre::UTFString InGameConsole::convert2UTF(std::string s){ 391 InputManager::setInputState(InputManager::IS_NORMAL); 392 } 393 394 /** 395 @brief Activates the console. 396 */ 397 void InGameConsole::openConsole() 398 { 399 InGameConsole::getInstance().activate(); 400 } 401 402 /** 403 @brief Deactivates the console. 404 */ 405 void InGameConsole::closeConsole() 406 { 407 InGameConsole::getInstance().deactivate(); 408 } 409 410 /** 411 @brief Shifts all output lines one line up 412 */ 413 void InGameConsole::shiftLines() 414 { 415 for (unsigned int i = LINES - 1; i > 1; --i) 416 { 417 this->consoleOverlayTextAreas_[i]->setCaption(this->consoleOverlayTextAreas_[i - 1]->getCaption()); 418 this->consoleOverlayTextAreas_[i]->setColourTop(this->consoleOverlayTextAreas_[i - 1]->getColourTop()); 419 this->consoleOverlayTextAreas_[i]->setColourBottom(this->consoleOverlayTextAreas_[i - 1]->getColourBottom()); 420 } 421 } 422 423 void InGameConsole::colourLine(int colourcode, int index) 424 { 425 if (colourcode == -1) 426 { 427 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.90, 0.90, 0.90, 1.00)); 428 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 1.00, 1.00, 1.00)); 429 } 430 else if (colourcode == 1) 431 { 432 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.25, 0.25, 1.00)); 433 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.50, 0.50, 1.00)); 434 } 435 else if (colourcode == 2) 436 { 437 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.95, 0.50, 0.20, 1.00)); 438 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.70, 0.50, 1.00)); 439 } 440 else if (colourcode == 3) 441 { 442 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.50, 0.50, 0.95, 1.00)); 443 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.80, 1.00, 1.00)); 444 } 445 else if (colourcode == 4) 446 { 447 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.65, 0.48, 0.44, 1.00)); 448 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(1.00, 0.90, 0.90, 1.00)); 449 } 450 else if (colourcode == 5) 451 { 452 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.40, 0.20, 0.40, 1.00)); 453 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 0.60, 0.80, 1.00)); 454 } 455 else 456 { 457 this->consoleOverlayTextAreas_[index]->setColourTop (ColourValue(0.21, 0.69, 0.21, 1.00)); 458 this->consoleOverlayTextAreas_[index]->setColourBottom(ColourValue(0.80, 1.00, 0.80, 1.00)); 459 } 460 } 461 462 void InGameConsole::setCursorPosition(int pos) 463 { 464 static std::string char1 = "bdefgilpqtzCEGIJKNOPQT5[}äü"; 465 static std::string char2 = "Z4"; 466 467 if (pos > (int)maxCharsPerLine_) 468 pos = maxCharsPerLine_; 469 else if (pos < 0) 470 pos = 0; 471 472 float width = 0; 473 for (int i = 0; i < pos; ++i) 474 { 475 if (char1.find(displayedText_[i]) != std::string::npos) 476 width += CHAR_WIDTH1; 477 else if (char2.find(displayedText_[i]) != std::string::npos) 478 width += CHAR_WIDTH2; 479 else 480 width += CHAR_WIDTH3; 481 } 482 this->consoleOverlayCursor_->setPosition(width + 5, this->windowH_ * InGameConsole::REL_HEIGHT - 20); 483 } 484 485 /** 486 @brief Prints string to bottom line. 487 @param s String to be printed 488 */ 489 void InGameConsole::print(const std::string& text, int index, bool alwaysShift) 490 { 491 char level = 0; 492 if (text.size() > 0) 493 level = text[0]; 494 495 std::string output = text; 496 497 if (level >= -1 && level <= 5) 498 output.erase(0, 1); 499 500 if (LINES > index) 501 { 502 this->colourLine(level, index); 503 504 if (index > 0) 505 { 506 unsigned int linesUsed = 1; 507 while (output.size() > this->maxCharsPerLine_) 508 { 509 ++linesUsed; 510 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output.substr(0, this->maxCharsPerLine_))); 511 output.erase(0, this->maxCharsPerLine_); 512 output.insert(0, 1, ' '); 513 if (linesUsed > numLinesShifted_ || alwaysShift) 514 this->shiftLines(); 515 this->colourLine(level, index); 516 } 517 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 518 this->displayedText_ = output; 519 this->numLinesShifted_ = linesUsed; 520 } 521 else 522 { 523 if (output.size() > this->maxCharsPerLine_) 524 { 525 if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_) 526 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition(); 527 else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1)) 528 this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1; 529 530 output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_); 531 } 532 else 533 this->inputWindowStart_ = 0; 534 this->displayedText_ = output; 535 this->consoleOverlayTextAreas_[index]->setCaption(convert2UTF(output)); 536 } 537 } 538 } 539 540 /** 541 @brief Converts a string into an Ogre::UTFString. 542 @param s The string to convert 543 @return The converted string 544 */ 545 Ogre::UTFString InGameConsole::convert2UTF(std::string s) 546 { 277 547 Ogre::UTFString utf; 278 int i;279 548 Ogre::UTFString::code_point cp; 280 for (i=0; i<(int)s.size(); ++i){ 549 for (unsigned int i = 0; i < s.size(); ++i) 550 { 281 551 cp = s[i]; 282 552 cp &= 0xFF; -
code/trunk/src/orxonox/console/InGameConsole.h
r1214 r1502 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Fabian 'x3n' Landau 26 26 * 27 27 */ … … 37 37 38 38 #include "core/Tickable.h" 39 #include "core/ InputBuffer.h"39 #include "core/Shell.h" 40 40 41 41 42 42 namespace orxonox 43 43 { 44 class _OrxonoxExport InGameConsole : public InputBufferListener44 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener 45 45 { 46 46 public: 47 InGameConsole(InputBuffer* ib); 48 ~InGameConsole(); 49 void listen(); 50 void execute(); 51 void hintandcomplete(); 52 void clear(); 53 void removeLast(); 54 void exit(); 55 void init(); 47 static InGameConsole& getInstance(); 48 49 void setConfigValues(); 56 50 void tick(float dt); 51 57 52 void activate(); 58 53 void deactivate(); 54 void resize(); 55 56 static void openConsole(); 57 static void closeConsole(); 59 58 60 59 private: 61 void resize(); 62 void print(Ogre::UTFString s); 63 void newline(); 64 Ogre::UTFString convert2UTF(std::string s); 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other); 62 ~InGameConsole(); 65 63 66 int windowW; 67 int windowH; 68 int scroll; 69 float scrollTimer; 70 float cursor; 71 bool active; 72 InputBuffer* ib_; 73 Ogre::OverlayManager* om; 74 Ogre::Overlay* consoleOverlay; 75 Ogre::OverlayContainer* consoleOverlayContainer; 76 Ogre::PanelOverlayElement* consoleOverlayNoise; 77 Ogre::BorderPanelOverlayElement* consoleOverlayBorder; 78 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas; 64 virtual void linesChanged(); 65 virtual void onlyLastLineChanged(); 66 virtual void lineAdded(); 67 virtual void inputChanged(); 68 virtual void cursorChanged(); 69 virtual void exit(); 70 71 void init(); 72 void shiftLines(); 73 void colourLine(int colourcode, int index); 74 void setCursorPosition(int pos); 75 void print(const std::string& text, int index, bool alwaysShift = false); 76 static Ogre::UTFString convert2UTF(std::string s); 77 78 static float REL_WIDTH; 79 static float REL_HEIGHT; 80 static float BLINK; 81 82 int windowW_; 83 int windowH_; 84 int desiredTextWidth_; 85 unsigned int maxCharsPerLine_; 86 unsigned int numLinesShifted_; 87 int scroll_; 88 float scrollTimer_; 89 float cursor_; 90 unsigned int inputWindowStart_; 91 char cursorSymbol_; 92 bool active_; 93 bool bShowCursor_; 94 std::string displayedText_; 95 Ogre::OverlayManager* om_; 96 Ogre::Overlay* consoleOverlay_; 97 Ogre::OverlayContainer* consoleOverlayContainer_; 98 Ogre::PanelOverlayElement* consoleOverlayNoise_; 99 Ogre::PanelOverlayElement* consoleOverlayCursor_; 100 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 101 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 79 102 }; 80 103 } -
code/trunk/src/orxonox/hud/BarOverlayElement.cc
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 30 #include "BarOverlayElement.h" 28 31 #include <OgreOverlayManager.h> 29 #include <OgreOverlayElement.h>30 #include <OgrePanelOverlayElement.h>31 32 #include "GraphicsEngine.h" 32 #include "BarOverlayElement.h"33 33 34 34 namespace orxonox 35 35 { 36 using namespace Ogre;36 using namespace Ogre; 37 37 38 BarOverlayElement::BarOverlayElement(const String& name): Ogre::PanelOverlayElement(name){38 BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){ 39 39 name_ = name; 40 40 } … … 42 42 BarOverlayElement::~BarOverlayElement(){} 43 43 44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, O gre::OverlayContainer* container){44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 45 45 // init some values... 46 46 container_ = container; 47 om = &O gre::OverlayManager::getSingleton();47 om = &OverlayManager::getSingleton(); 48 48 value_ = 0; 49 49 color_ = 2; … … 53 53 topRel_ = topRel; 54 54 dimRel_ = dimRel; 55 55 56 56 // create background... 57 57 background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container")); 58 58 background_->show(); 59 59 container_->addChild(background_); 60 background_->setMetricsMode( Ogre::GMM_PIXELS);60 background_->setMetricsMode(GMM_PIXELS); 61 61 background_->setMaterialName("Orxonox/BarBackground"); 62 62 … … 65 65 66 66 show(); 67 setMetricsMode( Ogre::GMM_PIXELS);67 setMetricsMode(GMM_PIXELS); 68 68 setMaterialName("Orxonox/Green"); 69 69 background_->addChild(this); … … 126 126 } 127 127 } 128 129 -
code/trunk/src/orxonox/hud/BarOverlayElement.h
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #ifndef _BarOverlayElement_H__ 30 #define _BarOverlayElement_H__ 28 31 29 #ifndef _BAR_H__ 30 #define _BAR_H__ 31 32 #include <OgreOverlayManager.h> 33 #include <OgreOverlayElement.h> 34 #include <OgrePanelOverlayElement.h> 32 #include "OrxonoxPrereqs.h" 35 33 36 34 #include <OgrePrerequisites.h> 37 #include "../OrxonoxPrereqs.h" 38 39 35 #include <OgrePanelOverlayElement.h> 40 36 41 37 namespace orxonox … … 44 40 { 45 41 private: 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 42 bool autoColor_; // whether bar changes color automatically 43 float value_; // progress of bar 44 int color_; 45 int left_; 46 int top_; 47 int width_; 48 int height_; 49 int windowW_, windowH_; 50 Ogre::Real leftRel_; 51 Ogre::Real topRel_; 52 Ogre::Real dimRel_; 53 Ogre::OverlayManager* om; // our overlay manager 54 Ogre::OverlayContainer* container_; // our parent container to attach to 55 Ogre::OverlayContainer* background_; 56 Ogre::String name_; 61 57 62 58 public: 63 64 65 66 59 bool left2Right; 60 static const int RED = 0; // predefined colors 61 static const int YELLOW = 1; 62 static const int GREEN = 2; 67 63 68 69 70 71 72 73 74 75 64 BarOverlayElement(const Ogre::String& name); 65 virtual ~BarOverlayElement(); 66 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 67 void resize(); 68 void setValue(float value); 69 void setColor(int color); 70 float getValue(); 71 int getBarColor(); 76 72 }; 77 73 } 78 #endif 79 80 74 #endif /* _BarOverlayElement_H__ */ -
code/trunk/src/orxonox/hud/HUD.cc
r1407 r1502 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist3 * 4 *5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 27 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "HUD.h" 31 32 #include <string> 33 #include <set> 30 34 #include <OgreOverlay.h> 31 35 #include <OgreOverlayContainer.h> 32 36 #include <OgreOverlayManager.h> 33 #include <OgreSceneNode.h>34 #include <OgreEntity.h>35 37 #include <OgreStringConverter.h> 38 36 39 #include "core/Debug.h" 40 #include "core/ConsoleCommand.h" 37 41 #include "objects/SpaceShip.h" 38 #include " HUD.h"42 #include "GraphicsEngine.h" 39 43 #include "BarOverlayElement.h" 44 #include "RadarObject.h" 40 45 #include "RadarOverlayElement.h" 46 #include "Navigation.h" 41 47 #include "OverlayElementFactories.h" 42 48 43 49 namespace orxonox 44 50 { 51 SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 52 SetConsoleCommandShortcut(HUD, toggleFPS).setAccessLevel(AccessLevel::User); 53 SetConsoleCommandShortcut(HUD, toggleRenderTime).setAccessLevel(AccessLevel::User); 54 45 55 using namespace Ogre; 46 56 47 HUD::HUD( int zoom){57 HUD::HUD(){ 48 58 om = &Ogre::OverlayManager::getSingleton(); 49 50 // create Factories 59 sm = GraphicsEngine::getSingleton().getSceneManager(); 60 showFPS = true; 61 showRenderTime = true; 62 63 // create Factories 51 64 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 52 65 om->addOverlayElementFactory(barOverlayElementFactory); … … 56 69 orxonoxHUD = om->create("Orxonox/HUD"); 57 70 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); 58 // test 59 test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123")); 60 test->show(); 61 test->setMetricsMode(Ogre::GMM_RELATIVE); 62 test->setDimensions(0.8, 0.8); 63 test->setPosition(0.02, 0.02); 64 test->setFontName("Console"); 65 test->setCaption("init"); 71 72 // creating text to display fps 73 fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText")); 74 fpsText->show(); 75 fpsText->setMetricsMode(Ogre::GMM_PIXELS); 76 fpsText->setDimensions(0.001, 0.001); 77 fpsText->setPosition(10, 10); 78 fpsText->setFontName("Console"); 79 fpsText->setCharHeight(20); 80 fpsText->setCaption("init"); 81 82 // creating text to display render time ratio 83 rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText")); 84 rTRText->show(); 85 rTRText->setMetricsMode(Ogre::GMM_PIXELS); 86 rTRText->setDimensions(0.001, 0.001); 87 rTRText->setPosition(10, 30); 88 rTRText->setFontName("Console"); 89 rTRText->setCharHeight(20); 90 rTRText->setCaption("init"); 66 91 67 92 // create energy bar … … 75 100 radar->show(); 76 101 77 // set up screen-wide container 102 // create Navigation 103 nav = new Navigation(container); 104 105 // set up screen-wide container 78 106 container->show(); 79 107 … … 85 113 container->setHeight(1.0); 86 114 container->setMetricsMode(Ogre::GMM_RELATIVE); 87 container->addChild(test); 115 container->addChild(fpsText); 116 container->addChild(rTRText); 117 88 118 energyBar->init(0.01, 0.94, 0.4, container); 89 119 energyBar->setValue(1); 120 90 121 speedoBar->init(0.01, 0.90, 0.4, container); 122 91 123 radar->init(0.5, 0.9, 0.2, container); 92 radar->addObject(Vector3(1500.0, 0.0, 100.0)); 93 radar->addObject(Vector3(0.0, 4000.0, 0.0)); 94 radar->addObject(Vector3(0.0, 0.0, 6800.0)); 95 RadarOverlayElement::cycleFocus(); 124 SceneNode* node; 125 node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0)); 126 addRadarObject(node); 127 node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0)); 128 addRadarObject(node); 129 node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0)); 130 addRadarObject(node); 131 node = sm->getRootSceneNode()->createChildSceneNode("station", Vector3(10000.0,16000.0,0.0)); 132 addRadarObject(node, 3); 133 } 134 135 HUD::~HUD(){ 136 //todo: clean up objects 96 137 } 97 138 98 139 void HUD::tick(float dt) 99 140 { 100 int d = radar->getDist2Focus()/10;101 if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));102 else test->setCaption("");103 104 141 energyBar->resize(); 105 142 106 float v = SpaceShip::instance_s->getVelocity().length(); 107 float vmax = SpaceShip::instance_s->getMaxSpeed(); 143 if(!SpaceShip::getLocalShip()) 144 return; 145 float v = SpaceShip::getLocalShip()->getVelocity().length(); 146 float vmax = SpaceShip::getLocalShip()->getMaxSpeed(); 108 147 speedoBar->setValue(v/vmax); 109 148 speedoBar->resize(); … … 111 150 radar->resize(); 112 151 radar->update(); 113 } 114 115 HUD::~HUD(void){ 152 153 nav->update(); 154 155 setFPS(); 156 } 157 158 void HUD::setRenderTimeRatio(float ratio) 159 { 160 if(showRenderTime){ 161 rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio)); 162 } 163 else{ 164 rTRText->setCaption(""); 165 return; 166 } 167 } 168 169 void HUD::setFPS(){ 170 if(showFPS){ 171 float fps = GraphicsEngine::getSingleton().getAverageFPS(); 172 fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps)); 173 } 174 else{ 175 fpsText->setCaption(""); 176 return; 177 } 178 } 179 180 void HUD::addRadarObject(SceneNode* node, int colour){ 181 RadarObject* obj = new RadarObject(container, node, colour); 182 roSet.insert(obj); 183 // // check if this is the first RadarObject to create 184 // if(firstRadarObject == NULL){ 185 // firstRadarObject = new RadarObject(container, node, colour); 186 // lastRadarObject = firstRadarObject; 187 // } 188 // else{ // if not, append to list 189 // lastRadarObject->next = new RadarObject(container, node, colour); 190 // lastRadarObject = lastRadarObject->next; 191 // } 192 } 193 194 void HUD::removeRadarObject(Ogre::SceneNode* node){ 195 COUT(3) << "blabla" << std::endl; 196 for(std::set<RadarObject*>::iterator it=roSet.begin(); it!=roSet.end(); it++){ 197 if((*it)->getNode() == node) { 198 delete (*it); 199 roSet.erase(it); 200 } 201 } 202 } 203 204 /*static*/ HUD& HUD::getSingleton(){ 205 static HUD theInstance; 206 return theInstance; 207 } 208 209 /*static*/ void HUD::setEnergy(float value){ 210 HUD::getSingleton().energyBar->setValue(value); 211 } 212 213 /*static*/ void HUD::cycleNavigationFocus(){ 214 HUD::getSingleton().nav->cycleFocus(); 215 } 216 217 /*static*/ void HUD::toggleFPS(){ 218 HUD::getSingleton().showFPS = !HUD::getSingleton().showFPS; 219 } 220 221 /*static*/ void HUD::toggleRenderTime(){ 222 HUD::getSingleton().showRenderTime = !HUD::getSingleton().showRenderTime; 116 223 } 117 224 } -
code/trunk/src/orxonox/hud/HUD.h
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 29 … … 30 31 #define _HUD_H__ 31 32 32 #include <string.h> 33 #include <OgreOverlayElement.h> 33 #include "OrxonoxPrereqs.h" 34 35 #include <OgrePrerequisites.h> 34 36 #include <OgreTextAreaOverlayElement.h> 35 #include <OgrePrerequisites.h> 36 37 #include "OrxonoxPrereqs.h" 37 #include <OgreSceneNode.h> 38 38 #include "core/Tickable.h" 39 #include "BarOverlayElement.h" 40 #include "RadarOverlayElement.h" 41 39 #include "util/Math.h" 42 40 43 41 namespace orxonox … … 45 43 class _OrxonoxExport HUD : public Tickable 46 44 { 47 private: 48 Ogre::OverlayManager* om; 49 Ogre::Overlay* orxonoxHUD; 50 Ogre::OverlayContainer* container; 51 Ogre::TextAreaOverlayElement* test; 52 BarOverlayElement* energyBar; 53 BarOverlayElement* speedoBar; 54 RadarOverlayElement* radar; 45 private: 46 HUD(); 47 HUD(HUD& instance); 48 ~HUD(); 49 Ogre::OverlayManager* om; 50 Ogre::SceneManager* sm; 51 Ogre::Overlay* orxonoxHUD; 52 Ogre::OverlayContainer* container; 53 Ogre::TextAreaOverlayElement* fpsText; 54 Ogre::TextAreaOverlayElement* rTRText; 55 BarOverlayElement* energyBar; 56 BarOverlayElement* speedoBar; 57 RadarOverlayElement* radar; 58 Navigation* nav; 55 59 56 public: 57 HUD(int zoom); 58 ~HUD(); 59 virtual void tick(float); 60 bool showFPS; 61 bool showRenderTime; 60 62 63 public: 64 virtual void tick(float); 65 void addRadarObject(Ogre::SceneNode* node, int colour = 0); 66 void removeRadarObject(Ogre::SceneNode* node); 67 void setRenderTimeRatio(float ratio); 68 void setFPS(); 69 70 std::set<RadarObject*> roSet; 71 72 static HUD* instance_s; 73 static HUD& getSingleton(); 74 static void setEnergy(float value); 75 static void cycleNavigationFocus(); 76 static void toggleFPS(); 77 static void toggleRenderTime(); 61 78 }; 62 79 } 63 80 64 #endif 81 #endif /* _HUD_H__ */ -
code/trunk/src/orxonox/hud/OverlayElementFactories.h
r1362 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 #ifndef _ FACTORIES_H__29 #define _ FACTORIES_H__29 #ifndef _OverlayElementFactories_H__ 30 #define _OverlayElementFactories_H__ 30 31 32 #include "OrxonoxPrereqs.h" 33 34 #include <OgrePrerequisites.h> 31 35 #include <OgreOverlayElement.h> 32 #include <OgrePrerequisites.h>33 36 #include <OgreOverlayElementFactory.h> 34 37 35 38 #include "BarOverlayElement.h" 39 #include "RadarOverlayElement.h" 36 40 37 41 namespace orxonox{ 38 42 class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{ 39 43 public: 40 44 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 41 45 return new BarOverlayElement(instanceName); … … 48 52 49 53 class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{ 50 54 public: 51 55 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 52 56 return new RadarOverlayElement(instanceName); … … 59 63 } 60 64 61 #endif 65 #endif /* _OverlayElementFactories_H__ */ -
code/trunk/src/orxonox/hud/RadarObject.cc
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Felix Schulthess 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Felix Schulthess 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 28 30 #include "RadarObject.h" 31 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 34 #include "GraphicsEngine.h" 29 35 30 36 namespace orxonox … … 32 38 using namespace Ogre; 33 39 34 40 int RadarObject::count = 0; // initialize static variable 35 41 36 RadarObject::RadarObject(Ogre::OverlayContainer* container){ 37 container_ = container; 38 pos_ = Vector3(0.0, 0.0, 0.0); 39 init(); 40 } 41 42 RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){ 43 container_ = container; 44 pos_ = pos; 45 init(); 46 } 47 48 RadarObject::~RadarObject(){} 49 50 void RadarObject::init(){ 51 next = NULL; 52 om = &Ogre::OverlayManager::getSingleton(); 53 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 54 "Object"+Ogre::StringConverter::toString(count))); 55 panel_->setMaterialName("Orxonox/RedDot"); 56 panel_->setDimensions(3,3); 42 RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){ 43 container_ = container; 44 node_ = node; 45 colour_ = colour; 46 om = &OverlayManager::getSingleton(); 47 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 48 "Object"+StringConverter::toString(count))); 49 setColour(colour_); 50 panel_->setDimensions(3,3); 57 51 panel_->setMetricsMode(Ogre::GMM_PIXELS); 58 52 panel_->show(); … … 60 54 count++; 61 55 container_->addChild(panel_); 62 } 56 } 57 58 RadarObject::~RadarObject(){ 59 delete panel_; 60 } 61 62 void RadarObject::setColour(int colour){ 63 switch(colour){ 64 case RED: panel_->setMaterialName("Orxonox/RedDot"); break; 65 case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break; 66 case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break; 67 case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break; 68 case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break; 69 default: panel_->setMaterialName("Orxonox/RedDot"); break; 70 } 71 } 72 73 void RadarObject::resetColour(){ 74 setColour(colour_); 75 } 76 77 Vector3 RadarObject::getPosition(){ 78 return node_->getPosition(); 79 } 80 81 SceneNode* RadarObject::getNode(){ 82 return node_; 83 } 63 84 } 64 85 65 /* my local clipboard...66 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";67 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl;68 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";69 */ -
code/trunk/src/orxonox/hud/RadarObject.h
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Felix Schulthess 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 28 #ifndef _R ADAR2_H__29 #define _R ADAR2_H__29 #ifndef _RadarObject_H__ 30 #define _RadarObject_H__ 30 31 31 #include <string.h>32 32 #include <OgrePrerequisites.h> 33 #include <OgreOverlayManager.h> 34 #include <OgreOverlayElement.h> 33 #include <OgreSceneNode.h> 35 34 #include <OgrePanelOverlayElement.h> 36 #include <OgreStringConverter.h> 37 38 #include <util/Math.h> 39 #include "../OrxonoxPrereqs.h" 35 #include "OrxonoxPrereqs.h" 36 #include "util/Math.h" 40 37 41 38 namespace orxonox … … 43 40 class _OrxonoxExport RadarObject 44 41 { 45 private: 46 Ogre::OverlayManager* om; // our one and only overlay manager 47 void init(); 42 private: 43 Ogre::OverlayManager* om; // our one and only overlay manager 44 Ogre::SceneNode* node_; // node of object 45 int colour_; 48 46 49 public: 50 RadarObject(Ogre::OverlayContainer* container); 51 RadarObject(Ogre::OverlayContainer* container, Vector3 pos); 52 ~RadarObject(); 47 public: 48 RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, int colour = 0); 49 ~RadarObject(); 50 void setColour(int colour); 51 void resetColour(); 52 Vector3 getPosition(); 53 Ogre::SceneNode* getNode(); 53 54 54 bool right_; 55 int index_; // index number of object 56 Vector3 pos_; // position in space 57 Ogre::Real radius_, phi_; // position on radar 58 Ogre::OverlayContainer* container_; 59 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 60 RadarObject* next; // next pointer of linked list 55 bool right_; 56 int index_; // index number of object 57 Ogre::OverlayContainer* container_; 58 Ogre::PanelOverlayElement* panel_; // the panel used to show the dot 61 59 62 static int count; 63 }; 60 static int count; 61 static const int RED = 0; 62 static const int YELLOW = 1; 63 static const int GREEN = 2; 64 static const int BLUE = 3; 65 static const int WHITE = 99; // used if object got nav focus 66 }; 64 67 } 65 68 66 #endif 69 #endif /* _RadarObject_H__ */ -
code/trunk/src/orxonox/hud/RadarOverlayElement.cc
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 29 #include "OrxonoxStableHeaders.h" 28 30 #include "RadarOverlayElement.h" 31 32 #include <string> 33 #include <OgreOverlayManager.h> 34 #include <OgreStringConverter.h> 35 36 #include "GraphicsEngine.h" 37 #include "core/Tickable.h" 38 #include "core/ConsoleCommand.h" 39 #include "objects/SpaceShip.h" 40 #include "RadarObject.h" 41 #include "HUD.h" 29 42 30 43 namespace orxonox 31 44 { 32 ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);33 34 45 using namespace Ogre; 35 46 36 RadarOverlayElement* RadarOverlayElement::instance_s = NULL; 37 38 RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 39 RadarOverlayElement::instance_s = this; 47 RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ 40 48 } 41 49 … … 43 51 } 44 52 45 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, O gre::OverlayContainer* container){53 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 46 54 // some initial data 47 om = &Ogre::OverlayManager::getSingleton();55 om = &OverlayManager::getSingleton(); 48 56 dimRel_ = dimRel; 49 57 leftRel_ = leftRel; 50 58 topRel_ = topRel; 51 59 container_ = container; 52 firstRadarObject_ = NULL;53 lastRadarObject_ = NULL;54 focus_ = NULL;55 60 56 // create nav marker ... 57 navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker")); 58 navMarker_->setMetricsMode(Ogre::GMM_PIXELS); 59 navMarker_->setMaterialName("Orxonox/NavMarker"); 60 navMarker_->setDimensions(16,16); 61 navMarker_->setPosition(0,386); 62 navMarker_->hide(); 63 container_->addChild(navMarker_); 64 65 // these have to fit the data in the level 66 shipPos_ = Vector3(0.0, 0.0, 0.0); 67 initialDir_ = Vector3(1.0, 0.0, 0.0); 68 currentDir_ = initialDir_; 69 initialOrth_ = Vector3(0.0, 0.0, 1.0); 70 currentOrth_ = initialOrth_; 71 plane = Plane(currentDir_, shipPos_); 72 73 setMetricsMode(Ogre::GMM_PIXELS); 61 setMetricsMode(GMM_PIXELS); 74 62 setMaterialName("Orxonox/Radar"); 75 63 resize(); … … 90 78 91 79 void RadarOverlayElement::update() { 92 shipPos_ = SpaceShip::instance_s->getPosition(); 93 currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_; // according to beni.... 94 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 95 plane = Plane(currentDir_, shipPos_); 96 97 RadarObject* ro = firstRadarObject_; 80 shipPos_ = SpaceShip::getLocalShip()->getPosition(); 81 currentDir_ = SpaceShip::getLocalShip()->getDir(); 82 currentOrth_ = SpaceShip::getLocalShip()->getOrth(); 98 83 // iterate through all RadarObjects 99 while(ro != NULL){100 101 ro->radius_ = calcRadius(ro);102 ro->phi_ = calcPhi(ro);103 ro->right_ = calcRight(ro);84 for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){ 85 // calc position on radar... 86 float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it)); 87 float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it)); 88 bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it)); 104 89 105 90 // set size to fit distance... 106 float d = (ro->pos_-shipPos_).length(); 107 if(d<4000) ro->panel_->setDimensions(4,4); 108 else if(d<8000) ro->panel_->setDimensions(3,3); 109 else if(d<16000) ro->panel_->setDimensions(2,2); 110 else ro->panel_->setDimensions(1,1); 91 float d = ((*it)->getPosition()-shipPos_).length(); 92 if(d<10000) (*it)->panel_->setDimensions(4,4); 93 else if(d<20000) (*it)->panel_->setDimensions(3,3); 94 else (*it)->panel_->setDimensions(2,2); 111 95 112 if (r o->right_){113 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/114 3.5*dim_/2+dim_/2+left_-2,-cos( ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);96 if (right){ 97 (*it)->panel_->setPosition(sin(phi)*radius/ 98 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 115 99 } 116 100 else { 117 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/ 118 3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2); 119 } 120 ro = ro->next; 121 } 122 updateNavMarker(); 123 } 124 125 void RadarOverlayElement::updateNavMarker(){ 126 if(focus_ == NULL) return; 127 // from the angle we find out where to draw the marker 128 // and which of the four arrows to take 129 float r1 = atan((float)(windowW_)/(float)(windowH_)); 130 float phi = focus_->phi_; 131 if(focus_->right_){ 132 if(phi<r1){ 133 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0); 134 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 135 } 136 else if(phi>3.14-r1){ 137 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16); 138 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 139 } 140 else { 141 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2); 142 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 143 } 144 } 145 else{ 146 if(phi<r1) { 147 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0); 148 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 149 } 150 else if(phi>3.14-r1) { 151 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16); 152 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 153 } 154 else { 155 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2); 156 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 101 (*it)->panel_->setPosition(-sin(phi)*radius/ 102 3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2); 157 103 } 158 104 } 159 105 } 160 106 161 void RadarOverlayElement::addObject(Vector3 pos){ 162 if(firstRadarObject_ == NULL){ 163 firstRadarObject_ = new RadarObject(container_, pos); 164 lastRadarObject_ = firstRadarObject_; 107 void RadarOverlayElement::listObjects(){ 108 int i = 0; 109 COUT(3) << "List of RadarObjects:\n"; 110 // iterate through all Radar Objects 111 for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){ 112 COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; 165 113 } 166 else{ 167 lastRadarObject_->next = new RadarObject(container_, pos); 168 lastRadarObject_ = lastRadarObject_->next; 169 } 170 } 114 } 171 115 172 void RadarOverlayElement::listObjects(){ 173 int i = 0; 174 RadarObject* ro = firstRadarObject_; 175 COUT(3) << "List of RadarObjects:\n"; 176 // iterate through all Radar Objects 177 while(ro != NULL) { 178 COUT(3) << i++ << ": " << ro->pos_ << std::endl; 179 ro = ro->next; 180 } 181 } 116 float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 117 return(acos((dir.dotProduct(obj->getPosition() - pos))/ 118 ((obj->getPosition() - pos).length()*dir.length()))); 119 } 182 120 183 float RadarOverlayElement::getDist2Focus(){ 184 if(focus_ == NULL) return(0.0); 185 return((focus_->pos_-shipPos_).length()); 186 } 121 float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 122 // project difference vector on our plane... 123 Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos); 124 // ...and find out the angle 125 return(acos((orth.dotProduct(proj))/ 126 (orth.length()*proj.length()))); 127 } 187 128 188 float RadarOverlayElement::calcRadius(RadarObject* obj){ 189 return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/ 190 ((obj->pos_ - shipPos_).length()*currentDir_.length()))); 191 } 192 193 float RadarOverlayElement::calcPhi(RadarObject* obj){ 194 // project difference vector on our plane... 195 Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_); 196 // ...and find out the angle 197 return(acos((currentOrth_.dotProduct(proj))/ 198 (currentOrth_.length()*proj.length()))); 199 } 200 201 bool RadarOverlayElement::calcRight(RadarObject* obj){ 202 if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0) 203 return true; 129 bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){ 130 if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0) 131 return true; 204 132 else return false; 205 } 206 207 /*static*/void RadarOverlayElement::cycleFocus(){ 208 if(RadarOverlayElement::instance_s == NULL) return; 209 210 if(RadarOverlayElement::instance_s->focus_ == NULL){ 211 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_; 212 } 213 else{ 214 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot"); 215 RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next; 216 } 217 218 if(RadarOverlayElement::instance_s->focus_ == NULL){ 219 RadarOverlayElement::instance_s->navMarker_->hide(); 220 } 221 else{ 222 RadarOverlayElement::instance_s->navMarker_->show(); 223 RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot"); 224 } 225 } 133 } 226 134 } 227 228 /* my local clipboard...229 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";230 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl;231 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";232 */ -
code/trunk/src/orxonox/hud/RadarOverlayElement.h
r1407 r1502 1 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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * Felix Schulthess 26 * 27 */ 27 28 28 #ifndef _R ADAR_H__29 #define _R ADAR_H__29 #ifndef _RadarOverlayElement_H__ 30 #define _RadarOverlayElement_H__ 30 31 31 #include <string.h> 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 34 #include <OgreOverlayElement.h> 32 #include "OrxonoxPrereqs.h" 33 34 #include <OgrePrerequisites.h> 35 35 #include <OgrePanelOverlayElement.h> 36 #include <OgrePrerequisites.h> 37 38 #include <util/Math.h> 39 #include <string.h> 40 #include "core/Tickable.h" 41 #include "core/ConsoleCommand.h" 42 #include "objects/SpaceShip.h" 43 #include "../OrxonoxPrereqs.h" 44 #include "RadarObject.h" 45 #include "GraphicsEngine.h" 36 #include "util/Math.h" 46 37 47 38 namespace orxonox … … 49 40 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement 50 41 { 51 private: 52 Ogre::OverlayManager* om; // our one and only overlay manager 53 Ogre::OverlayContainer* container_; // pointer to the container we're in 54 Vector3 initialDir_; // direction of nose 55 Vector3 currentDir_; 56 Vector3 initialOrth_; // direction of normal 57 Vector3 currentOrth_; 58 Vector3 shipPos_; // position of ship 59 Ogre::Plane plane; // plane perpendicular to dir 42 private: 43 Ogre::OverlayManager* om; // our one and only overlay manager 44 Ogre::OverlayContainer* container_; // pointer to the container we're in 45 Vector3 currentDir_; 46 Vector3 currentOrth_; 47 Vector3 shipPos_; // position of ship 60 48 61 62 63 int windowW_, windowH_;// absolute window dimensions49 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 50 int left_, top_, dim_; // absolute position/dimension 51 int windowW_, windowH_; // absolute window dimensions 64 52 65 public: 66 RadarOverlayElement(const Ogre::String& name); 67 ~RadarOverlayElement(); 68 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 69 void resize(); 70 void update(); 71 void updateNavMarker(); 72 void addObject(Vector3 pos); 73 void listObjects(); 74 float getDist2Focus(); 75 float calcRadius(RadarObject* obj); 76 float calcPhi(RadarObject* obj); 77 bool calcRight(RadarObject* obj); 53 public: 54 RadarOverlayElement(const Ogre::String& name); 55 ~RadarOverlayElement(); 56 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 57 void resize(); 58 void update(); 59 void listObjects(); 78 60 79 Ogre::PanelOverlayElement* navMarker_; // marker to help navigating 80 RadarObject* firstRadarObject_; // start of linked list 81 RadarObject* lastRadarObject_; // end of linked list 82 RadarObject* focus_; // object that is focussed 83 84 static RadarOverlayElement* instance_s; 85 static void cycleFocus(); 86 }; 61 static float calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 62 static float calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 63 static bool calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj); 64 }; 87 65 } 88 66 89 #endif 67 #endif /* _RadarOverlayElement_H__ */ -
code/trunk/src/orxonox/objects/Ambient.cc
r1293 r1502 47 47 namespace orxonox 48 48 { 49 ConsoleCommand(Ambient, setAmbientLightTest, AccessLevel::Offline, false).setDefaultValues(ColourValue(1, 1, 1, 1));49 SetConsoleCommand(Ambient, setAmbientLightTest, false).setDefaultValues(ColourValue(1, 1, 1, 1)).setAccessLevel(AccessLevel::Offline); 50 50 51 51 CreateFactory(Ambient); … … 66 66 bool Ambient::create(){ 67 67 GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_); 68 return true;68 return Synchronisable::create(); 69 69 } 70 70 -
code/trunk/src/orxonox/objects/Ambient.h
r1293 r1502 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 void setAmbientLight(const ColourValue& colour); 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 -
code/trunk/src/orxonox/objects/Camera.cc
r1293 r1502 60 60 { 61 61 CameraHandler::getInstance()->releaseFocus(this); 62 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName()); 62 63 } 63 64 … … 75 76 void Camera::tick(float dt) 76 77 { 77 if(this->positionNode_ != NULL) { 78 if (this->positionNode_ != NULL) 79 { 78 80 // this stuff here may need some adjustments 79 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition(); 80 this->cameraNode_->translate(15*dt*offset); 81 Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getWorldPosition(); 82 float coeff = 15.0f * dt; 83 if (coeff > 1.0f) 84 coeff = 1.0f; 81 85 82 this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 86 this->cameraNode_->translate(coeff * offset); 87 88 this->cameraNode_->setOrientation(Quaternion::Slerp(7.0f * dt, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false)); 83 89 } 84 90 } -
code/trunk/src/orxonox/objects/Camera.h
r1407 r1502 50 50 void setTargetNode(Ogre::SceneNode* obj); 51 51 52 Ogre::Camera* cam_; 53 52 54 void tick(float dt); 53 55 void update(); … … 63 65 Ogre::SceneNode* cameraNode_; 64 66 Ogre::Vector3 oldPos; 65 Ogre::Camera* cam_;66 67 bool bHasFocus_; 67 68 }; -
code/trunk/src/orxonox/objects/CameraHandler.cc
r1293 r1502 26 26 * 27 27 */ 28 #include "OrxonoxStableHeaders.h" 29 #include "CameraHandler.h" 30 28 31 #include <OgreSceneManager.h> 29 32 #include <OgreRenderWindow.h> 30 33 31 #include "OrxonoxStableHeaders.h"32 34 #include "core/ObjectList.h" 33 #include "CameraHandler.h"34 35 #include "Camera.h" 35 36 #include "GraphicsEngine.h" -
code/trunk/src/orxonox/objects/Explosion.cc
r1293 r1502 79 79 } 80 80 }; 81 82 /*bool Explosion::create(){ 83 if(!WorldEntity::create()) 84 return false; 85 classID=this->getIdentifier()->getNetworkID(); 86 }*/ 81 87 82 88 void Explosion::destroyObject() -
code/trunk/src/orxonox/objects/Explosion.h
r1056 r1502 43 43 virtual ~Explosion(); 44 44 void destroyObject(); 45 virtual bool create(){return WorldEntity::create();} 45 46 46 47 private: -
code/trunk/src/orxonox/objects/Model.cc
r1293 r1502 34 34 #include "GraphicsEngine.h" 35 35 #include "core/XMLPort.h" 36 37 #include <OgreEntity.h> 38 #include <OgreMesh.h> 39 #include <OgreHardwareVertexBuffer.h> 40 #include <OgreMeshManager.h> 41 36 42 37 43 namespace orxonox … … 77 83 this->mesh_.setMesh(meshSrc_); 78 84 this->attachObject(this->mesh_.getEntity()); 85 86 //HACK!! 87 /*if ((this->meshSrc_ == "assff.mesh") || (this->meshSrc_ == "ast1.mesh") || (this->meshSrc_ == "ast2.mesh") || (this->meshSrc_ == "ast3.mesh") || (this->meshSrc_ == "ast4.mesh") ||(this->meshSrc_ == "ast5.mesh") || (this->meshSrc_ == "ast6.mesh")) 88 { 89 Ogre::MeshPtr pMesh = this->mesh_.getEntity()->getMesh(); 90 //set Mesh to tangentspace 91 unsigned short src, dest; 92 if (!pMesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest)) 93 { 94 pMesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest); 95 } 96 if ((this->meshSrc_ == "assff.mesh")) 97 { 98 (this->mesh_.getEntity())->setMaterialName("Assff/BumpMap"); 99 } 100 else 101 { 102 (this->mesh_.getEntity())->setMaterialName("Asteroid/BumpMap"); 103 } 104 105 106 }*/ 79 107 COUT(4) << "Loader (Model.cc): Created model" << std::endl; 80 108 } -
code/trunk/src/orxonox/objects/Model.h
r1293 r1502 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 void setMesh(const std::string& meshname); 47 bool create();47 virtual bool create(); 48 48 49 49 protected: -
code/trunk/src/orxonox/objects/NPC.cc
r1293 r1502 67 67 } 68 68 69 bool NPC::create(){70 Model::create();71 return true;72 }73 69 74 70 /** -
code/trunk/src/orxonox/objects/NPC.h
r1293 r1502 53 53 void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable); 54 54 void registerAllVariables(); 55 bool create();55 virtual bool create(){return Model::create();} 56 56 57 57 private: -
code/trunk/src/orxonox/objects/Projectile.cc
r1360 r1502 30 30 #include "Projectile.h" 31 31 32 #include <OgreBillboard.h> 33 32 34 #include "core/CoreIncludes.h" 33 35 #include "core/Executor.h" … … 41 43 { 42 44 CreateFactory(Projectile); 45 46 float Projectile::speed_ = 0; 43 47 44 48 Projectile::Projectile(SpaceShip* owner) : … … 63 67 64 68 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject))); 65 this->classID = this->getIdentifier()->getNetworkID(); // TODO: remove this hack66 69 // COUT(3) << this->classID << std::endl; 67 70 } … … 92 95 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius)) 93 96 { 94 new Explosion(this); 97 Explosion *exp = new Explosion(this); 98 exp->create(); 95 99 delete this; 96 100 return; … … 104 108 delete this; 105 109 } 110 111 void Projectile::setColour(const ColourValue& colour) 112 { 113 this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour); 114 } 106 115 } -
code/trunk/src/orxonox/objects/Projectile.h
r1056 r1502 35 35 #include "../tools/BillboardSet.h" 36 36 #include "../tools/Timer.h" 37 #include "util/Math.h" 37 38 38 39 namespace orxonox … … 46 47 void destroyObject(); 47 48 virtual void tick(float dt); 49 virtual bool create(){return WorldEntity::create();} 50 void setColour(const ColourValue& colour); 51 52 static float getSpeed() 53 { return Projectile::speed_; } 54 55 protected: 56 SpaceShip* owner_; 48 57 49 58 private: 50 SpaceShip* owner_;51 59 BillboardSet billboard_; 52 float speed_;60 static float speed_; 53 61 float lifetime_; 54 62 Timer<Projectile> destroyTimer_; -
code/trunk/src/orxonox/objects/Skybox.cc
r1293 r1502 90 90 bool Skybox::create(){ 91 91 this->setSkybox(skyboxSrc_); 92 return true;92 return Synchronisable::create(); 93 93 } 94 94 -
code/trunk/src/orxonox/objects/Skybox.h
r1293 r1502 47 47 void setSkybox(const std::string& skyboxname); 48 48 49 bool create();49 virtual bool create(); 50 50 void registerAllVariables(); 51 51 void setSkyboxSrc(const std::string &src); -
code/trunk/src/orxonox/objects/SpaceShip.cc
r1407 r1502 45 45 #include "particle/ParticleInterface.h" 46 46 #include "Projectile.h" 47 #include "RotatingProjectile.h" 47 48 #include "core/XMLPort.h" 48 49 #include "core/ConsoleCommand.h" 49 50 #include "network/Client.h" 51 #include "hud/HUD.h" 50 52 51 53 namespace orxonox 52 54 { 53 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); 54 ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true); 55 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); 56 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); 57 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); 55 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 56 SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); 57 SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 58 SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 59 SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 60 SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 61 SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 62 SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); 63 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 64 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 65 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 58 66 59 67 CreateFactory(SpaceShip); … … 64 72 Iterator<SpaceShip> it; 65 73 for(it = ObjectList<SpaceShip>::start(); it; ++it){ 66 if( (it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ))74 if( (it)->myShip_ ) 67 75 return *it; 68 76 } 69 77 return NULL; 70 78 } 71 79 72 80 SpaceShip::SpaceShip() : 73 81 //testvector_(0,0,0), … … 103 111 mouseY_(0.0f), 104 112 emitterRate_(0.0f), 105 server_(false) 113 myShip_(false), 114 teamNr_(0), 115 health_(100) 106 116 { 107 117 RegisterObject(SpaceShip); … … 112 122 this->setConfigValues(); 113 123 124 initialDir_ = Vector3(1.0, 0.0, 0.0); 125 currentDir_ = initialDir_; 126 initialOrth_ = Vector3(0.0, 0.0, 1.0); 127 currentOrth_ = initialOrth_; 128 129 this->camName_ = this->getName() + "CamNode"; 114 130 115 131 this->setRotationAxis(1, 0, 0); … … 127 143 if (this->cam_) 128 144 delete this->cam_; 145 if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL) 146 //remove the radar object 147 HUD::getSingleton().removeRadarObject(this->getNode()); 129 148 } 130 149 131 150 bool SpaceShip::create(){ 151 if(!myShip_){ 152 if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) 153 myShip_=true; 154 else 155 HUD::getSingleton().addRadarObject(this->getNode(), 3); 156 } 132 157 if(Model::create()) 133 158 this->init(); … … 153 178 void SpaceShip::init() 154 179 { 155 if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))156 {157 if (!setMouseEventCallback_)158 {159 InputManager::addMouseHandler(this, "SpaceShip");160 //InputManager::enableMouseHandler("SpaceShip");161 setMouseEventCallback_ = true;162 }163 }164 165 180 // START CREATING THRUSTER 166 181 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 200 215 // END CREATING BLINKING LIGHTS 201 216 202 // START of testing crosshair 203 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 204 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 205 206 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 207 this->chNearNode_->setInheritScale(false); 208 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 209 this->chFarNode_->setInheritScale(false); 210 211 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 212 this->chNearNode_->setScale(0.2, 0.2, 0.2); 213 214 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 215 this->chFarNode_->setScale(0.4, 0.4, 0.4); 217 if (this->isExactlyA(Class(SpaceShip))) 218 { 219 // START of testing crosshair 220 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 221 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 222 223 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 224 this->chNearNode_->setInheritScale(false); 225 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 226 this->chFarNode_->setInheritScale(false); 227 228 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 229 this->chNearNode_->setScale(0.2, 0.2, 0.2); 230 231 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 232 this->chFarNode_->setScale(0.4, 0.4, 0.4); 233 } 216 234 217 235 createCamera(); … … 237 255 CameraHandler::getInstance()->requestFocus(cam_); 238 256 257 } 258 259 Camera* SpaceShip::getCamera(){ 260 return cam_; 239 261 } 240 262 … … 295 317 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 296 318 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 297 server_=true; // TODO: this is only a hack 319 myShip_=true; // TODO: this is only a hack 320 298 321 SpaceShip::create(); 299 getFocus(); 322 if (this->isExactlyA(Class(SpaceShip))) 323 getFocus(); 300 324 } 301 325 … … 308 332 } 309 333 310 void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)311 {312 /*313 this->mouseX += e.state.X.rel;314 if (this->bInvertMouse_)315 this->mouseY += e.state.Y.rel;316 else317 this->mouseY -= e.state.Y.rel;318 319 // if(mouseX>maxMouseX) maxMouseX = mouseX;320 // if(mouseX<minMouseX) minMouseX = mouseX;321 // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;322 323 this->moved = true;324 */325 if (this->bRMousePressed_)326 {327 this->camNode_->roll(Degree(-rel.x * 0.10));328 this->camNode_->yaw(Degree(rel.y * 0.10));329 }330 else331 {332 float minDimension = clippingSize.y;333 if (clippingSize.x < minDimension)334 minDimension = clippingSize.x;335 336 this->mouseX_ += rel.x;337 if (this->mouseX_ < -minDimension)338 this->mouseX_ = -minDimension;339 if (this->mouseX_ > minDimension)340 this->mouseX_ = minDimension;341 342 this->mouseY_ += rel.y;343 if (this->mouseY_ < -minDimension)344 this->mouseY_ = -minDimension;345 if (this->mouseY_ > minDimension)346 this->mouseY_ = minDimension;347 348 float xRotation = this->mouseX_ / minDimension;349 xRotation = xRotation*xRotation * sgn(xRotation);350 xRotation *= -this->rotationAcceleration_;351 if (xRotation > this->maxRotation_)352 xRotation = this->maxRotation_;353 if (xRotation < -this->maxRotation_)354 xRotation = -this->maxRotation_;355 this->mouseXRotation_ = Radian(xRotation);356 357 float yRotation = this->mouseY_ / minDimension;358 yRotation = yRotation*yRotation * sgn(yRotation);359 yRotation *= this->rotationAcceleration_;360 if (yRotation > this->maxRotation_)361 yRotation = this->maxRotation_;362 if (yRotation < -this->maxRotation_)363 yRotation = -this->maxRotation_;364 this->mouseYRotation_ = Radian(yRotation);365 }366 }367 368 void SpaceShip::mouseButtonPressed(MouseButton::Enum id)369 {370 if (id == MouseButton::Left)371 this->bLMousePressed_ = true;372 else if (id == MouseButton::Right)373 this->bRMousePressed_ = true;374 }375 376 void SpaceShip::mouseButtonReleased(MouseButton::Enum id)377 {378 if (id == MouseButton::Left)379 this->bLMousePressed_ = false;380 else if (id == MouseButton::Right)381 {382 this->bRMousePressed_ = false;383 this->camNode_->resetOrientation();384 }385 }386 387 334 std::string SpaceShip::whereAmI() { 388 335 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) … … 391 338 } 392 339 393 Vector3 SpaceShip::get SPosition() {394 return SpaceShip::getLocalShip()->getPosition();395 } 396 397 Quaternion SpaceShip::getSOrientation(){398 return SpaceShip::getLocalShip()->getOrientation();340 Vector3 SpaceShip::getDir() { 341 return currentDir_; 342 } 343 344 Vector3 SpaceShip::getOrth(){ 345 return currentOrth_; 399 346 } 400 347 … … 403 350 void SpaceShip::tick(float dt) 404 351 { 352 currentDir_ = getOrientation()*initialDir_; 353 currentOrth_ = getOrientation()*initialOrth_; 354 405 355 if (this->cam_) 406 356 this->cam_->tick(dt); … … 422 372 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 423 373 { 424 425 Projectile *p = new Projectile(this); 426 374 375 Projectile *p; 376 if (this->isExactlyA(Class(SpaceShip))) 377 p = new RotatingProjectile(this); 378 else 379 p = new Projectile(this); 380 p->setColour(this->getProjectileColour()); 381 p->create(); 382 if(p->classID==0) 383 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 384 427 385 p->setBacksync(true); 428 386 this->timeToReload_ = this->reloadTime_; … … 495 453 } 496 454 497 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ )498 {499 COUT(4) << "steering our ship: " << objectID << std::endl;500 if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))501 this->acceleration_.x = this->translationAcceleration_;502 else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))503 this->acceleration_.x = -this->translationAcceleration_;504 else505 this->acceleration_.x = 0;506 507 if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))508 this->acceleration_.y = -this->translationAcceleration_;509 else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))510 this->acceleration_.y = this->translationAcceleration_;511 else512 this->acceleration_.y = 0;513 514 if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))515 this->momentum_ = Radian(-this->rotationAccelerationRadian_);516 else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))517 this->momentum_ = Radian(this->rotationAccelerationRadian_);518 else519 this->momentum_ = 0;520 }/*else521 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/522 455 523 456 WorldEntity::tick(dt); … … 533 466 else 534 467 this->tt_->setRate(0); 535 } 536 468 469 if( myShip_ ) 470 { 471 COUT(4) << "steering our ship: " << objectID << std::endl; 472 this->acceleration_.x = 0; 473 this->acceleration_.y = 0; 474 this->momentum_ = 0; 475 this->mouseXRotation_ = Radian(0); 476 this->mouseYRotation_ = Radian(0); 477 this->bLMousePressed_ = false; 478 }/*else 479 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 480 } 481 482 void SpaceShip::movePitch(float val) 483 { getLocalShip()->setMovePitch(val); } 484 void SpaceShip::moveYaw(float val) 485 { getLocalShip()->setMoveYaw(val); } 486 void SpaceShip::moveRoll(float val) 487 { getLocalShip()->setMoveRoll(val); } 488 void SpaceShip::moveLongitudinal(float val) 489 { getLocalShip()->setMoveLongitudinal(val); } 490 void SpaceShip::moveLateral(float val) 491 { getLocalShip()->setMoveLateral(val); } 492 void SpaceShip::fire() 493 { getLocalShip()->doFire(); } 494 495 void SpaceShip::setMovePitch(float val) 496 { 497 val = -val * val * sgn(val) * this->rotationAcceleration_; 498 if (val > this->maxRotation_) 499 val = this->maxRotation_; 500 if (val < -this->maxRotation_) 501 val = -this->maxRotation_; 502 this->mouseYRotation_ = Radian(val); 503 } 504 505 void SpaceShip::setMoveYaw(float val) 506 { 507 val = -val * val * sgn(val) * this->rotationAcceleration_; 508 if (val > this->maxRotation_) 509 val = this->maxRotation_; 510 if (val < -this->maxRotation_) 511 val = -this->maxRotation_; 512 this->mouseXRotation_ = Radian(val); 513 } 514 515 void SpaceShip::setMoveRoll(float val) 516 { 517 this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val); 518 //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl; 519 } 520 521 void SpaceShip::setMoveLongitudinal(float val) 522 { 523 this->acceleration_.x = this->translationAcceleration_ * val; 524 } 525 526 void SpaceShip::setMoveLateral(float val) 527 { 528 this->acceleration_.y = -this->translationAcceleration_ * val; 529 } 530 531 void SpaceShip::doFire() 532 { 533 this->bLMousePressed_ = true; 534 } 537 535 } -
code/trunk/src/orxonox/objects/SpaceShip.h
r1407 r1502 41 41 namespace orxonox 42 42 { 43 class _OrxonoxExport SpaceShip : public Model , public MouseHandler43 class _OrxonoxExport SpaceShip : public Model 44 44 { 45 45 public: 46 46 47 47 static SpaceShip *getLocalShip(); 48 48 49 49 SpaceShip(); 50 50 ~SpaceShip(); 51 bool create();51 virtual bool create(); 52 52 void registerAllVariables(); 53 53 void init(); … … 64 64 void setTransDamp(float value); 65 65 void setRotDamp(float value); 66 void getFocus(); 66 67 67 void getFocus();68 static SpaceShip* instance_s;69 static Vector3 getSPosition();70 static Quaternion getSOrientation();71 68 static std::string whereAmI(); 72 69 static void setMaxSpeedTest(float value) 73 70 { SpaceShip::instance_s->setMaxSpeed(value); } 74 71 75 void mouseButtonPressed (MouseButton::Enum id); 76 void mouseButtonReleased(MouseButton::Enum id); 77 void mouseButtonHeld (MouseButton::Enum id) { } 78 void mouseMoved (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize); 79 void mouseScrolled (int abs, int rel) { } 72 static void movePitch(float value); 73 static void moveYaw(float value); 74 static void moveRoll(float value); 75 static void moveLongitudinal(float value); 76 static void moveLateral(float value); 77 static void fire(); 78 void setMovePitch(float value); 79 void setMoveYaw(float value); 80 void setMoveRoll(float value); 81 void setMoveLongitudinal(float value); 82 void setMoveLateral(float value); 83 void doFire(); 80 84 81 85 float getMaxSpeed(); 86 Vector3 getDir(); 87 Vector3 getOrth(); 88 Camera* getCamera(); 89 90 int getTeamNr() const 91 { return this->teamNr_; } 92 int getHealth() const 93 { return this->health_; } 94 95 bool getMyShip(){return myShip_;} 96 97 protected: 98 void setTeamNr(int teamNr) 99 { this->teamNr_ = teamNr; } 82 100 83 101 private: 84 102 void createCamera(); 103 virtual ColourValue getProjectileColour() const 104 { return ColourValue(1.0, 1.0, 0.5); } 85 105 86 106 Vector3 testvector_; 107 Vector3 initialDir_; 108 Vector3 currentDir_; 109 Vector3 initialOrth_; 110 Vector3 currentOrth_; 87 111 bool bInvertYAxis_; 88 112 bool setMouseEventCallback_; … … 130 154 131 155 float emitterRate_; 132 bool server_; 156 157 protected: 158 bool myShip_; 159 160 int teamNr_; 161 int health_; 162 163 static SpaceShip* instance_s; 133 164 }; 134 165 } -
code/trunk/src/orxonox/objects/WorldEntity.cc
r1360 r1502 85 85 this->rotationRate_ += (dt * this->momentum_); 86 86 this->rotate(this->rotationAxis_, dt * this->rotationRate_); 87 //COUT(3) << "rotationrate: " << this->rotationRate_.valueDegrees() << " momentum: " << this->momentum_.valueDegrees() << std::endl; 87 88 } 88 89 } … … 153 154 registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3); 154 155 //register acceleration & momentum 155 registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);156 registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);157 registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);158 registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA); 156 // registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x2); 157 // registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x2); 158 // registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x2); 159 // registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA, 0x2); // only backsync 159 160 } 160 161 -
code/trunk/src/orxonox/objects/WorldEntity.h
r1227 r1502 53 53 virtual void loadParams(TiXmlElement* xmlElem); 54 54 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 55 inline bool create(){ return true; }55 virtual inline bool create(){ return Synchronisable::create(); } 56 56 57 57 void attachWorldEntity(WorldEntity* entity); -
code/trunk/src/orxonox/objects/weapon/AmmunitionDump.h
r1056 r1502 60 60 61 61 protected: 62 inline bool create() { return true; }62 inline bool create() { return Synchronisable::create(); } 63 63 void registerAllVariables(); 64 64 -
code/trunk/src/orxonox/objects/weapon/BulletManager.h
r1209 r1502 60 60 61 61 protected: 62 inline bool create() { return true; }62 inline bool create() { return Synchronisable::create(); } 63 63 void registerAllVariables(); 64 64 -
code/trunk/src/orxonox/tools/Mesh.cc
r1056 r1502 40 40 unsigned int Mesh::meshCounter_s = 0; 41 41 42 Mesh::Mesh() 42 Mesh::Mesh() : 43 entity_(0) 43 44 { 44 this->entity_ = 0;45 45 } 46 46 -
code/trunk/src/orxonox/tools/Timer.cc
r1293 r1502 27 27 */ 28 28 29 #include <set> 30 29 31 #include "OrxonoxStableHeaders.h" 30 32 #include "Timer.h" … … 37 39 namespace orxonox 38 40 { 39 ConsoleCommandShortcutExtern(delay, AccessLevel::None); 41 SetConsoleCommandShortcutExtern(delay); 42 SetConsoleCommandShortcutExtern(killdelays); 43 44 static std::set<StaticTimer*> delaytimerset; 40 45 41 46 /** … … 47 52 { 48 53 StaticTimer *delaytimer = new StaticTimer(); 54 delaytimerset.insert(delaytimer); 55 49 56 ExecutorStatic* delayexecutor = createExecutor(createFunctor(&executeDelayedCommand)); 50 57 delayexecutor->setDefaultValues(delaytimer, command); … … 61 68 CommandExecutor::execute(command); 62 69 delete timer; 70 delaytimerset.erase(timer); 71 } 72 73 /** 74 @brief Kills all delayed commands. 75 */ 76 void killdelays() 77 { 78 for (std::set<StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it) 79 delete (*it); 80 81 delaytimerset.clear(); 63 82 } 64 83 -
code/trunk/src/orxonox/tools/Timer.h
r1056 r1502 69 69 class StaticTimer; 70 70 void delay(float delay, const std::string& command); 71 void killdelays(); 71 72 void executeDelayedCommand(StaticTimer* timer, const std::string& command); 72 73
Note: See TracChangeset
for help on using the changeset viewer.