GUI

GUI I.
Ogre3D Overlay
Project initialization









http://cg.iit.bme.hu/gamedev/KIC/06_GUI/
06_01_Ogre3D_Overlays_Base.zip
Extract
Run: OgreOverlays.sln
Set include and library paths (if not correct)
Set working directory (if not $(SolutionDir)/bin)
Compile
Run
Play !!
Ghost Buster Game
Newness / implementation



One mesh model, Phong shading, post processing
Camera motion(CameraAnimation : public
FrameListener)
 Text file (bin\cameraanim.txt)
 Animation stops at given time positions (const float
stopTimes[])
Ghosts:
 Particle system, billboards (media\ghosts.particle)
 1 emitter, adjusting emission rate at animation stop
and resume times
Newness / implementation

Counting the number of ghost births


Register a ParticleAffector
descendant(GhostCounter : public
ParticleAffector)
Shot ghosts




Need pixel-wise solution
ID map
How to set an ID to particles ???
How to read back the ID map ???
HUD, Overlay
HUD.h
#ifndef HUD_H
#define HUD_H
#include "stdafx.h"
#include "Ogre.h"
main.cpp
#include “HUD.h”
...
HUD* mainHUD;
...
void setupScene()
{
…
mainHUD = new HUD();
}
class HUD
{
public:
HUD()
{
Ogre::Overlay* mainOverlay =
Ogre::OverlayManager::getSingleton().getByName("MainOverlay");
mainOverlay->show();
}
};
#endif
/* HUD_H */
HUD.overlay
MainOverlay
{
container Panel(MainContainer)
{
transparent true
left 0
top 0
width 1
height 1
element Panel(GhostIDMap)
{
left 0.8
top 0.0
width 0.2
height 0.2
material HUD/IDMAP
transparent false
uv_coords 0 0 1 1
}
}
}
material HUD/IDMAP
{
technique
{
pass
{
lighting off
texture_unit
{
texture idMap
}
}
}
}
unique names
relative,
parent space values
absolute,
screen space values
Run
Cross-hair, hiding the cursor
inputs.h
#if defined OIS_WIN32_PLATFORM
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_FOREGROUND" )));
pl.insert(std::make_pair(std::string("w32_mouse"),
std::string("DISCL_NONEXCLUSIVE")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_FOREGROUND")));
pl.insert(std::make_pair(std::string("w32_keyboard"),
std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM
pl.insert(std::make_pair(std::string("x11_mouse_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_mouse_hide"),
std::string("false")));
pl.insert(std::make_pair(std::string("x11_keyboard_grab"),
std::string("false")));
pl.insert(std::make_pair(std::string("XAutoRepeatOn"),
std::string("true")));
#endif
Cross-hair image
MainOverlay
{
container Panel(MainContainer)
{
….
element Panel(Cross)
{
metrics_mode pixels
width 20
height 20
material HUD/crosshair
uv_coords 0 0 1 1
}
material HUD/crosshair
{
technique
{
pass
{
lighting off
scene_blend add
texture_unit
{
texture crosshair.jpg
}
}
}
}
Cross-hair movement I.
class HUD
{
float cursorSize;
float cursorScaler;
public:
HUD()
{
...
cursorSize = 20;
cursorScaler = 1;
}
void setCursorPos(float x, float y)
{
Ogre::OverlayElement* cursor = Ogre::OverlayManager::getSingleton()
.getOverlayElement("Cross", false);
cursor->setPosition(x-cursorScaler*cursorSize*0.5f, y-cursorScaler*cursorSize*0.5f);
}
};
void setCursorSize(float scaler)
{
cursorScaler = scaler;
Ogre::OverlayElement* cursor = Ogre::OverlayManager::getSingleton()
.getOverlayElement("Cross", false);
cursor->setWidth(cursorScaler*cursorSize);
cursor->setHeight(cursorScaler*cursorSize);
}
Cross-hair movement II.
class ShootController
{
public:
bool handleEvent(float t, float dt, OIS::Keyboard* keyboard, OIS::Mouse*
mouse)
{
unsigned int w = renderWindow->getWidth();
unsigned int h = renderWindow->getHeight();
unsigned int mouseX = mouse->getMouseState().X.abs;
unsigned int mouseY = mouse->getMouseState().Y.abs;
if(mouse->getMouseState().buttonDown(OIS::MB_Left))
{
mainHUD->setCursorSize(2.0);
…
}
else
{
mainHUD->setCursorSize(1.0);
}
mainHUD->setCursorPos(mouseX, mouseY);
}
return true;
Test
2012. 11. 8.
Diplaying current score I.
MainOverlay
{
container Panel(TMP)
{
transparent true
element TextArea(TMPTEXT)
{
font_name TrebuchetMSBold
caption blablablab
}
}
container Panel(MainContainer)
{
left 0
top 0
width 1
height 1
element TextArea(Score)
{
left 0.02
width 0.2
top 0.02
height 0.06
char_height 0.04
font_name TrebuchetMSBold
caption 0/0
}
BUG!!!???
Diplaying current score II.
class HUD
{
...
public:
...
void refreshScore(int allGhosts, int killedGhosts)
{
Ogre::String newCaption = Ogre::StringConverter::toString(killedGhosts) + "/" +
Ogre::StringConverter::toString(allGhosts);
Ogre::OverlayElement* score = Ogre::OverlayManager::getSingleton().getOverlayElement("Score");
score->setCaption(newCaption);
}
Main.cpp
printf("ghosts %i/%i\n", ghostBorn, ghostShooted);
mainHUD->refreshScore(ghostBorn, ghostShooted);
Test
2012. 11. 8.
Game statistics I.
template 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(GhostsTemplate)
{
left 0.35
width 0.153
top 0.045
height 0.06
char_height 0.04
alignment center
font_name TrebuchetMSBold
}
template element TextArea(KillsTemplate)
{
left 0.245
width 0.153
top 0.045
height 0.06
char_height 0.04
alignment center
font_name TrebuchetMSBold
}
template element TextArea(HealthTemplate)
{
left 0.47
width 0.153
top 0.045
height 0.06
char_height 0.04
alignment center
font_name TrebuchetMSBold
}
Game statistics II.
container Panel(MainContainer)
{
...
}
container Panel(PlayerStats)
{
left 0.2
top 0.02
width 0.6
height 0.6
material HUD/Stats
}
element TextArea(PlayerName) : PlayerTemplate
{
caption Player
}
element TextArea(PlayerKills) : KillsTemplate
{
caption Kills
}
element TextArea(PlayerGhosts) : GhostsTemplate
{
caption Ghosts
}
element TextArea(PlayerHealth) : HealthTemplate
{
caption Health
}
material HUD/Stats
{
technique
{
pass
{
lighting off
scene_blend alpha_blend
texture_unit
{
texture stats.png
}
}
}
}
Game statistics III.
class ShootController : public InputListener, public
RenderTargetListener
{
public:
bool handleEvent(float t, float dt, OIS::Keyboard* keyboard,
OIS::Mouse* mouse)
{
if(keyboard->isKeyDown(OIS::KC_SPACE)
&& mTimeUntilNextToggle < 0)
{
mainHUD->showStats();
mTimeUntilNextToggle = 1;
}
...
Game statistics IV.
class HUD
{
…
HUD()
{
…
Ogre::OverlayElement* stats = Ogre::OverlayManager::getSingleton().getOverlayElement("PlayerStats", false);
stats->hide();
}
void showStats()
{
Ogre::OverlayElement* stats = Ogre::OverlayManager::getSingleton().getOverlayElement("PlayerStats", false);
if(stats->isVisible())
stats->show()
else
stats->hide();
}
2012. 11. 8.
Example of inserting a new
element into the statistics table
Ogre::OverlayElement* ke =
Ogre::OverlayManager::getSingleton().
createOverlayElementFromTemplate(
"KillsTemplate",
"TextArea",
name + "Kills");
ke->setTop(ke->getTop() + 0.04 + 0.04 * (i+1));
The End
2012. 11. 8.