[8987] | 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: |
---|
[9348] | 25 | * Fabian 'x3n' Landau |
---|
[8987] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "HUDEnemyHealthBar.h" |
---|
| 30 | |
---|
[9667] | 31 | #include "core/config/ConfigValueIncludes.h" |
---|
[9259] | 32 | #include "worldentities/pawns/Pawn.h" |
---|
[10171] | 33 | #include "graphics/Camera.h" |
---|
[8987] | 34 | |
---|
| 35 | namespace orxonox |
---|
| 36 | { |
---|
[9667] | 37 | RegisterClass(HUDEnemyHealthBar); |
---|
[8987] | 38 | |
---|
[9667] | 39 | HUDEnemyHealthBar::HUDEnemyHealthBar(Context* context) : HUDHealthBar(context) |
---|
[8987] | 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 | { |
---|
[9259] | 58 | this->updateTarget(); |
---|
[9348] | 59 | |
---|
[10171] | 60 | |
---|
| 61 | |
---|
| 62 | /* |
---|
| 63 | //-------------------------------------------------------------------------- |
---|
| 64 | //first try to place a healthbar under the enemy ship |
---|
| 65 | //getting all the parameters (direction, position, angle) to place the health bar on the screen |
---|
| 66 | |
---|
| 67 | Camera* camera = this->owner_->getCamera(); |
---|
| 68 | |
---|
| 69 | //position and orientation relative to the root space |
---|
| 70 | Vector3 cameraPosition = camera->getWorldPosition(); |
---|
| 71 | Quaternion cameraOrientation = camera->getWorldOrientation(); |
---|
| 72 | |
---|
| 73 | Vector3 cameraDirection = camera->FRONT; |
---|
| 74 | Vector3 cameraOrthonormal = camera->UP; |
---|
| 75 | |
---|
| 76 | //get target |
---|
| 77 | //if there is one get it's position (relative to the root space( |
---|
| 78 | WorldEntity* target = this->owner_->getTarget(); |
---|
| 79 | |
---|
| 80 | if(target != NULL){ |
---|
| 81 | Vector3 targetPosition = target->getWorldPosition(); |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | //try 1 |
---|
| 85 | Vector2 screenCoordinates = get2DViewcoordinates(cameraPosition, cameraOrientation * WorldEntity::FRONT, cameraOrientation * WorldEntity::UP, targetPosition); |
---|
| 86 | |
---|
| 87 | orxout() << screenCoordinates.x << endl; |
---|
| 88 | |
---|
| 89 | //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 |
---|
| 90 | screenCoordinates.x += 0.5; |
---|
| 91 | screenCoordinates.y += 0.5; |
---|
| 92 | orxout() << screenCoordinates.x << endl; |
---|
| 93 | |
---|
| 94 | this->setPosition(screenCoordinates); |
---|
| 95 | |
---|
| 96 | this->setTextOffset(screenCoordinates); |
---|
| 97 | } |
---|
| 98 | //-------------------------------------------------------------------------- |
---|
| 99 | */ |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
[9348] | 103 | SUPER(HUDEnemyHealthBar, tick, dt); |
---|
[8987] | 104 | } |
---|
| 105 | |
---|
[9259] | 106 | void HUDEnemyHealthBar::updateTarget() |
---|
[8987] | 107 | { |
---|
[9259] | 108 | Pawn* pawn = NULL; |
---|
| 109 | if (this->owner_ && this->useEnemyBar_) |
---|
[8987] | 110 | { |
---|
[9259] | 111 | // Get the owner's current target (target is usually a Model) |
---|
| 112 | WorldEntity* target = this->owner_->getTarget(); |
---|
| 113 | // Find the Pawn that belongs to this target (if any) |
---|
| 114 | while (target && !target->isA(Class(Pawn))) |
---|
| 115 | target = target->getParent(); |
---|
| 116 | pawn = orxonox_cast<Pawn*>(target); |
---|
[10171] | 117 | |
---|
| 118 | |
---|
[9259] | 119 | // Don't show the HealthBar if the pawn is invisible |
---|
| 120 | if (pawn && !pawn->isVisible()) |
---|
| 121 | pawn = NULL; |
---|
[8987] | 122 | } |
---|
[10171] | 123 | |
---|
[9259] | 124 | // Set the pawn as owner of the HealthBar |
---|
| 125 | this->setHealthBarOwner(pawn); |
---|
| 126 | this->setVisible(pawn != NULL); |
---|
[8987] | 127 | } |
---|
| 128 | |
---|
| 129 | void HUDEnemyHealthBar::changedOwner() |
---|
| 130 | { |
---|
[9348] | 131 | SUPER(HUDEnemyHealthBar, changedOwner); |
---|
| 132 | |
---|
| 133 | this->owner_ = orxonox_cast<ControllableEntity*>(this->getOwner()); |
---|
| 134 | this->updateTarget(); |
---|
[8987] | 135 | } |
---|
| 136 | } |
---|