Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hudHS14/src/modules/overlays/hud/HUDEnemyHealthBar.cc @ 10110

Last change on this file since 10110 was 10110, checked in by aejonas, 10 years ago

new way to display the healthbar on the screen (in a similar way like the existing ship marker)

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
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 *      Matthias Spalinger
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "HUDEnemyHealthBar.h"
30
31#include "core/config/ConfigValueIncludes.h"
32#include "worldentities/pawns/Pawn.h"
33#include "graphics/Camera.h"
34
35namespace orxonox
36{
37    RegisterClass(HUDEnemyHealthBar);
38
39    HUDEnemyHealthBar::HUDEnemyHealthBar(Context* context) : HUDHealthBar(context)
40    {
41        RegisterObject(HUDEnemyHealthBar);
42
43        this->setConfigValues();
44        this->owner_ = 0;
45    }
46
47    HUDEnemyHealthBar::~HUDEnemyHealthBar()
48    {
49    }
50
51    void HUDEnemyHealthBar::setConfigValues()
52    {
53        SetConfigValue(useEnemyBar_, true);
54    }
55
56    void HUDEnemyHealthBar::tick(float dt)
57    {
58        this->updateTarget();
59
60
61
62
63/*
64        //--------------------------------------------------------------------------
65        //first try to place a healthbar under the enemy ship
66        //getting all the parameters (direction, position, angle) to place the health bar on the screen
67
68        Camera* camera = this->owner_->getCamera();
69
70        //position and orientation relative to the root space
71        Vector3 cameraPosition = camera->getWorldPosition();
72        Quaternion cameraOrientation = camera->getWorldOrientation();
73
74        Vector3 cameraDirection = camera->FRONT;
75        Vector3 cameraOrthonormal = camera->UP;
76
77        //get target
78        //if there is one get it's position (relative to the root space(
79        WorldEntity* target = this->owner_->getTarget();
80
81        if(target != NULL){
82        Vector3 targetPosition = target->getWorldPosition();
83
84
85        //try 1
86        Vector2 screenCoordinates = get2DViewcoordinates(cameraPosition, cameraOrientation * WorldEntity::FRONT, cameraOrientation * WorldEntity::UP, targetPosition);
87
88        orxout() << screenCoordinates.x << endl;
89
90        //shift coordinates because the screen has it's root in the upper left corner (0,0) but get2Dviewcoordiantes return values between -0.5 and 0.5
91        screenCoordinates.x += 0.5;
92        screenCoordinates.y += 0.5;
93        orxout() << screenCoordinates.x << endl;
94
95        this->setPosition(screenCoordinates);
96
97        this->setTextOffset(screenCoordinates);
98
99
100
101
102
103        }
104
105        //--------------------------------------------------------------------------
106*/
107
108
109        SUPER(HUDEnemyHealthBar, tick, dt);
110    }
111
112    void HUDEnemyHealthBar::updateTarget()
113    {
114        Pawn* pawn = NULL;
115        if (this->owner_ && this->useEnemyBar_)
116        {
117            // Get the owner's current target (target is usually a Model)
118            WorldEntity* target = this->owner_->getTarget();
119            // Find the Pawn that belongs to this target (if any)
120            while (target && !target->isA(Class(Pawn)))
121                target = target->getParent();
122            pawn = orxonox_cast<Pawn*>(target);
123
124
125
126            /*Vector3 tempPosition = target->getWorldPosition();
127            Vector2 tempPos2D = Vector2(tempPosition.x, tempPosition.y);
128                     this->pickPoint_(tempPos2D);
129                     this->position_(tempPos2D);*/
130
131
132            // Don't show the HealthBar if the pawn is invisible
133            if (pawn && !pawn->isVisible())
134                pawn = NULL;
135        }
136
137        // Set the pawn as owner of the HealthBar
138        this->setHealthBarOwner(pawn);
139        this->setVisible(pawn != NULL);
140    }
141
142    void HUDEnemyHealthBar::changedOwner()
143    {
144        SUPER(HUDEnemyHealthBar, changedOwner);
145
146        this->owner_ = orxonox_cast<ControllableEntity*>(this->getOwner());
147        this->updateTarget();
148    }
149}
Note: See TracBrowser for help on using the repository browser.