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>2015-01-03 20:23:13 +0000
committerStijn Buys <ingar@osirion.org>2015-01-03 20:23:13 +0000
commit57d958d40af061e83aa99ca12e375e5345836ecd (patch)
tree99969fa526093b0be9d944a810908272882e9408 /src
parent85671408eed36060f5ff4799f2ee153d66e16282 (diff)
Added freelook support. added +freelook action and set it as default bind for the left mouse button.
Diffstat (limited to 'src')
-rw-r--r--src/client/input.cc149
-rw-r--r--src/client/keyboard.cc2
-rw-r--r--src/render/camera.cc9
3 files changed, 133 insertions, 27 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index ab0c847..7f3a021 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -70,19 +70,26 @@ float mouse_direction = 0;
// true if the mouse has control
-float mouse_control_override_time = 0;
-bool mouse_control_override = false;
bool mouse_control = false;
+bool mouse_control_override = false;
+float mouse_control_override_time = 0;
// time the mouse was last moved
float mouse_lastmoved = 0;
// true if we're using a joystick
bool joystick_control = false;
-// time the joystick last moved
+// time the joystick last moved
float joystick_lastmoved = 0;
+// true of freelook is active
+bool freelook_control = false;
+bool freelook_control_override = false;
+float freelook_control_override_time = 0.0f;
+int freelook_control_x = 0;
+int freelook_control_y = 0;
+
const float thruster_offset = 0.05f;
int mouse_position_x()
@@ -435,7 +442,14 @@ void action_press(Key *key)
render::Camera::set_zoom(+0.1f);
break;
case Action::FreeLook:
- // TODO 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;
/* -- fire control -------------------------------- */
@@ -506,7 +520,7 @@ void action_release(Key *key)
case Action::Control:
if (mouse_control_override) {
mouse_control_override = false;
- mouse_control_override_time = 0;
+ 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))) {
@@ -541,7 +555,14 @@ void action_release(Key *key)
case Action::ZoomOut:
break;
case Action::FreeLook:
- // TODO freelook
+ if (freelook_control_override)
+ {
+ freelook_control_override = false;
+ freelook_control_override_time = 0.0f;
+
+ render::Camera::set_direction(0.0f);
+ render::Camera::set_pitch(0.0f);
+ }
break;
@@ -720,8 +741,13 @@ void reset()
render::Camera::reset();
render::Dust::reset();
mouse_control_override = false;
- mouse_control_override_time = 0;
+ mouse_control_override_time = 0.0f;
targets::reset();
+
+ freelook_control_override = false;
+ freelook_control_override_time = 0.0f;
+ freelook_control_x = 0;
+ freelook_control_y = 0;
keyboard->reset();
@@ -852,7 +878,7 @@ void frame()
repeat /= 1000.0f;
delay /= 1000.0f;
- for (Keyboard::Keys::iterator it = keyboard->keys().begin(); it != keyboard->keys().end(); it++) {
+ for (Keyboard::Keys::iterator it = keyboard->keys().begin(); it != keyboard->keys().end(); ++it) {
key = (*it).second;
if (key && (key->sym() < 512) && key->pressed()) {
if ((key->pressed() + delay < core::application()->time()) && (key->lastpressed() + repeat < core::application()->time())) {
@@ -864,47 +890,118 @@ void frame()
/* -- process mouse movement ----------------------*/
mouse_control = false;
+ freelook_control = false;
- if (core::application()->connected() && core::localcontrol()) {
- 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 (core::application()->connected() && core::localcontrol())
+ {
+ // 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()) ));
+
+ // 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) {
+ if (mouse_control || freelook_control ) {
const float aim_square_size = 256.0f;
+ int l = mouse_x;
+ int h = mouse_y;
+
+ if (freelook_control)
+ {
+ // mouse location is relative to where freelook was initiated
+ l -= freelook_control_x;
+ h -= freelook_control_y;
+ }
+ else
+ {
+ // mouse location is relative to the center of the screen
+ l -= (render::State::width() / 2);
+ h -= (render::State::height() / 2);
+ }
+
// direction
- int l = mouse_x - (render::State::width() / 2);
mouse_direction = float(-l) / math::min( 0.5f *(float)(render::State::width()), aim_square_size);
math::clamp(mouse_direction, -1.0f, 1.0f);
// pitch
- int h = mouse_y - (render::State::height() / 2);
mouse_pitch = float(-h) / math::min (0.5f * (float)(render::State::height()), aim_square_size);
math::clamp(mouse_pitch, -1.0f, 1.0f);
- if ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit)) {
-
- local_direction = mouse_direction;
- local_pitch = mouse_pitch;
-
- // enable autopilot override
- local_controlflags = local_controlflags | core::EntityControlable::ControlFlagOverride;
-
- } else if (render::Camera::mode() == render::Camera::Free) {
+ if (freelook_control)
+ {
+ // mouse is controling freelook
+ switch (render::Camera::mode())
+ {
+ case render::Camera::Track:
+ case render::Camera::Cockpit:
+ if (mouse_control)
+ {
+ local_direction = 0.0f;
+ local_pitch = 0.0f;
+
+ // enable autopilot override
+ local_controlflags = local_controlflags | core::EntityControlable::ControlFlagOverride;
+ } else
+ {
+ // disable autopilot override
+ local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
+ }
+ render::Camera::set_direction(mouse_direction);
+ render::Camera::set_pitch(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));
+
+ // disable autopilot override
+ local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
+ break;
+
+ case render::Camera::Overview:
+ break;
+ }
- render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction));
- render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch));
+ } else if (mouse_control)
+ {
+ // mouse is controling direction
+ switch (render::Camera::mode())
+ {
+ case render::Camera::Track:
+ case render::Camera::Cockpit:
+ local_direction = mouse_direction;
+ local_pitch = mouse_pitch;
+
+ // enable autopilot override
+ local_controlflags = local_controlflags | core::EntityControlable::ControlFlagOverride;
+ 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));
- // disable autopilot override
- local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
+ // disable autopilot override
+ local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
+ break;
+
+ case render::Camera::Overview:
+ break;
+ }
+ local_controlflags = local_controlflags | core::EntityControlable::ControlFlagOverride;
}
} else {
+ render::Camera::set_direction(0.0f);
+ render::Camera::set_pitch(0.0f);
+
// disable autopilot override
local_controlflags = local_controlflags & ~core::EntityControlable::ControlFlagOverride;
}
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index 70bca9e..86fb2d4 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -224,7 +224,7 @@ Keyboard::Keyboard()
add_key("euro", SDLK_EURO);
// mouse button aliases
- add_key("mouse1", 512 + SDL_BUTTON_LEFT, 0, "+control");
+ add_key("mouse1", 512 + SDL_BUTTON_LEFT, 0, "+freelook");
add_key("mouse2", 512 + SDL_BUTTON_RIGHT, 0, "+fire");
add_key("mouse3", 512 + SDL_BUTTON_MIDDLE);
diff --git a/src/render/camera.cc b/src/render/camera.cc
index ba9c367..881d9ae 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -263,7 +263,12 @@ void Camera::frame(float seconds)
float cosangle; // cosine of an angle
float angle; // angle in radians
math::Vector3f n; // normal of a plane
+
+ // freelook target
+ target_axis.change_direction(90 * target_direction);
+ target_axis.change_pitch(90 * target_pitch);
+ // rotate scene axis towards target axis
n.assign(math::crossproduct(camera_scene_axis.forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
@@ -324,6 +329,10 @@ void Camera::frame(float seconds)
} else if (mode() == Cockpit) {
+ // freelook target
+ target_axis.change_direction(90 * target_direction);
+ target_axis.change_pitch(90 * target_pitch);
+
camera_scene_axis.assign(target_axis);
if (core::localcontrol()->model()) {