diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/hud.cc | 22 | ||||
-rw-r--r-- | src/client/hudenginestatus.cc | 3 | ||||
-rw-r--r-- | src/client/input.cc | 185 | ||||
-rw-r--r-- | src/client/savegamemenu.cc | 4 | ||||
-rw-r--r-- | src/client/soundext.cc | 4 | ||||
-rw-r--r-- | src/client/targets.cc | 30 | ||||
-rw-r--r-- | src/client/video.cc | 2 |
7 files changed, 151 insertions, 99 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc index 1ae008c..49f9c9d 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -73,8 +73,8 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) const core::EntityControlable *controlable = ( (entity->type() == core::Entity::Controlable) ? static_cast<core::EntityControlable *>(entity) : 0 ); - math::Vector3f target(entity->location() - render::Camera::eye()); - target = render::Camera::axis().transpose() * target; + math::Vector3f target(entity->location() - render::camera().location()); + target = render::camera().axis().transpose() * target; math::Vector2f screen_edge; @@ -205,8 +205,8 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) } // don't draw target if it is outside the visible cone - Vector3f target(entity->location() - render::Camera::eye()); - if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75) { + Vector3f target(entity->location() - render::camera().location()); + if (math::dotproduct(render::camera().axis().forward(), Vector3f::normalized(target)) < 0.75) { draw_offscreen_target(entity, is_active_target); return; } @@ -216,7 +216,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) // calculate target screen position // transform the target into the camera coordinate system - target = render::Camera::axis().transpose() * target; + target = render::camera().axis().transpose() * target; // calculate the intersection between the line (0,0,0)-target and the frustum front float t = (render::FRUSTUMFRONT + 0.001f) / target.x(); @@ -416,10 +416,12 @@ void HUD::draw() { using namespace render; - if (core::localcontrol() && (input::mouse_control || input::joystick_control) && - (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + if (core::localcontrol() && (input::mouse_control || input::joystick_control) && (render::camera().mode() != render::camera().Overview)) + { hud_center->set_visible(true); - } else { + } + else + { hud_center->set_visible(false); } @@ -468,7 +470,7 @@ void HUD::draw() if (has_mouse_focus()) { - if (render::Camera::mode() == render::Camera::Overview) { + if (render::camera().mode() == render::camera().Overview) { ui::root()->set_pointer("pointer", ui::Palette::Highlight); @@ -484,7 +486,7 @@ void HUD::draw() ui::root()->set_pointer("control", ui::Palette::Pointer); - } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::camera().mode() == render::camera().Cockpit || render::camera().mode() == render::camera().Track)) { ui::root()->set_pointer(); diff --git a/src/client/hudenginestatus.cc b/src/client/hudenginestatus.cc index 1283970..0eeafba 100644 --- a/src/client/hudenginestatus.cc +++ b/src/client/hudenginestatus.cc @@ -11,8 +11,9 @@ #include "ui/ui.h" #include "ui/iconbutton.h" #include "ui/paint.h" -#include "render/render.h" +#include "render/camera.h" #include "render/gl.h" +#include "render/render.h" namespace client { diff --git a/src/client/input.cc b/src/client/input.cc index 72fa5af..dadc027 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -139,9 +139,6 @@ void func_ui_control(std::string const &args) local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; - - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); } con_print << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl; @@ -152,7 +149,7 @@ void func_ui_control(std::string const &args) void func_view_next(std::string const &args) { if (!core::localplayer()->view() && core::application()->connected() && core::localcontrol()) { - render::Camera::view_next(); + render::camera().cycle_mode_next(); local_roll = 0; local_pitch = 0; local_direction = 0; @@ -163,7 +160,7 @@ void func_view_next(std::string const &args) void func_view_prev(std::string const &args) { if (!core::localplayer()->view() && core::application()->connected() && core::localcontrol()) { - render::Camera::view_previous(); + render::camera().cycle_mode_previous(); local_roll = 0; local_pitch = 0; local_direction = 0; @@ -348,7 +345,8 @@ void shutdown() void action_press(Key *key) { - switch(key->action()->id()) { + switch(key->action()->id()) + { case Action::None: case Action::Console: return; @@ -411,60 +409,95 @@ void action_press(Key *key) /* -- camera control ------------------------------ */ + case Action::FreeLook: + if (!freelook_control_override) + { + freelook_control_override = true; + freelook_control_override_time = key->pressed(); + + freelook_control_x = mouse_x; + freelook_control_y = mouse_y; + } + break; case Action::LookLeft: - if (render::Camera::mode() == render::Camera::Free) + if (render::camera().mode() == render::Camera::Free) { - render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f)); - } else { - render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f)); + render::camera().set_movement_direction(-1.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_direction(90.0f); } break; case Action::LookRight: - if (render::Camera::mode() == render::Camera::Free) + if (render::camera().mode() == render::Camera::Free) { - render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f)); - } else { - render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f)); + render::camera().set_movement_direction(1.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_direction(-90.0f); } break; case Action::LookUp: - if (render::Camera::mode() == render::Camera::Free) + if (render::camera().mode() == render::Camera::Free) { - render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f)); - } else { - render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f)); + render::camera().set_movement_pitch(1.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_pitch(90.0f); } break; case Action::LookDown: - if (render::Camera::mode() == render::Camera::Free) + if (render::camera().mode() == render::Camera::Free) { - render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f)); - } else { - render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f)); + render::camera().set_movement_pitch(-1.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_pitch(-90.0f); } break; case Action::ZoomIn: - render::Camera::set_zoom(-0.1f); + if (!core::localplayer()->view()) + { + float m = render::camera().multiplier(); + if (m > 1.0f) + { + m -= 0.1f; + } + else + { + m = 1.0f; + } + render::camera().set_multiplier(m); + } break; case Action::ZoomOut: - render::Camera::set_zoom(+0.1f); - break; - case Action::FreeLook: - if (!freelook_control_override) + if (!core::localplayer()->view()) { - freelook_control_override = true; - freelook_control_override_time = key->pressed(); - - freelook_control_x = mouse_x; - freelook_control_y = mouse_y; + float m = render::camera().multiplier(); + if (m < 5.0f) + { + m += 0.1f; + } + else + { + m = 5.0f; + } + render::camera().set_multiplier(m); } break; - + /* -- fire control -------------------------------- */ case Action::Fire: local_controlflags = local_controlflags | core::EntityControlable::ControlFlagFire; break; + + default: + break; } } @@ -531,15 +564,15 @@ void action_release(Key *key) mouse_control_override_time = 0.0f; if (!input_mousecontrol->value() || (joystick_control && mouse_control && - (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) { + (render::camera().mode() == render::Camera::Track || render::camera().mode() == render::Camera::Cockpit))) { local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; local_vstrafe = 0.0f; local_strafe = 0.0f; - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); + render::camera().set_movement_direction(0.0f); + render::camera().set_movement_pitch(0.0f); } } break; @@ -547,16 +580,26 @@ void action_release(Key *key) /* -- camera control ------------------------------ */ case Action::LookLeft: - render::Camera::set_direction(0.0f); - break; case Action::LookRight: - render::Camera::set_direction(0.0f); + if (render::camera().mode() == render::Camera::Free) + { + render::camera().set_movement_direction(0.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_direction(0.0f); + } break; case Action::LookUp: - render::Camera::set_pitch(0.0f); - break; case Action::LookDown: - render::Camera::set_pitch(0.0f); + if (render::camera().mode() == render::Camera::Free) + { + render::camera().set_movement_pitch(0.0f); + } + else if ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit)) + { + render::camera().set_freelook_pitch(0.0f); + } break; case Action::ZoomIn: break; @@ -568,8 +611,8 @@ void action_release(Key *key) freelook_control_override = false; freelook_control_override_time = 0.0f; - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); + render::camera().set_freelook_direction(0.0f); + render::camera().set_freelook_pitch(0.0f); } break; @@ -601,8 +644,8 @@ bool console_key_pressed(const Key *key) local_pitch = 0.0f; local_roll = 0.0f; - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); + //render::Camera::set_direction(0.0f); + //render::Camera::set_pitch(0.0f); ui::console()->toggle(); return true; @@ -737,7 +780,7 @@ void reset() mouse_direction = 0.0f; mouse_x = render::State::width() / 2; mouse_y = render::State::height() / 2; - render::Camera::reset(); + render::camera().reset(); render::Dust::reset(); mouse_control_override = false; mouse_control_override_time = 0.0f; @@ -951,18 +994,23 @@ void frame() // if freelook_control is true, the mouse controls freelook freelook_control = ui::console()->hidden() && freelook_control_override && (freelook_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()); - // if mouse control is true, the mouse controls the spacecraft - mouse_control = ui::console()->hidden() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()) )); + if (!freelook_control) + { + // if mouse control is true, the mouse controls the spacecraft + mouse_control = ui::console()->hidden() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()) )); - // joystick control takes presedence over mouse control, but not over mouse_control_override - if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) { - if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) { - mouse_control = false; + // joystick control takes presedence over mouse control, but not over mouse_control_override + if (mouse_control && joystick_control && ((render::camera().mode() == render::Camera::Track) || (render::camera().mode() == render::Camera::Cockpit))) + { + if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) + { + mouse_control = false; + } } } if (mouse_control || freelook_control ) { - const float aim_square_size = 256.0f; + const float aim_square_size = math::min(render::State::width(), render::State::height()) * 0.5f; int l = mouse_x; int h = mouse_y; @@ -991,7 +1039,7 @@ void frame() if (freelook_control) { // mouse is controling freelook - switch (render::Camera::mode()) + switch (render::camera().mode()) { case render::Camera::Track: case render::Camera::Cockpit: @@ -1007,14 +1055,18 @@ void frame() // disable autopilot override local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride; } - render::Camera::set_direction(mouse_direction); - render::Camera::set_pitch(mouse_pitch); + + render::camera().set_freelook_direction(180.0f * mouse_direction); + render::camera().set_freelook_pitch(90.0f * mouse_pitch); break; case render::Camera::Free: - render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction)); - render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch)); + render::camera().set_movement_direction(0.0f); + render::camera().set_movement_pitch(0.0f); + + render::camera().set_freelook_direction(180.0f * mouse_direction); + render::camera().set_freelook_pitch(90.0f * mouse_pitch); // disable autopilot override local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride; @@ -1027,7 +1079,7 @@ void frame() } else if (mouse_control) { // mouse is controling direction - switch (render::Camera::mode()) + switch (render::camera().mode()) { case render::Camera::Track: case render::Camera::Cockpit: @@ -1039,8 +1091,8 @@ void frame() break; case render::Camera::Free: - render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction)); - render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch)); + render::camera().set_movement_direction(mouse_direction); + render::camera().set_movement_pitch(mouse_pitch); // disable autopilot override local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride; @@ -1053,11 +1105,10 @@ void frame() } } else { - //render::Camera::set_direction(0.0f); - //render::Camera::set_pitch(0.0f); - // disable autopilot override local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride; + render::camera().set_movement_direction(0.0f); + render::camera().set_movement_pitch(0.0f); } math::clamp(local_direction, -1.0f, 1.0f); @@ -1089,8 +1140,8 @@ void frame() local_afterburner = 0.0f; local_controlflags = core::EntityControlable::ControlFlagNone; - render::Camera::set_direction(0.0f); - render::Camera::set_pitch(0.0f); + //render::Camera::set_direction(0.0f); + //render::Camera::set_pitch(0.0f); } } diff --git a/src/client/savegamemenu.cc b/src/client/savegamemenu.cc index d002b54..2ba038f 100644 --- a/src/client/savegamemenu.cc +++ b/src/client/savegamemenu.cc @@ -567,9 +567,9 @@ void SaveGameMenu::savescreenshot(std::string savename) gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set camera transformation - render::Camera::frame(0.0f); + render::camera().frame(0.0f); - render::Camera::frustum(); + render::camera().draw(); // draw the world render::draw(0.0f); diff --git a/src/client/soundext.cc b/src/client/soundext.cc index dd86a70..9de548b 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -14,7 +14,7 @@ #include "core/entityprojectile.h" #include "client/soundext.h" #include "client/client.h" -#include "render/camera.h" +#include "render/draw.h" #include <sstream> #include <iomanip> @@ -45,7 +45,7 @@ void render_listener_sound() (*snd_volume) = master_volume; } - audio::update_listener(render::Camera::eye(), render::Camera::axis(), velocity, master_volume); + audio::update_listener(render::camera().location(), render::camera().axis(), velocity, master_volume); } void render_entity_sound(core::Entity *entity) diff --git a/src/client/targets.cc b/src/client/targets.cc index b320b08..ae2afb0 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -25,7 +25,7 @@ #include "core/range.h" #include "math/axis.h" #include "math/vector3f.h" -#include "render/camera.h" +#include "render/draw.h" #include "render/state.h" namespace client @@ -395,19 +395,19 @@ void func_target_center(std::string const &args) // this is essentialy the hover algorithm with the cursor in the center const core::Entity *new_target = 0; - math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001); + math::Vector3f center = render::camera().location() + render::camera().axis().forward() * (render::FRUSTUMFRONT + 0.001); float smallest_d = -1; for (core::Zone::Content::const_iterator it = core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) { const core::Entity *entity = (*it); - math::Vector3f v(entity->location() - render::Camera::eye()); + math::Vector3f v(entity->location() - render::camera().location()); 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().location()) , (render::camera().location() - entity->location()))) / math::Vector3f::length(center - render::camera().location()); // the entity closer to the center beam if (smallest_d < 0 || d < smallest_d) { @@ -495,7 +495,7 @@ void frame() float x = 0; float y = 0; - if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && (render::camera().mode() == render::Camera::Cockpit || render::camera().mode() == render::Camera::Track)) { x = 0; y = 0; } else { @@ -503,13 +503,13 @@ void frame() y = (float)(input::mouse_position_y() - render::State::height() / 2) / (float)render::State::height() / render::State::aspect(); } - cursor_aim.assign(render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001)); - cursor_aim -= render::Camera::axis().left() * x; - cursor_aim -= render::Camera::axis().up() * y; + cursor_aim.assign(render::camera().location() + render::camera().axis().forward() * (render::FRUSTUMFRONT + 0.001)); + cursor_aim -= render::camera().axis().left() * x; + cursor_aim -= render::camera().axis().up() * y; float aim_distance = core::range::fxdistance; - //math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001f)); + //math::Vector3f center = render::camera().location() + (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); @@ -526,13 +526,13 @@ void frame() } // check if the mouse is hovering the entity - Vector3f v(entity->location() - render::Camera::eye()); + Vector3f v(entity->location() - render::camera().location()); 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_aim - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor_aim - render::Camera::eye()); + float d = math::Vector3f::length(math::crossproduct((cursor_aim - render::camera().location()) , (render::camera().location() - entity->location()))) / math::Vector3f::length(cursor_aim - render::camera().location()); float r = entity->radius(); @@ -549,7 +549,7 @@ void frame() if (z < 0 || myz < z) { current_hover = entity->id(); // aim slightly behind target to prevent colliding projectiles - aim_distance = entity->radius() + math::distance(render::Camera::eye(), entity->location()); + aim_distance = entity->radius() + math::distance(render::camera().location(), entity->location()); z = myz; } } @@ -559,7 +559,7 @@ void frame() } } - cursor_aim = render::Camera::eye() + (cursor_aim - render::Camera::eye()) * aim_distance / math::distance(render::Camera::eye(), cursor_aim); + cursor_aim = render::camera().location() + (cursor_aim - render::camera().location()) * aim_distance / math::distance(render::camera().location(), cursor_aim); if (!current_target) { current_target_id = 0; diff --git a/src/client/video.cc b/src/client/video.cc index b7eb325..5f8c14d 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -328,8 +328,6 @@ void frame(float elapsed) if (core::application()->connected()) { if (core::game()->time() && core::localplayer()->zone()) { - render::Camera::frame(elapsed); - render::Camera::frustum(); render::draw(elapsed); // draw the world targets::frame(); // validate current target, render sound |