Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/targets.cc')
-rw-r--r--src/client/targets.cc56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/client/targets.cc b/src/client/targets.cc
index e478d84..cd3db41 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -1,7 +1,7 @@
/*
client/targets.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <iostream>
@@ -28,9 +28,11 @@
#include "render/camera.h"
#include "render/state.h"
-namespace client {
+namespace client
+{
-namespace targets {
+namespace targets
+{
const float TARGETBOXRADIUS = 0.025f;
unsigned int current_target_id = 0;
@@ -157,7 +159,7 @@ void func_target_next(std::string const &args)
} else {
current_target = 0;
current_target_id = 0;
-
+
}
}
@@ -222,22 +224,22 @@ void func_target_center(std::string const &args)
{
if (!core::localcontrol())
return;
-
+
// this is essentialy the hover algorithm with the cursor in the center
core::Entity *new_target = 0;
math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001);
float smallest_d = -1;
- for (core::Zone::Content::iterator it=core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) {
+ for (core::Zone::Content::iterator it = core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) {
core::Entity *entity = (*it);
math::Vector3f v(entity->location() - render::Camera::eye());
v.normalize();
- if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) {
+ if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85) {
// calculate the distance from entity location to the line [eye - cursor]
- float d = math::Vector3f::length(math::crossproduct( (center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye());
+ float d = math::Vector3f::length(math::crossproduct((center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye());
// the entity closer to the center beam
if (smallest_d < 0 || d < smallest_d) {
@@ -256,7 +258,7 @@ void reset()
current_target = 0;
current_target_id = 0;
current_hover = 0;
-
+
}
void init()
@@ -296,7 +298,7 @@ void render_listener_sound()
if (!(snd_engines && snd_engines->value()))
return;
- math::Vector3f velocity(0, 0 ,0);
+ math::Vector3f velocity(0, 0 , 0);
if (core::localcontrol()) {
velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed());
}
@@ -308,13 +310,13 @@ void render_entity_sound(core::Entity *entity)
{
if (!(snd_engines && snd_engines->value())) {
if (ext_sound(entity))
- delete ext_sound(entity);
+ delete ext_sound(entity);
return;
}
if (!ext_render(entity) || (ext_render(entity) && !ext_render(entity)->visible())) {
if (ext_sound(entity))
- delete ext_sound(entity);
+ delete ext_sound(entity);
return;
} else {
if (!ext_sound(entity)) {
@@ -354,18 +356,18 @@ void frame()
x = 0;
y = 0;
} else {
- x = (float)(input::mouse_position_x() - render::State::width() /2) / (float)render::State::width();
- y = (float)(input::mouse_position_y() - render::State::height() /2) / (float)render::State::height() / render::State::aspect();
+ x = (float)(input::mouse_position_x() - render::State::width() / 2) / (float)render::State::width();
+ y = (float)(input::mouse_position_y() - render::State::height() / 2) / (float)render::State::height() / render::State::aspect();
}
Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001);
cursor -= render::Camera::axis().left() * x;
cursor -= render::Camera::axis().up() * y;
- math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT +0.001f));
- for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
+ math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001f));
+ for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
+
// render entity sound
if (entity->type() == core::Entity::Controlable) {
render_entity_sound(entity);
@@ -377,24 +379,24 @@ void frame()
if (entity->id() == current_target_id) {
current_target = entity;
}
-
+
// check if the mouse is hovering the entity
Vector3f v(entity->location() - render::Camera::eye());
v.normalize();
- if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
+ if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75) {
// calculate the distance from entity location to the line [eye - cursor]
- float d = math::Vector3f::length(math::crossproduct( (cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
-
+ float d = math::Vector3f::length(math::crossproduct((cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
+
float r = entity->radius() * 0.5f;
if (ext_render(entity)->distance() > 512.0f)
- math::clamp(r, 8.0f,r);
+ math::clamp(r, 8.0f, r);
else if (ext_render(entity)->distance() > 256.0f)
- math::clamp(r, 4.0f,r);
+ math::clamp(r, 4.0f, r);
else if (ext_render(entity)->distance() > 128.0f)
- math::clamp(r, 2.0f,r);
+ math::clamp(r, 2.0f, r);
// if the cursor-beam hits the entity sphere
if (d < r) {
@@ -406,7 +408,7 @@ void frame()
}
}
-
+
}
}
@@ -415,7 +417,7 @@ void frame()
} else {
current_target_id = current_target->id();
-
+
}
}