From 2c98d3eef488233b99a76ca44d69c1c9d53404af Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Dec 2014 16:12:49 +0000 Subject: Cleanup of the slots code, unified model weapon and dock tags into a single slots list, load dock tags into entity slots, represent entity slot locations in entity coordinate space, have r_slots render fixed-size slot indicators regardless of model scale. --- src/render/draw.cc | 106 ++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 54 deletions(-) (limited to 'src/render') diff --git a/src/render/draw.cc b/src/render/draw.cc index 2428735..47fcb40 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -824,10 +824,6 @@ void draw_pass_model_fragments() ext_render(entity)->power(), ext_render(entity)->thrust() ); - - if (r_slots && r_slots->value()) { - draw_slots(entity); - } if (r_bbox->value()) { gl::disable(GL_DEPTH_TEST); @@ -847,8 +843,18 @@ void draw_pass_model_fragments() draw_inidicators(static_cast(entity)); } + if (entity->slots() && r_slots && r_slots->value()) { + gl::pop(); + + gl::push(); + gl::translate(entity->location()); + gl::multmatrix(entity->axis()); + + // not scaled through modelscale + draw_slots(entity); + } gl::pop(); - } + } } } @@ -1393,80 +1399,72 @@ void draw_inidicators(const core::EntityControlable *entity) void draw_slots(const core::Entity *entity) { - if (!entity->model()) { - return; - } - - if (entity->model()->docks().size()) { + if (entity->slots()) + { + const float r = 0.025f; - // draw docks: pass 1 - background with GL_DEPTH_TEST disabled + // draw slots: pass 1 - background with GL_DEPTH_TEST disabled gl::disable(GL_DEPTH_TEST); - gl::color(0.0f, 0.5f, 0.5f, 0.25f); - - for (model::Model::Docks::iterator dit = entity->model()->docks().begin(); dit != entity->model()->docks().end(); ++dit) { - model::Dock *dock = (*dit); - math::Vector3f maxbox(dock->location()); - math::Vector3f minbox(dock->location()); - - for (size_t i = 0; i < 3; i++) { - maxbox[i] += 0.025; - minbox[i] -= 0.025; - } - - draw_box(minbox, maxbox); - } - - // draw docks: pass 2 - highlight with GL_DEPTH_TEST enabled - gl::enable(GL_DEPTH_TEST); - gl::color(0.0f, 1.0f, 1.0f, 1.0f); - - for (model::Model::Docks::iterator dit = entity->model()->docks().begin(); dit != entity->model()->docks().end(); ++dit) { - model::Dock *dock = (*dit); - math::Vector3f maxbox(dock->location()); - math::Vector3f minbox(dock->location()); - - for (size_t i = 0; i < 3; i++) { - maxbox[i] += 0.025; - minbox[i] -= 0.025; - } - - draw_box(minbox, maxbox); - } - } - - if (entity->slots()) { - - // draw weapon slots: pass 1 - background with GL_DEPTH_TEST disabled - gl::disable(GL_DEPTH_TEST); - gl::color(0.5f, 0.0f, 0.0f, 0.25f); for(core::Slots::iterator it = entity->slots()->begin(); it != entity->slots()->end(); ++it) { core::Slot *slot = (*it); + switch (slot->type()) { + case model::Slot::Cannon: + case model::Slot::Turret: + // red for weapons + gl::color(0.5f, 0.0f, 0.0f, 0.25f); + break; + case model::Slot::Dock: + // cyan for docks + gl::color(0.0f, 0.5f, 0.5f, 0.25f); + break; + case model::Slot::None: + // gray for unkown + gl::color(0.25f, 0.25f, 0.25f, 0.25f); + break; + } + math::Vector3f maxbox(slot->location()); math::Vector3f minbox(slot->location()); for (size_t i = 0; i < 3; i++) { - maxbox[i] += 0.025; - minbox[i] -= 0.025; + maxbox[i] += r; + minbox[i] -= r; } draw_box(minbox, maxbox); } - // draw weapon slots: pass 2 - highlight with GL_DEPTH_TEST enabled + // draw slots: pass 2 - highlight with GL_DEPTH_TEST enabled gl::enable(GL_DEPTH_TEST); gl::color(1.0f, 0.0f, 0.0f); for(core::Slots::iterator it = entity->slots()->begin(); it != entity->slots()->end(); ++it) { core::Slot *slot = (*it); + switch (slot->type()) { + case model::Slot::Cannon: + case model::Slot::Turret: + // red for weapons + gl::color(1.0f, 0.0f, 0.0f, 1.0f); + break; + case model::Slot::Dock: + // cyan for docks + gl::color(0.0f, 1.0f, 1.0f, 1.0f); + break; + case model::Slot::None: + // gray for unkown + gl::color(0.5f, 0.5f, 0.5f, 1.0f); + break; + } + math::Vector3f maxbox(slot->location()); math::Vector3f minbox(slot->location()); for (size_t i = 0; i < 3; i++) { - maxbox[i] += 0.025; - minbox[i] -= 0.025; + maxbox[i] += r; + minbox[i] -= r; } draw_box(minbox, maxbox); -- cgit v1.2.3