Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-20 19:55:27 +0000
committerStijn Buys <ingar@osirion.org>2008-07-20 19:55:27 +0000
commit166a7c820704c978178b3cb9300eda81dbc23455 (patch)
tree3408748d195874fd855582b84345bebe0df88b1a /src/client/targets.cc
parent8ad20ed0462227463a5e3b94683d8c1c5a650494 (diff)
core::localcontrol() is not a legal target
Diffstat (limited to 'src/client/targets.cc')
-rw-r--r--src/client/targets.cc112
1 files changed, 68 insertions, 44 deletions
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 00a2e86..418ca47 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -54,24 +54,34 @@ void func_target_next(std::string const &args)
std::map<unsigned int, core::Entity *>::iterator it = core::Entity::registry.begin();
if (!current_target_id) {
- // last entity
+
+ // first entity
it = core::Entity::registry.begin();
+ while (!is_legal_target((*it).second) && it != core::Entity::registry.end())
+ it++;
+
} else {
// current entity
it = core::Entity::registry.find(current_target_id);
-
- // next entity
+
+ // next legal entity
if (it != core::Entity::registry.end())
it++;
if (it == core::Entity::registry.end()) {
it = core::Entity::registry.begin();
}
+ while (!is_legal_target((*it).second)) {
+ it++;
+ if (it == core::Entity::registry.end())
+ it = core::Entity::registry.begin();
+
+ if ((*it).first == current_target_id) {
+ current_target = (*it).second;
+ return;
+ }
+ }
}
-/*
- // next while not a legal target
- while (it != core::Entity::registry.end() && !is_legal_target((*it).second))
- it++;
-*/
+
if (it != core::Entity::registry.end()) {
current_target = (*it).second;
current_target_id = current_target->id();
@@ -98,21 +108,31 @@ void func_target_prev(std::string const &args)
if (!current_target_id) {
// last entity
rit = core::Entity::registry.rbegin();
+ while (!is_legal_target((*rit).second) && rit != core::Entity::registry.rend())
+ rit++;
} else {
// current entity
while (rit != core::Entity::registry.rend() && ((*rit).first != current_target_id))
++rit;
- // previous entity
+
+ // previous legal entity
if (rit != core::Entity::registry.rend())
++rit;
- if (rit == core::Entity::registry.rend())
+ if (rit == core::Entity::registry.rend()) {
rit = core::Entity::registry.rbegin();
+ }
+ while (!is_legal_target((*rit).second)) {
+ ++rit;
+ if (rit == core::Entity::registry.rend())
+ rit = core::Entity::registry.rbegin();
+
+ if ((*rit).first == current_target_id) {
+ current_target = (*rit).second;
+ return;
+ }
+ }
}
-/*
- // previous while not a legal target
- while (rit != core::Entity::registry.rend() && is_legal_target((*rit).second))
- ++rit;
-*/
+
if (rit != core::Entity::registry.rend()) {
current_target = (*rit).second;
current_target_id = current_target->id();
@@ -235,40 +255,44 @@ void draw()
if (entity->id() == current_target_id) {
current_target = entity;
- // if target is in visible space
- Vector3f v(entity->state()->location() - render::Camera::eye());
- v.normalize();
- if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
-
- // find the intersection of the line [ eye - target ] in the frustum front plane
- Vector3f const &plane_normal = render::Camera::axis().forward();
- Vector3f const &plane_point = render::Camera::eye() + render::Camera::axis().forward() * (render::frustum_front + 0.001);
-
- float d = (plane_normal.x * plane_point.x + plane_normal.y * plane_point.y + plane_normal.z * plane_point.z);
- float t = d - plane_normal.x * render::Camera::eye().x
- - plane_normal.y * render::Camera::eye().y
- - plane_normal.z * render::Camera::eye().z;
- t /= plane_normal.x * (entity->state()->location().x - render::Camera::eye().x)
- + plane_normal.y * (entity->state()->location().y - render::Camera::eye().y)
- + plane_normal.z * (entity->state()->location().z - render::Camera::eye().z);
-
- Vector3f intersection = render::Camera::eye() + (entity->state()->location() - render::Camera::eye()) * t;
-
- // draw the target cursor in the frustum front plane, but in real world coordinates
- const float r = 0.05;
- render::gl::color(1, 1, 1, 1);
- render::gl::begin(render::gl::LineLoop);
- render::gl::vertex(intersection + render::Camera::axis().up() * r);
- render::gl::vertex(intersection + render::Camera::axis().left() * r);
- render::gl::vertex(intersection - render::Camera::axis().up() * r);
- render::gl::vertex(intersection - render::Camera::axis().left() * r);
- render::gl::end();
- }
}
}
if (!current_target) {
current_target_id = 0;
+
+ } else {
+ core::Entity *entity = current_target;
+
+ // if target is in visible space
+ Vector3f v(entity->state()->location() - render::Camera::eye());
+ v.normalize();
+ if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
+
+ // find the intersection of the line [ eye - target ] in the frustum front plane
+ Vector3f const &plane_normal = render::Camera::axis().forward();
+ Vector3f const &plane_point = render::Camera::eye() + render::Camera::axis().forward() * (render::frustum_front + 0.001);
+
+ float d = (plane_normal.x * plane_point.x + plane_normal.y * plane_point.y + plane_normal.z * plane_point.z);
+ float t = d - plane_normal.x * render::Camera::eye().x
+ - plane_normal.y * render::Camera::eye().y
+ - plane_normal.z * render::Camera::eye().z;
+ t /= plane_normal.x * (entity->state()->location().x - render::Camera::eye().x)
+ + plane_normal.y * (entity->state()->location().y - render::Camera::eye().y)
+ + plane_normal.z * (entity->state()->location().z - render::Camera::eye().z);
+
+ Vector3f intersection = render::Camera::eye() + (entity->state()->location() - render::Camera::eye()) * t;
+
+ // draw the target cursor in the frustum front plane, but in real world coordinates
+ const float r = 0.05;
+ render::gl::color(1, 1, 1, 1);
+ render::gl::begin(render::gl::LineLoop);
+ render::gl::vertex(intersection + render::Camera::axis().up() * r);
+ render::gl::vertex(intersection + render::Camera::axis().left() * r);
+ render::gl::vertex(intersection - render::Camera::axis().up() * r);
+ render::gl::vertex(intersection - render::Camera::axis().left() * r);
+ render::gl::end();
+ }
}
}