Fixed mousebutton and relative mouse movement bugs

dev
Shariq Shah 9 years ago
parent 22684f22d5
commit b151e2d52f
  1. 8
      .dir-locals.el
  2. 21
      README
  3. 3
      orgfile.org
  4. 36
      src/game.c
  5. 5
      src/input.c
  6. 1
      src/input.h
  7. 10
      src/platform.c
  8. 1
      src/platform.h

@ -1,6 +1,6 @@
((c-mode .
((company-clang-arguments . ("-I/mnt/Dev/Projects/Symmetry/include/GLFW"))
(flycheck-clang-include-path . ("/mnt/Dev/Projects/Symmetry/include/GLFW")))
((company-clang-arguments . ("-I/mnt/Dev/Projects/symmetry/libs/SDL2-2.0.5"))
(flycheck-clang-include-path . ("/mnt/Dev/Projects/symmetry/libs/SDL2-2.0.5")))
)
(nil .
(toggle-truncate-lines t)))
((c++-mode . ((mode . c))))
)

@ -42,7 +42,7 @@ _________________
.. 2.26 DONE Materials with textures
.. 2.27 TODO Lights!
.. 2.28 DONE Fix problems with texture units
.. 2.29 TODO Draw light volumes
.. 2.29 CANCELED Draw light volumes
.. 2.30 TODO Fix problems with frustrum culling
.. 2.31 TODO 2d drawing routines
.. 2.32 TODO Gui
@ -51,8 +51,8 @@ _________________
.. 2.35 TODO Physics
.. 2.36 TODO Variant type
.. 2.37 TODO Event Subsystem
.. 2.38 TODO Fix mouse bugs
.. 2.39 TODO Fix issues with opengl context showing 2.1 only
.. 2.38 DONE Fix mouse bugs
.. 2.39 DONE Fix issues with opengl context showing 2.1 only
.. 2.40 TODO Improve this readme
.. 2.41 TODO ???
.. 2.42 TODO Profit!
@ -252,8 +252,11 @@ _________________
- State "DONE" from "TODO" [2016-05-30 Mon 00:57]
2.29 TODO Draw light volumes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.29 CANCELED Draw light volumes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- State "CANCELED" from "TODO" [2017-02-26 Sun 15:39]
Deferred rendering on hold for now.
2.30 TODO Fix problems with frustrum culling
@ -293,13 +296,17 @@ _________________
~~~~~~~~~~~~~~~~~~~~~~~~~
2.38 TODO Fix mouse bugs
2.38 DONE Fix mouse bugs
~~~~~~~~~~~~~~~~~~~~~~~~
- State "DONE" from "TODO" [2017-03-01 Wed 00:45]
2.39 TODO Fix issues with opengl context showing 2.1 only
2.39 DONE Fix issues with opengl context showing 2.1 only
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- State "DONE" from "TODO" [2017-02-26 Sun 15:39]
2.40 TODO Improve this readme
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -88,7 +88,8 @@ All the code in this repository is under GPLv3, see LICENSE for more information
** TODO Physics
** TODO Variant type
** TODO Event Subsystem
** TODO Fix mouse bugs
** DONE Fix mouse bugs
- State "DONE" from "TODO" [2017-03-01 Wed 00:45]
** DONE Fix issues with opengl context showing 2.1 only
- State "DONE" from "TODO" [2017-02-26 Sun 15:39]
** TODO Improve this readme

@ -25,7 +25,7 @@
#include "gl_load.h"
static void run(void);
static void update(float dt);
static void update(float dt, int* window_should_close);
static void render(void);
static void debug(float dt);
static void scene_setup(void);
@ -195,18 +195,20 @@ void debug(float dt)
vec3 rot_axis_left_right = {0, 1, 0};
/* Look around */
if(input_map_state_get("Turn_Up", KS_PRESSED)) turn_up_down += turn_speed;
if(input_map_state_get("Turn_Down", KS_PRESSED)) turn_up_down -= turn_speed;
if(input_map_state_get("Turn_Up", KS_PRESSED)) turn_up_down += turn_speed;
if(input_map_state_get("Turn_Down", KS_PRESSED)) turn_up_down -= turn_speed;
if(input_map_state_get("Turn_Right", KS_PRESSED)) turn_left_right += turn_speed;
if(input_map_state_get("Turn_Left", KS_PRESSED)) turn_left_right -= turn_speed;
if(input_map_state_get("Turn_Left", KS_PRESSED)) turn_left_right -= turn_speed;
/* if(input_key_state_get(KEY_TAB, KS_PRESSED)) */
/* if(input_key_state_get(KEY_TAB, KS_PRESSED) && input_key_state_get(KEY_LSHIFT, KS_PRESSED)) input_mouse_mode_set(MM_NORMAL); */
if(input_mousebutton_state_get(MB_RIGHT, KS_PRESSED))
{
if(input_mouse_mode_get() != MM_RELATIVE) input_mouse_mode_set(MM_RELATIVE);
const double scale = 0.25;
int cursor_lr, cursor_ud;
input_mouse_pos_get(&cursor_lr, &cursor_ud);
log_message("Mouse position : %d, %d", cursor_lr, cursor_ud);
input_mouse_delta_get(&cursor_lr, &cursor_ud);
turn_up_down = -cursor_ud * turn_speed * dt * scale;
turn_left_right = cursor_lr * turn_speed * dt * scale;
input_mouse_pos_set(0.0, 0.0);
@ -256,13 +258,13 @@ void debug(float dt)
}
/* Movement */
if(input_map_state_get("Sprint", KS_PRESSED)) move_speed *= move_scale;
if(input_map_state_get("Move_Forward", KS_PRESSED)) offset.z -= move_speed;
if(input_map_state_get("Move_Backward", KS_PRESSED)) offset.z += move_speed;
if(input_map_state_get("Move_Left", KS_PRESSED)) offset.x -= move_speed;
if(input_map_state_get("Move_Right", KS_PRESSED)) offset.x += move_speed;
if(input_map_state_get("Move_Up", KS_PRESSED)) offset.y += move_speed;
if(input_map_state_get("Move_Down", KS_PRESSED)) offset.y -= move_speed;
if(input_map_state_get("Sprint", KS_PRESSED)) move_speed *= move_scale;
if(input_map_state_get("Move_Forward", KS_PRESSED)) offset.z -= move_speed;
if(input_map_state_get("Move_Backward", KS_PRESSED)) offset.z += move_speed;
if(input_map_state_get("Move_Left", KS_PRESSED)) offset.x -= move_speed;
if(input_map_state_get("Move_Right", KS_PRESSED)) offset.x += move_speed;
if(input_map_state_get("Move_Up", KS_PRESSED)) offset.y += move_speed;
if(input_map_state_get("Move_Down", KS_PRESSED)) offset.y -= move_speed;
vec3_scale(&offset, &offset, dt);
if(offset.x != 0 || offset.y != 0 || offset.z != 0)
@ -323,18 +325,18 @@ void run(void)
float delta_time = (float)(curr_time - last_time) / 1000.f;
last_time = curr_time;
update(delta_time);
update(delta_time, &should_window_close);
render();
window_swap_buffers(game_state->window);
platform_poll_events(&should_window_close);
}
}
void update(float dt)
void update(float dt, int* window_should_close)
{
input_update();
//if(input_key_state_get(KEY_ESCAPE, KS_PRESSED))
//window_set_should_close(1);
if(input_key_state_get(KEY_ESCAPE, KS_PRESSED))
*window_should_close = 1;
debug(dt);
}

@ -227,3 +227,8 @@ int input_mouse_mode_get(void)
}
void input_mouse_delta_get(int* xpos, int* ypos)
{
platform_mouse_delta_get(xpos, ypos);
}

@ -397,6 +397,7 @@ void input_cleanup(void);
int input_mousebutton_state_get(uint button, int state_type);
int input_key_state_get(int key, int state_type);
void input_mouse_pos_get(int* xpos, int* ypos);
void input_mouse_delta_get(int* xpos, int* ypos); // Use with relative mouse mode
void input_mouse_pos_set(int xpos, int ypos);
void input_mouse_mode_set(enum Mouse_Mode mode);
int input_mouse_mode_get(void);

@ -244,9 +244,10 @@ int platform_key_state_get(int key)
int platform_mousebutton_state_get(uint button)
{
int pressed = 0;
uint32 current_button_state = SDL_GetMouseState(NULL, NULL);
//return (current_button_state & button);
return current_button_state & button;
if((current_button_state & SDL_BUTTON(button)) > 0) pressed = 1;
return pressed;
}
void platform_mouse_position_get(int* x, int* y)
@ -278,3 +279,8 @@ uint32 platform_get_ticks(void)
{
return SDL_GetTicks();
}
void platform_mouse_delta_get(int* x, int* y)
{
SDL_GetRelativeMouseState(x, y);
}

@ -34,6 +34,7 @@ void platform_windowresize_callback_set(Windowresize_Event_Func func);
int platform_key_state_get(int key);
int platform_mousebutton_state_get(uint button);
void platform_mouse_position_get(int* x, int* y);
void platform_mouse_delta_get(int* x, int* y); // Use with relative mouse mode
void platform_mouse_position_set(struct Window* window, int x, int y);
void platform_mouse_global_position_set(int x, int y);
void platform_mouse_relative_mode_set(int relative_mode);

Loading…
Cancel
Save