Top Banner
Ogre3D Overlay
27
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Ogre3D Overlay. HUD.h #pragma once #include "Ogre.h" #include "Player.h" class HUD { public: HUD(Player** players, int playerCount, int ID) { this->players.

Ogre3D Overlay

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

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;}

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

Hud.hvoid 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;}

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

HUD.hprotected:

Player** players;int playerCount;int ID;float FPS;float timeFromSecond;int framesInSecond;bool showStatistics;

};

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

HUD.overlayMainOverlay{

container Panel(MainContainer){

transparent trueleft 0top 0width 1height 1

element Panel(Cross) { left 0.48125 top 0.4975 width 0.0375 height 0.05 material HUD/crosshair transparent false uv_coords 0 0 1 1 }

}}

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

Client.h#include "HUD.h”

class Client{

protected:

HUD* mHUD;

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

Client.cppstart(){… inputManager-

>addInputListener(playerController);

mHUD = new HUD(players, numPlayers, clientID);

mainLoop();}

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

Próba

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

HUD.overlayMainOverlay{

container Panel(MainContainer){

…element Panel(HealthIcon) { left 0.75 top 0.85 width 0.075 height 0.1 material HUD/health transparent false uv_coords 0 0 1 1 } element TextArea(Health) { left 0.85 top 0.86 char_height 0.1 colour 1 1 0 font_name TrebuchetMSBold

caption 100 }

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

HUD.overlay…

element Panel(AmmoIcon) { left 0.75 top 0.7 width 0.075 height 0.1 material HUD/bullet transparent false uv_coords 0 0 1 1 } element TextArea(Bullet) { left 0.85 top 0.71 char_height 0.1 colour 1 1 0 font_name TrebuchetMSBold

caption 20 }

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

HUD.overlay…

container Panel(Statistics) {

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

caption 25}

}

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

Próba

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

Client.cppupdate(){…

fpsCamera->update(t, dt);

mHUD->update(t,dt);}

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

HUD.hupdate(){…

//update fpsOgre::OverlayElement* fpsText =

Ogre::OverlayManager::getSingleton().getOverlayElement("FPS");fpsText->setCaption(Ogre::StringConverter::toString(FPS, 4));

//update healts, bulletsOgre::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 statisticsOgre::OverlayElement* statistics =

Ogre::OverlayManager::getSingleton().getOverlayElement("Statistics");if(showStatistics)

statistics->show();else

statistics->hide();

showStatistics = false;

}

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

Próba

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

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;

}…

}

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

Client.cppstart(){… inputManager-

>addInputListener(playerController);

mHUD = new HUD(players, numPlayers, clientID);inputManager->addInputListener(mHUD);

mainLoop();}

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

Próba

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

HUD.overlaytemplate element

TextArea(PlayerTemplate){ left 0.106 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold}

template element TextArea(HealthTemplate)

{ left 0.245 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold}

template element TextArea(KillsTemplate){ left 0.35 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold}

template element TextArea(DeathsTemplate){ left 0.47 width 0.153 top 0.045 height 0.06 char_height 0.04 alignment center font_name TrebuchetMSBold}

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

HUD.overlaycontainer 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}

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

HUD.hprotected:

Player** players;int playerCount;int ID;float FPS;float timeFromSecond;int framesInSecond;bool showStatistics;Ogre::OverlayElement** healthTexts;Ogre::OverlayElement** killsTexts;Ogre::OverlayElement** deathsTexts;

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

HUD.hHUD(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}

}

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

HUD.hOgre::String name = "Player" + Ogre::StringConverter::toString(i);

Ogre::OverlayElement* pe = Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate(

"PlayerTemplate","TextArea",name);

pe->setTop(pe->getTop() + 0.04 + 0.04 * (i+1));pe->setCaption(name);if(i == ID)

pe->setColour(Ogre::ColourValue::Red);

playerStats->addChild(pe);…

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

HUD.hOgre::OverlayElement* he =

Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate(

"HealthTemplate","TextArea",name + "Health");

he->setTop(he->getTop() + 0.04 + 0.04 * (i+1));if(i == ID)

he->setColour(Ogre::ColourValue::Red);

playerStats->addChild(he);healthTexts[i] = he;

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

HUD.hOgre::OverlayElement* ke =

Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate(

"KillsTemplate","TextArea",name + "Kills");

ke->setTop(ke->getTop() + 0.04 + 0.04 * (i+1));if(i == ID)

ke->setColour(Ogre::ColourValue::Red);

playerStats->addChild(ke);killsTexts[i] = ke;

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

HUD.hOgre::OverlayElement* de =

Ogre::OverlayManager::getSingleton().createOverlayElementFromTemplate(

"DeathsTemplate","TextArea",name + "Deaths");

de->setTop(de->getTop() + 0.04 + 0.04 * (i+1));if(i == ID)

de->setColour(Ogre::ColourValue::Red);

playerStats->addChild(de);deathsTexts[i] = de;

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

HUD.hupdate(){…

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;}