diff options
author | Stijn Buys <ingar@osirion.org> | 2012-12-24 21:33:18 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-12-24 21:33:18 +0000 |
commit | fee209b6769ee6b207e9101c4f15e16c0a67ad09 (patch) | |
tree | 6a8c39a549c9884b17baacba3b9da8b00851c6b7 | |
parent | 2b54cd13579abe2b277e305b7c5cd2eff78d82cd (diff) |
Improved off-screen HUD target indicators.
-rw-r--r-- | src/client/hud.cc | 109 | ||||
-rw-r--r-- | src/math/matrix4f.cc | 3 | ||||
-rw-r--r-- | src/math/matrix4f.h | 2 | ||||
-rw-r--r-- | src/math/vector2f.cc | 24 | ||||
-rw-r--r-- | src/math/vector2f.h | 19 |
5 files changed, 115 insertions, 42 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc index e0e0d89..18b00af 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -66,66 +66,99 @@ void HUD::resize() } +/* + * This function is called to draw off-screen target indicators + * */ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) { math::Vector3f target(entity->location() - render::Camera::eye()); target = render::Camera::axis().transpose() * target; - float cx = 0; - float cy = 0; + math::Vector2f screen_edge; if (target.y() * target.y() + target.z() * target.z() < 0.0001) { // X - bound, behind (front is visible) - cx = 0.0f; - cy = -0.5f; - + screen_edge.assign(0.0f, -0.5f); } else if (fabs(target.y()) > fabs(target.z())) { // Y-bound - cx = math::sgnf(target.y()) * 0.5f; - cy = 0.5f * target.z() / fabs(target.y()); + screen_edge.assign(math::sgnf(target.y()) * 0.5f, 0.5f * target.z() / fabs(target.y())); } else { // Z-bound - cx = 0.5f * target.y() / fabs(target.z()); - cy = math::sgnf(target.z()) * 0.5f; + screen_edge.assign(0.5f * target.y() / fabs(target.z()), math::sgnf(target.z()) * 0.5f); + } + + screen_edge[0] = (0.5f - screen_edge[0]) * ((float) render::State::width()); + screen_edge[1] = (0.5f - screen_edge[1]) * ((float) render::State::height()); + + const float bitmap_margin = 24.0f; + float bitmap_radius = 32.0f; + + if (!is_active_target) { + bitmap_radius = 24.0f; + } + + math::Vector2f screen_center((float) render::State::width() * 0.5f, (float) render::State::height() * 0.5f); + math::Vector2f bitmap_up((screen_edge - screen_center)); + bitmap_up /= bitmap_up.length(); + math::Vector2f bitmap_left(-bitmap_up.y(), bitmap_up.x()); + math::Vector2f bitmap_center(screen_edge - (bitmap_up * (bitmap_margin + bitmap_radius))); + + // popup effect + if (is_active_target && (hud_splash_time > 0.0f)) { + bitmap_radius *= (core::application()->time() - hud_splash_time) / SPLASH_POPUP_DELAY; } - const float r = 16; - const float margin = 24; - cx = (0.5f - cx) * ((float) render::State::width() - margin * 2); - cx += margin; - cy = (0.5f - cy) * ((float) render::State::height() - margin * 2); - cy += margin; - - gl::disable(GL_TEXTURE_2D); - gl::color(0, 0, 0, 1); - gl::begin(gl::LineLoop); - glVertex3f(cx + r, cy + 2, 0); - glVertex3f(cx, cy + r + 2, 0); - glVertex3f(cx - r, cy + 2, 0); - glVertex3f(cx, cy - r + 2, 0); - gl::end(); + bitmap_up *= bitmap_radius; + bitmap_left *= bitmap_radius; - if (entity == core::localplayer()->mission_target()) { - gl::color(palette()->mission()); - } else if (entity->type() == core::Entity::Controlable) { - gl::color(0, 1, 0, 1); // FIXME allegiance color + //math::Vector2f bitmap_location(bitmap_center[0] - bitmap_radius, bitmap_center[1] - bitmap_radius); + //math::Vector2f bitmap_size(2.0f * bitmap_radius, 2.0f * bitmap_radius); + + math::Color bitmap_color; + std:: string bitmap_material("bitmaps/hud/offscreen_default"); + + if (entity->type() == core::Entity::Controlable) { + //bitmap_material.assign("bitmaps/hud/offscreen_controlable"); + bitmap_color.assign(palette()->fancy()); + + } else if (entity->has_flag(core::Entity::Dockable)) { + //bitmap_material.assign("bitmaps/hud/offscreen_dockable"); + bitmap_color.assign(palette()->foreground()); + } else { - gl::color(1, 1, 1, 1); // FIXME neutral color + //bitmap_material.assign("bitmaps/hud/offscreen_default"); + bitmap_color.assign(palette()->text()); } - - gl::begin(gl::LineLoop); - glVertex3f(cx + r, cy, 0); - glVertex3f(cx, cy + r, 0); - glVertex3f(cx - r, cy, 0); - glVertex3f(cx, cy - r, 0); - gl::end(); + + if (entity == core::localplayer()->mission_target()) { + bitmap_color.assign(palette()->mission()); + } + + render::Textures::bind(bitmap_material.c_str()); + gl::color(bitmap_color); gl::enable(GL_TEXTURE_2D); + gl::begin(gl::Quads); + + gl::texcoord(0.0f, 0.0f); + gl::vertex(bitmap_center + bitmap_up - bitmap_left); + + gl::texcoord(1.0f, 0.0f); + gl::vertex(bitmap_center + bitmap_up + bitmap_left); + + gl::texcoord(1.0f, 1.0f); + gl::vertex(bitmap_center - bitmap_up + bitmap_left); + + gl::texcoord(0.0f, 1.0f); + gl::vertex(bitmap_center - bitmap_up - bitmap_left); + + gl::end(); + gl::disable(GL_TEXTURE_2D); } /* - * This function is called to draw on-screen targets - * if is_active_target is set, the target is the currently selected target + * This function is called to draw on-screen target indicators + * If is_active_target is set, the target is the currently selected HUD target * */ void HUD::draw_target(core::Entity *entity, bool is_active_target) { diff --git a/src/math/matrix4f.cc b/src/math/matrix4f.cc index b7953e9..caccae6 100644 --- a/src/math/matrix4f.cc +++ b/src/math/matrix4f.cc @@ -4,8 +4,7 @@ the terms of the GNU General Public License version 2 */ -#include <string.h> - +#include <cstring> #include <cmath> #include "math/matrix4f.h" diff --git a/src/math/matrix4f.h b/src/math/matrix4f.h index 4148870..5442cb9 100644 --- a/src/math/matrix4f.h +++ b/src/math/matrix4f.h @@ -7,8 +7,6 @@ #ifndef __INCLUDED_MATH_MATRIX4F_H__ #define __INCLUDED_MATH_MATRIX4F_H__ -#include <iostream> - #include "math/axis.h" namespace math diff --git a/src/math/vector2f.cc b/src/math/vector2f.cc index 878304f..bff60c9 100644 --- a/src/math/vector2f.cc +++ b/src/math/vector2f.cc @@ -63,6 +63,25 @@ Vector2f &Vector2f::operator-=(const Vector2f &other) return (*this); } +Vector2f & Vector2f::operator*=(const float scalar) +{ + coord[0] *= scalar; + coord[1] *= scalar; + return (*this); +} + +Vector2f & Vector2f::operator/=(const float scalar) +{ + coord[0] /= scalar; + coord[1] /= scalar; + return (*this); +} + +float Vector2f::length() const +{ + return (sqrtf((coord[0] * coord[0]) + (coord[1] * coord[1]))); +} + float distance(const Vector2f& first, const Vector2f& second) { float r = 0; @@ -80,4 +99,9 @@ float distancesquared(const Vector2f& first, const Vector2f& second) return (r); } +Vector2f operator*(float scalar, const Vector2f &vector) +{ + return vector * scalar; +} + } diff --git a/src/math/vector2f.h b/src/math/vector2f.h index 1a5f4de..7641cbc 100644 --- a/src/math/vector2f.h +++ b/src/math/vector2f.h @@ -43,6 +43,18 @@ public: /// vector sum Vector2f & operator+=(const Vector2f &other); + + /** + * @brief scalar multiplication assignment + * @param scalar multiplication factor + * */ + Vector2f& operator*=(const float scalar); + + /** + * @brief scalar division assignment + * @param scalar divider + * */ + Vector2f& operator/=(const float scalar); /// vector subtraction inline Vector2f operator+(const Vector2f &other) const { @@ -97,6 +109,10 @@ public: inline float y() const { return coord[1]; } + + /// cartesian length + float length() const; + /// mutable reference to the x coordinate inline float & get_x() { @@ -131,6 +147,9 @@ float distance(const Vector2f& first, const Vector2f& second); /// distance between two vectors squared float distancesquared(const Vector2f& first, const Vector2f& second); +/// scalar * Vector2f operators +Vector2f operator*(float scalar, const Vector2f & vector); + } #endif // __INCLUDED_MATH_VECTOR2F_H__ |