Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-08-06 16:43:32 +0000
committerStijn Buys <ingar@osirion.org>2008-08-06 16:43:32 +0000
commit6979c74625d51897d99797b309974c2ee82a024b (patch)
tree812f652254672ef016deb96239d6a5c5b98a8801 /src
parent668026125ae19b9bd800004ae9ec0510f20753ad (diff)
every player within 1024 game units is drawn as target
Diffstat (limited to 'src')
-rw-r--r--src/client/targets.cc208
-rw-r--r--src/client/targets.h7
-rw-r--r--src/client/view.cc7
-rw-r--r--src/core/Makefile.am6
-rw-r--r--src/core/core.h1
-rw-r--r--src/core/netconnection.cc10
-rw-r--r--src/core/range.h28
-rw-r--r--src/game/ship.cc4
8 files changed, 160 insertions, 111 deletions
diff --git a/src/client/targets.cc b/src/client/targets.cc
index e140df2..b16ae13 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -19,6 +19,7 @@
#include "core/entity.h"
#include "core/func.h"
#include "core/gameinterface.h"
+#include "core/range.h"
#include "math/axis.h"
#include "math/vector3f.h"
#include "render/gl.h"
@@ -39,10 +40,20 @@ core::Cvar *snd_engines = 0;
bool is_legal_target(core::Entity *entity)
{
- if (entity->id() == core::localcontrol()->id())
+ if (entity->id() == core::localcontrol()->id()) {
return false;
- else
- return true;
+ } else if (entity->state()->distance() < 0.001f) {
+ return false;
+ } else {
+ if (entity->type() != core::Entity::Controlable) {
+ return entity->state()->visible();
+
+ } else if (entity->state()->distance() < core::range::max) {
+ return true;
+ }
+ }
+
+ return false;
}
core::Entity* current()
@@ -271,8 +282,83 @@ void render_entity_sound(core::Entity *entity)
}
}
-// render client targets
-void frame()
+//core::Entity *entity = current_target;
+void draw_entity_target(core::Entity *entity, bool is_active_target)
+{
+ using math::Vector3f;
+
+ // don't draw target if we're very close to it
+ if (entity->state()->distance() < 0.001f)
+ return;
+
+ // don't draw target if it is outside the visible cone
+ Vector3f target(entity->state()->location() - render::Camera::eye());
+ if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75 )
+ return;
+
+ // transform the target into the normalized coordinate system
+ target = render::Camera::axis().transpose() * target;
+
+ // calculate the intersection between the line (0,0,0)-target and the frustum front
+ float t = (render::Camera::frustum_front() + 0.001f) / target.x;
+ Vector3f center(target *t);
+
+ float cx = video::width * (0.5 - center.y);
+ float cy = video::height * (0.5 - center.z * render::Camera::aspect());
+
+ const float pointer_size = 48.0f;
+ float r = pointer_size;
+ if (!is_active_target)
+ r *= 0.5;
+
+ render::gl::disable(GL_TEXTURE_2D);
+
+ render::gl::color(0, 0, 0, 1);
+ render::gl::begin(render::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);
+ render::gl::end();
+
+ render::gl::color(1, 1, 1, 1);
+ render::gl::begin(render::gl::LineLoop);
+ glVertex3f(cx+r, cy, 0);
+ glVertex3f(cx, cy+r, 0);
+ glVertex3f(cx-r, cy, 0);
+ glVertex3f(cx, cy-r, 0);
+ render::gl::end();
+
+ render::gl::enable(GL_TEXTURE_2D);
+
+ if (is_active_target) {
+ // entity name and distance
+ std::stringstream strdistance;
+ float d = math::distance(core::localcontrol()->location(), entity->state()->location()) - entity->radius() - core::localcontrol()->radius();
+ if (d > 0 ) {
+ if (d > 100) {
+ strdistance << roundf(d * 0.1f) << "km";
+ } else {
+ strdistance << roundf(d * 100.0f) << "m";
+ }
+ } else {
+ strdistance << "--";
+ }
+ if (entity->type() == core::Entity::Controlable) {
+ render::Text::setcolor('B');
+ } else {
+ render::Text::setcolor('N');
+ }
+ render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
+ cy-r-4- render::Text::fontheight(), entity->name());
+
+ render::Text::draw(cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f,
+ cy - render::Text::fontheight() * 0.5f, strdistance);
+ }
+}
+
+// render targets and sounds
+void draw()
{
core::Zone *zone = core::localplayer()->zone();
if (!zone)
@@ -299,7 +385,7 @@ void frame()
cursor -= render::Camera::axis().left() * x;
cursor -= render::Camera::axis().up() * y;
- math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::Camera::frustum_front() +0.01f));
+ math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::Camera::frustum_front() +0.001f));
for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
@@ -307,22 +393,35 @@ void frame()
render_entity_sound(entity);
// find the current target
- if (entity->id() == current_target_id) {
- current_target = entity;
- }
+ if (core::localcontrol() && is_legal_target(entity)) {
+
+ if (entity->id() == current_target_id) {
+ current_target = entity;
+ draw_entity_target(current_target, true);
+ } else if (entity->type() == core::Entity::Controlable) {
+ draw_entity_target(entity, false);
+ }
- // check if the mouse is hovering the entity
- if (core::localcontrol() && entity->state()->visible()) {
+ // check if the mouse is hovering the entity
Vector3f v(entity->state()->location() - render::Camera::eye());
v.normalize();
- if (is_legal_target(entity) && (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 )) {
+ if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
// caculate 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 r = entity->radius() * 0.5f;
+
+ if (entity->state()->distance() > 512)
+ math::clamp(r, 8.0f,r);
+ else if (entity->state()->distance() > 256)
+ math::clamp(r, 4.0f,r);
+ else if (entity->state()->distance() > 128.0f)
+ math::clamp(r, 2.0f,r);
+
// if the cursor-beam hits the entity sphere
- if (d < entity->radius() * 0.5f) {
+ if (d < r) {
float myz = math::distance(cursor, entity->location());
if (z < 0 || myz < z) {
current_hover = entity->id();
@@ -337,89 +436,8 @@ void frame()
current_target_id = 0;
} else {
current_target_id = current_target->id();
- }
-}
-
-void draw_target()
-{
- using math::Vector3f;
-
- if (!current_target)
- return;
-
- 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::Camera::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;
- //intersection -= render::Camera::eye()
- Vector3f intersection = (entity->state()->location() - render::Camera::eye()) * t;
-
- Vector3f center(render::Camera::axis().transpose()*intersection);
-
- float cx = video::width * (0.5 - center.y);
- float cy = video::height * (0.5 - center.z * render::Camera::aspect());
-
- const float pointer_size = 48.0f;
- const float r = pointer_size;
-
- render::gl::disable(GL_TEXTURE_2D);
-
- render::gl::color(0, 0, 0, 1);
- render::gl::begin(render::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);
- render::gl::end();
-
- render::gl::color(1, 1, 1, 1);
- render::gl::begin(render::gl::LineLoop);
- glVertex3f(cx+r, cy, 0);
- glVertex3f(cx, cy+r, 0);
- glVertex3f(cx-r, cy, 0);
- glVertex3f(cx, cy-r, 0);
- render::gl::end();
-
- render::gl::enable(GL_TEXTURE_2D);
-
- std::stringstream str;
-
- // entity name
- render::Text::setcolor('B');
- render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f, cy-r-4- render::Text::fontheight(), entity->name());
-
-
- d = math::distance(core::localcontrol()->location(), entity->state()->location()) - entity->radius() - core::localcontrol()->radius();
- if (d > 0 ) {
- if (d > 100) {
- str << roundf(d * 0.1f) << "km";
- } else {
- str << roundf(d * 100.0f) << "m";
- }
- } else {
- str << "--";
- }
- render::Text::setcolor('B');
- render::Text::draw(cx - aux::text_length(str.str()) * render::Text::fontwidth() * 0.5f, cy - render::Text::fontheight() * 0.5f, str);
+
}
}
diff --git a/src/client/targets.h b/src/client/targets.h
index 0df9df7..f805305 100644
--- a/src/client/targets.h
+++ b/src/client/targets.h
@@ -22,11 +22,8 @@ void shutdown();
void reset();
-/// render client side entity properties
-void frame();
-
-/// draw target box
-void draw_target();
+/// render targets and sounds
+void draw();
/// render sound listener properties
void render_listener_sound();
diff --git a/src/client/view.cc b/src/client/view.cc
index 4fe7a33..a551bf6 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -391,7 +391,6 @@ void frame(float seconds)
if (core::application()->connected() && core::game()->serverframetime()) {
render::draw(seconds); // draw the world
- targets::frame();
}
// switch to orthographic projection to draw the GUI
@@ -421,8 +420,10 @@ void frame(float seconds)
if (draw_ui->value()) {
Text::setfont("bitmaps/fonts/gui", 12, 18);
- // draw the current target selection
- targets::draw_target();
+ // draw the current targets
+ if (core::application()->connected() && core::game()->serverframetime()) {
+ targets::draw();
+ }
// draw the player status
draw_status();
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 6c2c41e..3badbd9 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -10,7 +10,7 @@ libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \
$(top_builddir)/src/auxiliary/libauxiliary.la
noinst_LTLIBRARIES = libcore.la
-noinst_HEADERS = application.h commandbuffer.h clientstate.h core.h cvar.h entity.h func.h \
- gameconnection.h gameinterface.h gameserver.h module.h net.h \
- netclient.h netconnection.h netserver.h player.h stats.h
+noinst_HEADERS = application.h clientstate.h commandbuffer.h core.h cvar.h \
+ entity.h func.h gameconnection.h gameinterface.h gameserver.h module.h net.h \
+ netclient.h netconnection.h netserver.h player.h range.h stats.h
diff --git a/src/core/core.h b/src/core/core.h
index a3c9005..feca5fd 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -17,6 +17,7 @@
#include "core/gameinterface.h"
#include "core/module.h"
#include "core/player.h"
+#include "core/range.h"
#include "core/zone.h"
/// core contains the basic functionality of the engine
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 3b302dd..0b33652 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -451,7 +451,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
} else if (command == "die") {
unsigned int id;
if (msgstream >> id) {
- con_debug << "Received die entity id " << id << std::endl;
+ //con_debug << "Received die entity id " << id << std::endl;
Entity *e = Entity::find(id);
if (localcontrol() == e)
localplayer()->set_control(0);
@@ -470,7 +470,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
con_warn << "Received create for NULL entity!" << std::endl;
return;
}
- con_debug << "Received create entity id " << id << " type " << type << std::endl;
+ //con_debug << "Received create entity id " << id << " type " << type << std::endl;
Entity *entity = Entity::find(id);
@@ -508,7 +508,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
std::string label;
if (msgstream >> id) {
if (id) {
- con_debug << "Received zone " << id << std::endl;
+ //con_debug << "Received zone " << id << std::endl;
Zone * zone = Zone::find(id);
// create the zone if necessary
@@ -525,12 +525,12 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
} else if (command == "pif") {
- con_debug << "Received update player info" << std::endl;
+ //con_debug << "Received update player info" << std::endl;
Zone *oldzone = connection()->localplayer()->zone();
connection()->localplayer()->receive_server_update(msgstream);
- con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl;
+ //con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl;
if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) {
diff --git a/src/core/range.h b/src/core/range.h
new file mode 100644
index 0000000..5921e70
--- /dev/null
+++ b/src/core/range.h
@@ -0,0 +1,28 @@
+/*
+ core/core.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CORE_RANGE_H__
+#define __INCLUDED_CORE_RANGE_H__
+
+namespace core {
+
+namespace range {
+ /// maximal range
+ /** This is the distance of the frustum far plane,
+ * the maximal distance at which non-controlable entities can be drawn.
+ * the maximal radar range for controlable entities,
+ * and the maximal range to send entity updates
+ */
+ const float max = 1024.0f;
+
+ /// maximal visible range for controlable entities
+ const float visible = 512.0f;
+}
+
+}
+
+#endif // __INCLUDED_CORE_RANGE_H__
+
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 89ff343..8492b68 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -132,6 +132,10 @@ void Ship::frame(float seconds)
float actual_turnspeed = ship_shipmodel->turnspeed();
float actual_acceleration = ship_shipmodel->acceleration();
+ // speed might get set to 0 on this update
+ if (entity_speed != 0.0f)
+ entity_dirty = true;
+
// jumpdrive
// target axis
math::Axis target_axis(entity_axis);