Skip to content

Commit eff7d90

Browse files
committed
Add distance to target to display
1 parent 19bd28d commit eff7d90

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

Display.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Airplane.h"
1313
#include "Level.h"
14+
#include "Target.h"
1415
#include "World.h"
1516

1617
static const Ogre::String
@@ -19,6 +20,7 @@ static const Ogre::String
1920
OVERLAY_NAME = "Fly/HUD",
2021
INFO_BAR_NAME = "Fly/InfoBar",
2122
LEVEL_TEXT_BOX_NAME = "Fly/LevelName",
23+
DISTANCE_TEXT_BOX_NAME = "Fly/Distance",
2224
STATS_PANEL_NAME = "Fly/StatsPanel",
2325
POSITION_TEXT_BOX_NAME = "Fly/Position",
2426
VELOCITY_TEXT_BOX_NAME = "Fly/Velocity",
@@ -34,6 +36,7 @@ Display::Display(Game * game) :
3436
overlay(overlayMgr()->getByName(OVERLAY_NAME)),
3537
infoBar(overlay->getChild(INFO_BAR_NAME)),
3638
levelTextBox(getTextArea(LEVEL_TEXT_BOX_NAME, infoBar)),
39+
distanceTextBox(getTextArea(DISTANCE_TEXT_BOX_NAME, infoBar)),
3740
statsPanel(overlay->getChild(STATS_PANEL_NAME)),
3841
positionTextBox(getTextArea(POSITION_TEXT_BOX_NAME)),
3942
velocityTextBox(getTextArea(VELOCITY_TEXT_BOX_NAME)),
@@ -63,7 +66,10 @@ template<typename T> static inline Ogre::String toString(T x) { return Ogre::Str
6366
void Display::update(float dt) {
6467
const Airplane * const player = game->getWorld()->getPlayer();
6568
const AirplaneState& state = player->getState();
69+
6670
levelTextBox->setCaption(game->getCurrentLevel()->getName());
71+
distanceTextBox->setCaption(toString(game->getWorld()->getTarget()->displacement(player).length()) + "m");
72+
6773
positionTextBox->setCaption(toString(state.position));
6874
velocityTextBox->setCaption(toString(state.velocity));
6975
speedTextBox->setCaption(toString(state.velocity.length()));

Display.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Display {
1111

1212
Ogre::OverlayContainer * const infoBar;
1313
Ogre::TextAreaOverlayElement * const levelTextBox;
14-
14+
Ogre::TextAreaOverlayElement * const distanceTextBox;
15+
1516
Ogre::OverlayContainer * const statsPanel;
1617
Ogre::TextAreaOverlayElement * const positionTextBox;
1718
Ogre::TextAreaOverlayElement * const velocityTextBox;

Target.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Target.h"
22

3+
#include "Airplane.h"
34

45
Target::Target(Ogre::SceneNode * sceneNode) : sceneNode(sceneNode){
56

@@ -13,3 +14,7 @@ Target::Target(Ogre::SceneNode * sceneNode) : sceneNode(sceneNode){
1314
}
1415

1516
Target::~Target() { }
17+
18+
Ogre::Vector3 Target::displacement(const Airplane * airplane) const {
19+
return sceneNode->getPosition() - airplane->getPosition();
20+
}

Target.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ class Target{
66
public:
77
Target(Ogre::SceneNode *);
88
~Target();
9+
10+
Ogre::Vector3 displacement(const Airplane *) const;
911
};

World.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class World : public Object {
2727
Airplane * getPlayer() { return player; }
2828
const Airplane * getPlayer() const { return player; }
2929

30+
Target * getTarget() { return target; }
31+
const Target * getTarget() const { return target; }
32+
3033
static const Ogre::String GROUND_NODE_NAME;
3134

3235
private:

data/ui/scripts/hud.overlay

+21-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ template element TextArea(Fly/Label) : Fly/TextBox
1515
colour_bottom 1 1 1
1616
}
1717

18+
template element TextArea(Fly/InfoLabel) : Fly/Label
19+
{
20+
top 0.01
21+
height 0.05
22+
char_height 0.04
23+
}
24+
1825
template element TextArea(Fly/MaxedTextBox) : Fly/TextBox
1926
{
2027
colour 1 0 0
@@ -30,14 +37,24 @@ Fly/HUD
3037
height 0.05
3138
material StatsPanel_Material
3239

33-
element TextArea(Fly/LevelName) : Fly/Label
40+
element TextArea(Fly/LevelName) : Fly/InfoLabel
3441
{
35-
top 0.01
3642
left 0.375
3743
width 0.2
38-
height 0.05
3944
alignment center
40-
char_height 0.04
45+
}
46+
47+
element TextArea(Fly/DistanceLabel) : Fly/InfoLabel
48+
{
49+
left 0.7
50+
width 0.1
51+
caption To Target:
52+
}
53+
54+
element TextArea(Fly/Distance) : Fly/InfoLabel
55+
{
56+
left 0.825
57+
width 0.075
4158
}
4259
}
4360

0 commit comments

Comments
 (0)