players.">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ogre3D Overlay. HUD.h #pragma once #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, int playerCount, int ID) { this->players.

Similar presentations


Presentation on theme: "Ogre3D Overlay. HUD.h #pragma once #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, int playerCount, int ID) { this->players."— Presentation transcript:

1 Ogre3D Overlay

2 HUD.h #pragma once #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, int playerCount, int ID) { this->players = players; this->playerCount = playerCount; this->ID = ID; Ogre::Overlay* mainOverlay = Ogre::OverlayManager::getSingleton().getByName("MainOverlay"); mainOverlay->show(); timeFromSecond = 0; framesInSecond = 0; FPS = 0; showStatistics = false; }

3 Hud.h void update(float t, float dt) { timeFromSecond += dt; framesInSecond++; if(timeFromSecond >= 1) { FPS = framesInSecond / timeFromSecond; timeFromSecond = 0; framesInSecond = 0; } //update fps //update healts, bullets //show statistics showStatistics = false; } void showStats(){showStatistics = true;}

4 HUD.h protected: Player** players; int playerCount; int ID; float FPS; float timeFromSecond; int framesInSecond; bool showStatistics; };

5 HUD.overlay MainOverlay { container Panel(MainContainer) { transparent true left 0 top 0 width 1 height 1 element Panel(Cross) { left top width height 0.05 material HUD/crosshair transparent false uv_coords }

6 Client.h #include "HUD.h” class Client { protected: HUD* mHUD;

7 Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); mainLoop(); }

8 Próba

9 HUD.overlay MainOverlay { container Panel(MainContainer) { … element Panel(HealthIcon) { left 0.75 top 0.85 width height 0.1 material HUD/health transparent false uv_coords } element TextArea(Health) { left 0.85 top 0.86 char_height 0.1 colour font_name TrebuchetMSBold caption 100 } …

10 HUD.overlay … element Panel(AmmoIcon) { left 0.75 top 0.7 width height 0.1 material HUD/bullet transparent false uv_coords } element TextArea(Bullet) { left 0.85 top 0.71 char_height 0.1 colour font_name TrebuchetMSBold caption 20 } …

11 HUD.overlay … container Panel(Statistics) { left 0 right 0 width 1 height 1 container Panel(PlayerStats) { left 0.2 top 0.02 width 0.6 height 0.6 material HUD/Stats } element TextArea(FPS) { left 0.02 top 0.02 char_height 0.05 colour font_name TrebuchetMSBold caption 25 }

12 Próba

13 Client.cpp update() { … fpsCamera->update(t, dt); mHUD->update(t,dt); }

14 HUD.h update() { … //update fps Ogre::OverlayElement* fpsText = Ogre::OverlayManager::getSingleton().getOverlayElement("FPS"); fpsText->setCaption(Ogre::StringConverter::toString(FPS, 4)); //update healts, bullets Ogre::OverlayElement* healthText = Ogre::OverlayManager::getSingleton().getOverlayElement("Health"); healthText->setCaption(Ogre::StringConverter::toString(players[ID]->getData().life)); Ogre::OverlayElement* ammoText = Ogre::OverlayManager::getSingleton().getOverlayElement("Bullet"); ammoText->setCaption(Ogre::StringConverter::toString(players[ID]->getData().bullets)); //show statistics Ogre::OverlayElement* statistics = Ogre::OverlayManager::getSingleton().getOverlayElement("Statistics"); if(showStatistics) statistics->show(); else statistics->hide(); showStatistics = false; }

15 Próba

16 HUD.h #include "Inputs.h„ class HUD : public InputListener { public: … bool handleEvent(float t, float dt, OIS::Keyboard* keyboard, OIS::Mouse* mouse) { if(keyboard->isKeyDown(OIS::KC_TAB)) { showStatistics =! showStatistics; } return true; } … }

17 Client.cpp start() { … inputManager->addInputListener(playerController); mHUD = new HUD(players, numPlayers, clientID); inputManager->addInputListener(mHUD); mainLoop(); }

18 Próba

19 HUD.overlay template element TextArea(PlayerTemplate) { left width top height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold } template element TextArea(HealthTemplate) { left width top height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold } template element TextArea(KillsTemplate) { left 0.35 width top height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold } template element TextArea(DeathsTemplate) { left 0.47 width top height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold }

20 HUD.overlay container Panel(PlayerStats) { … element TextArea(PlayerName) : PlayerTemplate { caption Player } element TextArea(PlayerHealth) : HealthTemplate { caption Health } element TextArea(PlayerKills) : KillsTemplate { caption Kills } element TextArea(PlayerDeaths) : DeathsTemplate { caption Deaths } …

21 HUD.h protected: Player** players; int playerCount; int ID; float FPS; float timeFromSecond; int framesInSecond; bool showStatistics; Ogre::OverlayElement** healthTexts; Ogre::OverlayElement** killsTexts; Ogre::OverlayElement** deathsTexts;

22 HUD.h HUD(Player** players, int playerCount, int ID) { … healthTexts = new Ogre::OverlayElement*[playerCount]; killsTexts = new Ogre::OverlayElement*[playerCount]; deathsTexts = new Ogre::OverlayElement*[playerCount]; Ogre::OverlayContainer* playerStats = (Ogre::OverlayContainer*) Ogre::OverlayManager::getSingleton().getOverlayElement("PlayerStats"); for(int i = 0; i < playerCount; i++) { …következő 4 dia }

23 HUD.h Ogre::String name = "Player" + Ogre::StringConverter::toString(i); Ogre::OverlayElement* pe = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "PlayerTemplate", "TextArea", name); pe->setTop(pe->getTop() * (i+1)); pe->setCaption(name); if(i == ID) pe->setColour(Ogre::ColourValue::Red); playerStats->addChild(pe); …

24 HUD.h Ogre::OverlayElement* he = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "HealthTemplate", "TextArea", name + "Health"); he->setTop(he->getTop() * (i+1)); if(i == ID) he->setColour(Ogre::ColourValue::Red); playerStats->addChild(he); healthTexts[i] = he; …

25 HUD.h Ogre::OverlayElement* ke = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "KillsTemplate", "TextArea", name + "Kills"); ke->setTop(ke->getTop() * (i+1)); if(i == ID) ke->setColour(Ogre::ColourValue::Red); playerStats->addChild(ke); killsTexts[i] = ke; …

26 HUD.h Ogre::OverlayElement* de = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate( "DeathsTemplate", "TextArea", name + "Deaths"); de->setTop(de->getTop() * (i+1)); if(i == ID) de->setColour(Ogre::ColourValue::Red); playerStats->addChild(de); deathsTexts[i] = de;

27 HUD.h update() { … for(int i = 0; i < playerCount; i++) { healthTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().life)); killsTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().flags)); deathsTexts[i]->setCaption( Ogre::StringConverter::toString(players[i]->getData().deaths)); } showStatistics = false; }


Download ppt "Ogre3D Overlay. HUD.h #pragma once #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, int playerCount, int ID) { this->players."

Similar presentations


Ads by Google