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-11-16 18:47:01 +0000
committerStijn Buys <ingar@osirion.org>2008-11-16 18:47:01 +0000
commit44158ccfbe943b832c0e0bf9ce547212aa6c2b8b (patch)
tree3749d855271779b65283f86599c0faebdfdf4318
parent315a8c2dff9b76ac5e1ebbef265f13ac19d65e3d (diff)
camera zoom
-rw-r--r--src/client/input.cc37
-rw-r--r--src/client/input.h3
-rw-r--r--src/client/keyboard.cc3
-rw-r--r--src/client/view.cc21
-rw-r--r--src/render/camera.cc13
-rw-r--r--src/render/camera.h4
6 files changed, 61 insertions, 20 deletions
diff --git a/src/client/input.cc b/src/client/input.cc
index 8236b9b..a5af430 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -384,17 +384,24 @@ void action_press(Key const *key, std::string const &action)
local_afterburner = -1.0f;
/* -- camera control ------------------------------ */
+
+ } else if (action.compare("+zoomin") == 0) {
+ render::Camera::set_zoom(-0.1f);
+
+ } else if (action.compare("+zoomout") == 0) {
+ render::Camera::set_zoom(+0.1f);
+
} else if (action.compare("+camleft") == 0) {
- render::Camera::set_direction(1.0f);
+ render::Camera::set_direction( math::min(key->pressed() - core::application()->time(), 1.0f) );
} else if (action.compare("+camright") == 0) {
- render::Camera::set_direction(-1.0f);
+ render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(),1.0f));
} else if (action.compare("+camup") == 0) {
- render::Camera::set_pitch(1.0f);
+ render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(),1.0f));
} else if (action.compare("+camdown") == 0) {
- render::Camera::set_pitch(-1.0f);
+ render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(),1.0f));
} else
con_warn << "Unknown action " << action << std::endl;
}
@@ -471,17 +478,15 @@ void action_release(Key *key, std::string const &action)
}
}
-Key::Modifier convert_SDL_modifier(int const sdlmodifier)
-{
- if (sdlmodifier & Key::Shift)
+Key::Modifier modifier() {
+ if ((keyboard_modifiers & Key::Shift) > 0 )
return Key::Shift;
- else if (sdlmodifier & Key::Ctrl)
+ else if ((keyboard_modifiers & Key::Ctrl) > 0 )
return Key::Ctrl;
- else if (sdlmodifier & Key::Alt)
+ else if ((keyboard_modifiers & Key::Alt) > 0 )
return Key::Alt;
else
return Key::None;
-
}
void key_pressed(Key *key)
@@ -515,25 +520,25 @@ void key_pressed(Key *key)
} else if (!core::localplayer()->view() && core::application()->connected() && core::localcontrol()) {
- char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0];
+ char c = key->bind(modifier()).c_str()[0];
if (c == '@') {
// target bind
if (targets::current_id())
- core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << " " << targets::current_id() <<"\n";
+ core::cmd() << key->bind(modifier()) << " " << targets::current_id() <<"\n";
} else if (c == '+') {
// action bind
- action_press(key, key->bind(convert_SDL_modifier(keyboard_modifiers)));
+ action_press(key, key->bind(modifier()));
} else {
// normal bind
- core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n";
+ core::cmd() << key->bind(modifier()) << "\n";
}
} else if (core::application()->connected()) {
- char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0];
+ char c = key->bind(modifier()).c_str()[0];
if (c && c != '+' && c != '@') {
// normal bind
- core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n";
+ core::cmd() << key->bind(modifier()) << "\n";
}
}
}
diff --git a/src/client/input.h b/src/client/input.h
index 88a65b3..394e521 100644
--- a/src/client/input.h
+++ b/src/client/input.h
@@ -43,6 +43,9 @@ float mouse_lastmoved_time();
/// time the joystick was last moved
float joystick_lastmoved_time();
+/// current modifier
+Key::Modifier modifier();
+
extern bool mouse_deadzone;
extern bool mouse_control;
extern bool joystick_control;
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index a29b601..232e0bb 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -45,6 +45,9 @@ Keyboard::Keyboard()
add_action("+camup", Action::None, "rotate camera up");
add_action("+camdown", Action::None, "rotate camera down");
+ add_action("+zoomin", Action::None, "zoom camera in");
+ add_action("+zoomout", Action::None, "zoom camera out");
+
add_action("+thrustup", Action::None, "increase thruster");
add_action("+thrustdown", Action::None, "decrease thruster");
diff --git a/src/client/view.cc b/src/client/view.cc
index 0f981ca..de867c0 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -165,10 +165,25 @@ KeyPress::KeyPress(ui::Widget *parent) : Widget(parent)
void KeyPress::draw()
{
- if(input::last_key_pressed()) {
- ui::paint::color(palette()->highlight());
- ui::paint::label(global_location(), size(), font(), input::last_key_pressed()->name(), ui::AlignCenter);
+ std::string label;
+ ui::paint::color(palette()->highlight());
+
+ Key::Modifier mod = input::modifier();
+ if (mod != Key::None) {
+ if (mod == Key::Shift)
+ label.assign("shift+");
+ else if (mod == Key::Ctrl)
+ label.assign("ctrl+");
+ else if (mod == Key::Alt)
+ label.assign("alt+");
+ }
+
+ if(input::last_key_pressed()) {
+ label.append(input::last_key_pressed()->name());
}
+
+ if (label.size())
+ ui::paint::label(global_location(), size(), font(), label , ui::AlignCenter);
}
/* -- View --------------------------------------------------------- */
diff --git a/src/render/camera.cc b/src/render/camera.cc
index c136375..f97ea96 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -43,6 +43,7 @@ float Camera::pitch_target;
float Camera::target_pitch;
float Camera::distance;
+float Camera::camera_zoom;
void Camera::init()
{
@@ -59,6 +60,7 @@ void Camera::init()
target_direction = 0.0f;
distance = 0.4f;
+ camera_zoom = 1.0f;
camera_mode = Overview;
camera_previous_mode = Track;
@@ -192,6 +194,13 @@ void Camera::view_previous()
break;
}
}
+
+void Camera::set_zoom(float zoom)
+{
+ camera_zoom += zoom;
+ math::clamp(camera_zoom, 1.0f, 10.0f);
+}
+
void Camera::frame(float seconds)
{
math::Axis target_axis;
@@ -245,6 +254,8 @@ void Camera::frame(float seconds)
if (mode() == Track) {
+ distance *= camera_zoom;
+
float cosangle; // cosine of an angle
float angle; // angle in radians
math::Vector3f n; // normal of a plane
@@ -297,7 +308,7 @@ void Camera::frame(float seconds)
pitch_current = degrees360f(pitch_current - d * seconds);
camera_axis.change_pitch(pitch_current);
- distance = 1.5f * core::localcontrol()->radius();
+ distance = 1.5f * core::localcontrol()->radius() * camera_zoom;
} else if (mode() == Cockpit) {
diff --git a/src/render/camera.h b/src/render/camera.h
index 3f30ff6..400c4b0 100644
--- a/src/render/camera.h
+++ b/src/render/camera.h
@@ -53,6 +53,9 @@ public:
*/
static void ortho();
+ /// set target zoom
+ static void set_zoom(float zoom);
+
/// set target direction
static void set_direction(float direction);
@@ -94,6 +97,7 @@ private:
static float target_pitch;
static float distance;
+ static float camera_zoom;
};