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-04-06 15:36:51 +0000
committerStijn Buys <ingar@osirion.org>2008-04-06 15:36:51 +0000
commitc5e90960fc333c2b1d2b3e961da439928b2ac872 (patch)
tree6b6a4fbda96458db97ec880e346e347ee5c7a2c8
parentf36e9bd8190c377836463bdeaf553671d34e8e98 (diff)
mouse control
-rw-r--r--README9
-rw-r--r--osirion.kdevelop.pcsbin556279 -> 555162 bytes
-rw-r--r--osirion.kdevses8
-rw-r--r--src/client/camera.h3
-rw-r--r--src/client/console.cc2
-rw-r--r--src/client/input.cc62
6 files changed, 72 insertions, 12 deletions
diff --git a/README b/README
index f167aa8..b9c71af 100644
--- a/README
+++ b/README
@@ -26,7 +26,7 @@ Client
Keyboard
- The keyboard controls can not be configured:
+ The controls can not be configured:
~ toggle console
space bar switch camera mode
@@ -38,6 +38,11 @@ Keyboard
T open the chat window
print screen screenshot
+Mouse
+
+ You can enable mouse control through the cl_mousecontrol variable.
+ Use the scroll wheel to increase/decrease thruster.
+
Console functions
The following commands are available on the console:
@@ -46,7 +51,7 @@ Console functions
disconnect disconnect the client from the game module
list_ent list registered entities
list_func list registered functions
- list_model list regsitered models
+ list_model list registered models
list_var list registered variables
quit exit the application
r_restart restart the video subsystem
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs
index 89b1535..54e6375 100644
--- a/osirion.kdevelop.pcs
+++ b/osirion.kdevelop.pcs
Binary files differ
diff --git a/osirion.kdevses b/osirion.kdevses
index 1fa919a..16c5d69 100644
--- a/osirion.kdevses
+++ b/osirion.kdevses
@@ -3,16 +3,16 @@
<KDevPrjSession>
<DocsAndViews NumberOfDocuments="5" >
<Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.cc" >
- <View0 Encoding="" line="75" Type="Source" />
+ <View0 Encoding="" line="79" Type="Source" />
</Doc0>
<Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.h" >
- <View0 Encoding="" line="28" Type="Source" />
+ <View0 Encoding="" Type="Source" />
</Doc1>
<Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" >
- <View0 Encoding="" line="381" Type="Source" />
+ <View0 Encoding="" Type="Source" />
</Doc2>
<Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/render.h" >
- <View0 Encoding="" line="28" Type="Source" />
+ <View0 Encoding="" Type="Source" />
</Doc3>
<Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/render.cc" >
<View0 Encoding="" line="89" Type="Source" />
diff --git a/src/client/camera.h b/src/client/camera.h
index 08adfaa..2a79fda 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -47,6 +47,9 @@ namespace camera
/// gameworld coordinates of the camera eye
extern math::Vector3f eye;
+ /// current camera mode
+ extern Mode mode;
+
} // namespace camera
} // namespace client
diff --git a/src/client/console.cc b/src/client/console.cc
index ca84384..04f896f 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -216,8 +216,10 @@ void toggle()
(*history_pos).clear();
SDL_WM_GrabInput(SDL_GRAB_OFF);
+ SDL_ShowCursor(SDL_ENABLE);
} else {
SDL_WM_GrabInput(SDL_GRAB_ON);
+ SDL_ShowCursor(SDL_DISABLE);
}
setkeyboardmode(console::visible());
diff --git a/src/client/input.cc b/src/client/input.cc
index 0650119..c7c751e 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -12,6 +12,7 @@
#include "client/camera.h"
#include "client/keyboard.h"
#include "client/video.h"
+#include "render/text.h"
#include "SDL/SDL.h"
@@ -34,12 +35,17 @@ unsigned int last_control = 0;
int mouse_x = 0;
int mouse_y = 0;
+core::Cvar *cl_mousecontrol = 0;
+
void init()
{
con_print << "Initializing input..." << std::endl;
client::setkeyboardmode(false);
+ SDL_ShowCursor(SDL_DISABLE);
SDL_WM_GrabInput(SDL_GRAB_ON);
// SDL_EnableUNICODE(1);
+ cl_mousecontrol = core::Cvar::get("cl_mousecontrol", "0", core::Cvar::Archive);
+ cl_mousecontrol->set_info("[bool] mouse control");
}
void shutdown()
@@ -61,6 +67,8 @@ void keyreleased(const SDL_keysym &keysym)
}
// handle key press events for the game world
+
+// http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlkey.html
void keypressed(const SDL_keysym &keysym)
{
switch (keysym.sym) {
@@ -77,7 +85,6 @@ void keypressed(const SDL_keysym &keysym)
camera::key_down();
break;
case SDLK_KP_PLUS:
- // TODO set core entity params
local_thrust += 0.015f;
if (local_thrust > 1.0f)
local_thrust = 1.0f;
@@ -102,6 +109,27 @@ void keypressed(const SDL_keysym &keysym)
}
+// handle mouse button events for the game world
+
+// http://docs.mandragor.org/files/Common_libs_documentation/SDL/SDL_Documentation_project_en/sdlmousebuttonevent.html
+void mousebuttonpressed(const SDL_MouseButtonEvent &button)
+{
+ switch (button.button) {
+ case SDL_BUTTON_WHEELUP:
+ local_thrust += 0.015f;
+ if (local_thrust > 1.0f)
+ local_thrust = 1.0f;
+
+ break;
+ case SDL_BUTTON_WHEELDOWN:
+ local_thrust -= 0.02f;
+ if (local_thrust < 0.0f)
+ local_thrust = 0.0f;
+
+ break;
+ }
+}
+
void frame(float seconds)
{
if (core::localcontrol() && (last_control != core::localcontrol()->id())) {
@@ -119,7 +147,11 @@ void frame(float seconds)
mouse_x = event.motion.x;
mouse_y = event.motion.y;
break;
+ case SDL_MOUSEBUTTONDOWN:
+ if (!console::visible() && core::application()->connected() && core::localcontrol())
+ mousebuttonpressed(event.button);
+ break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_PRINT) {
video::screenshot();
@@ -162,12 +194,30 @@ void frame(float seconds)
}
}
-
+
if (!console::visible() && core::application()->connected() && core::localcontrol()) {
- if (local_turn > 1.0f)
- local_turn = 1.0f;
- else if (local_turn < -1.0f)
- local_turn = -1.0f;
+
+ if (cl_mousecontrol->value()) {
+ // mouse control when camera is in tracking mode
+ if (camera::mode == camera::Track) {
+ int l = mouse_x - (video::width >> 1);
+
+ if (abs(l) < ( CHARWIDTH >> 1 )) // dead zone
+ local_turn = 0;
+ else {
+ l = (mouse_x - CHARWIDTH) - ((video::width - CHARWIDTH) >> 1);
+ local_turn = float (-l) / (float) ((video::width - CHARWIDTH) >> 1);
+ }
+ } else {
+ local_turn = 0;
+ }
+
+ } else {
+ if (local_turn > 1.0f)
+ local_turn = 1.0f;
+ else if (local_turn < -1.0f)
+ local_turn = -1.0f;
+ }
core::localcontrol()->set_thrust(local_thrust);
core::localcontrol()->set_direction(local_turn);