diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gfx/rodeo_gfx.c | 24 | ||||
| -rw-r--r-- | src/input/irodeo_input.h | 11 | ||||
| -rw-r--r-- | src/input/irodeo_input_t.h | 2 | ||||
| -rw-r--r-- | src/input/rodeo_input.c | 108 | ||||
| -rw-r--r-- | src/window/irodeo_window.h | 5 | ||||
| -rw-r--r-- | src/window/irodeo_window_t.h | 4 | ||||
| -rw-r--r-- | src/window/rodeo_window.c | 42 |
7 files changed, 149 insertions, 47 deletions
diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c index 9004370..5f7b35c 100644 --- a/src/gfx/rodeo_gfx.c +++ b/src/gfx/rodeo_gfx.c @@ -46,8 +46,8 @@ rodeo_gfx_init(float width, float height) //init.type = BGFX_RENDERER_TYPE_COUNT; // auto determine renderer init.type = BGFX_RENDERER_TYPE_OPENGL; // force opengl renderer //SDL_GetWindowSize(irodeo_gfx_state.window, &irodeo_gfx_state.screen_width, &irodeo_gfx_state.screen_height); - init.resolution.width = rodeo_window_screen_height_get(); - init.resolution.height = rodeo_window_screen_width_get(); + init.resolution.width = rodeo_window_height_get(); + init.resolution.height = rodeo_window_width_get(); init.resolution.reset = BGFX_RESET_VSYNC; init.platformData = pd; bgfx_init(&init); @@ -174,8 +174,8 @@ rodeo_gfx_init(float width, float height) SDL_SetWindowResizable(irodeo_window_get(), true); bgfx_reset( - (uint32_t)rodeo_window_screen_width_get(), - (uint32_t)rodeo_window_screen_height_get(), + (uint32_t)rodeo_window_width_get(), + (uint32_t)rodeo_window_height_get(), //BGFX_RESET_MSAA_X16 | BGFX_RESET_MAXANISOTROPY, BGFX_RESET_VSYNC, BGFX_TEXTURE_FORMAT_COUNT @@ -217,7 +217,7 @@ rodeo_gfx_frame_begin(void) float result_width = target_width; float result_height = target_height; const float game_aspect = target_width / target_height; - const float window_aspect = (float)rodeo_window_screen_width_get()/(float)rodeo_window_screen_height_get(); + const float window_aspect = (float)rodeo_window_width_get()/(float)rodeo_window_height_get(); if(window_aspect > game_aspect) { result_width /= (game_aspect) / window_aspect; @@ -250,7 +250,7 @@ rodeo_gfx_frame_begin(void) glm_translated(irodeo_gfx_state.proj_matrix, offset); bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix, irodeo_gfx_state.proj_matrix); - bgfx_set_view_rect(0, 0, 0, (uint16_t)rodeo_window_screen_width_get(), (uint16_t)rodeo_window_screen_height_get()); + bgfx_set_view_rect(0, 0, 0, (uint16_t)rodeo_window_width_get(), (uint16_t)rodeo_window_height_get()); irodeo_gfx_render_buffer_transient_alloc(); bgfx_touch(0); @@ -280,6 +280,18 @@ rodeo_gfx_frame_end(void) } float +rodeo_gfx_width_get(void) +{ + return irodeo_gfx_state.target_width; +} + +float +rodeo_gfx_height_get(void) +{ + return irodeo_gfx_state.target_height; +} + +float rodeo_gfx_frame_time_get(void) { return irodeo_gfx_state.frame_time; //(float)bgfx_get_stats()->cpuTimeFrame; diff --git a/src/input/irodeo_input.h b/src/input/irodeo_input.h new file mode 100644 index 0000000..5066170 --- /dev/null +++ b/src/input/irodeo_input.h @@ -0,0 +1,11 @@ +#pragma once + +// -- internal -- +// public +#include "rodeo/input.h" +// private +#include "irodeo_input_t.h" + +float +irodeo_input_screen_to_world(float input); + diff --git a/src/input/irodeo_input_t.h b/src/input/irodeo_input_t.h index 702e381..a4d46fd 100644 --- a/src/input/irodeo_input_t.h +++ b/src/input/irodeo_input_t.h @@ -1,4 +1,4 @@ - +#pragma once // -- internal -- // public diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c index 63dc0b1..2801718 100644 --- a/src/input/rodeo_input.c +++ b/src/input/rodeo_input.c @@ -2,11 +2,12 @@ // -- internal -- // public #include "rodeo/input.h" -#include "irodeo_input_t.h" #include "rodeo/log.h" #include "rodeo/window.h" +#include "rodeo/gfx.h" // private #include "rodeo_internal.h" +#include "input/irodeo_input.h" #include "window/irodeo_window.h" // -- external -- @@ -18,6 +19,100 @@ static irodeo_input_state_t istate = {0}; +float +irodeo_input_screen_to_world_x(float input) +{ + float gfx_width = rodeo_gfx_width_get(); + float gfx_height = rodeo_gfx_height_get(); + float win_width = (float)rodeo_window_width_get(); + float win_height = (float)rodeo_window_height_get(); + float gfx_aspect = gfx_width / gfx_height; + float win_aspect = win_width / win_height; + float aspect_compare = gfx_aspect / win_aspect; + + if(win_aspect <= gfx_aspect) + { + return (input / win_width) * gfx_width; + } + else + { + float remainder = (win_width - ((gfx_aspect) * win_height)) / 2.0f; + float conversion = win_width * aspect_compare; + return ((input - remainder) / conversion) * gfx_width; + } +} + +float +irodeo_input_screen_to_world_y(float input) +{ + float gfx_width = rodeo_gfx_width_get(); + float gfx_height = rodeo_gfx_height_get(); + float win_width = (float)rodeo_window_width_get(); + float win_height = (float)rodeo_window_height_get(); + float gfx_aspect = gfx_width / gfx_height; + float win_aspect = win_width / win_height; + float aspect_compare = gfx_aspect / win_aspect; + + if(win_aspect < gfx_aspect) + { + float remainder = (win_height - ((1.0f/gfx_aspect) * win_width)) / 2.0f; + float conversion = win_height / aspect_compare; + return (((input - remainder) / conversion) * gfx_height); + } + else + { + return (input / win_height) * gfx_height; + } +} + +float +irodeo_input_screen_to_world_dx(float input) +{ + float gfx_width = rodeo_gfx_width_get(); + float gfx_height = rodeo_gfx_height_get(); + float win_width = (float)rodeo_window_width_get(); + float win_height = (float)rodeo_window_height_get(); + float gfx_aspect = gfx_width / gfx_height; + float win_aspect = win_width / win_height; + float aspect_compare = gfx_aspect / win_aspect; + + if(win_aspect <= gfx_aspect) + { + return input * (gfx_width / win_width); + } + else + { + float remainder = (win_width - ((gfx_aspect) * win_height)) / 2.0f; + float conversion = win_width * aspect_compare; + return ((input - remainder) / conversion) * gfx_width; + } +} + +float +irodeo_input_screen_to_world_dy(float input) +{ + float gfx_width = rodeo_gfx_width_get(); + float gfx_height = rodeo_gfx_height_get(); + float win_width = (float)rodeo_window_width_get(); + float win_height = (float)rodeo_window_height_get(); + float gfx_aspect = gfx_width / gfx_height; + float win_aspect = win_width / win_height; + float aspect_compare = gfx_aspect / win_aspect; + + if(win_aspect < gfx_aspect) + { + //float remainder = (win_height - ((1.0f/gfx_aspect) * win_width)) / 2.0f; + //float conversion = win_height / aspect_compare; + //return (((input - remainder) / conversion) * gfx_height); + return input; + } + else + { + //return (input / win_height) * gfx_height; + return input; + } +} + bool rodeo_input_poll(void) { @@ -43,8 +138,7 @@ rodeo_input_poll(void) BGFX_RESET_VSYNC, BGFX_TEXTURE_FORMAT_COUNT ); - irodeo_window_screen_width_setVar((uint16_t)width); - irodeo_window_screen_height_setVar((uint16_t)height); + irodeo_window_dimensions_update(); } } // keep going, to check for inputs @@ -154,7 +248,7 @@ rodeo_input_poll(void) if(x_value != NULL) { rodeo_input_any_state_t input_state = { - .data.positional_state = event.motion.x, + .data.positional_state = (int64_t)irodeo_input_screen_to_world_x((float)event.motion.x), .type = rodeo_input_type_Positional }; c_foreach( @@ -170,7 +264,7 @@ rodeo_input_poll(void) if(y_value != NULL) { rodeo_input_any_state_t input_state = { - .data.positional_state = event.motion.y, + .data.positional_state = (int64_t)irodeo_input_screen_to_world_y((float)event.motion.y), .type = rodeo_input_type_Positional }; c_foreach( @@ -185,7 +279,7 @@ rodeo_input_poll(void) if(rel_x_value != NULL) { rodeo_input_any_state_t input_state = { - .data.unbounded_range_state = (float)event.motion.xrel, + .data.unbounded_range_state = irodeo_input_screen_to_world_dx((float)event.motion.xrel), .type = rodeo_input_type_UnboundedRange }; c_foreach( @@ -201,7 +295,7 @@ rodeo_input_poll(void) if(rel_y_value != NULL) { rodeo_input_any_state_t input_state = { - .data.unbounded_range_state = (float)event.motion.yrel, + .data.unbounded_range_state = irodeo_input_screen_to_world_dy((float)event.motion.yrel), .type = rodeo_input_type_UnboundedRange }; c_foreach( diff --git a/src/window/irodeo_window.h b/src/window/irodeo_window.h index f0c02e2..23600b8 100644 --- a/src/window/irodeo_window.h +++ b/src/window/irodeo_window.h @@ -15,10 +15,7 @@ SDL_Surface * irodeo_window_surface_get(void); void -irodeo_window_screen_width_setVar(uint16_t width); - -void -irodeo_window_screen_height_setVar(uint16_t height); +irodeo_window_dimensions_update(void); SDL_Window * irodeo_window_get(void); diff --git a/src/window/irodeo_window_t.h b/src/window/irodeo_window_t.h index f7e0c26..3ff4d6c 100644 --- a/src/window/irodeo_window_t.h +++ b/src/window/irodeo_window_t.h @@ -14,8 +14,8 @@ struct SDL_Window* window; SDL_Surface* screen_surface; SDL_SysWMinfo wmi; - uint32_t screen_width; - uint32_t screen_height; + uint32_t width; + uint32_t height; bool quit; } irodeo_window_state_t; diff --git a/src/window/rodeo_window.c b/src/window/rodeo_window.c index e92382e..59c7c18 100644 --- a/src/window/rodeo_window.c +++ b/src/window/rodeo_window.c @@ -14,15 +14,15 @@ static irodeo_window_state_t irodeo_window_state = {0}; void rodeo_window_init( - uint16_t screen_height, - uint16_t screen_width, + uint16_t width, + uint16_t height, cstr title ) { irodeo_window_state.window = NULL; irodeo_window_state.screen_surface = NULL; - irodeo_window_state.screen_height = screen_height; - irodeo_window_state.screen_width = screen_width; + irodeo_window_state.height = height; + irodeo_window_state.width = width; rodeo_log( rodeo_logLevel_info, @@ -58,8 +58,8 @@ rodeo_window_init( cstr_str(&title), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - screen_width, - screen_height, + width, + height, SDL_WINDOW_SHOWN //| SDL_WINDOW_RESIZABLE ); if(irodeo_window_state.window == NULL) @@ -110,7 +110,7 @@ rodeo_window_deinit(void) } void -irodeo_window_update_screen_size(void) +irodeo_window_dimensions_update(void) { int32_t width = 0; int32_t height = 0; @@ -119,34 +119,22 @@ irodeo_window_update_screen_size(void) &width, &height ); - irodeo_window_state.screen_width = (uint32_t)width; - irodeo_window_state.screen_height = (uint32_t)height; + irodeo_window_state.width = (uint32_t)width; + irodeo_window_state.height = (uint32_t)height; } uint32_t -rodeo_window_screen_width_get(void) +rodeo_window_width_get(void) { - irodeo_window_update_screen_size(); - return irodeo_window_state.screen_width; + //irodeo_window_update_screen_size(); + return irodeo_window_state.width; } uint32_t -rodeo_window_screen_height_get(void) +rodeo_window_height_get(void) { - irodeo_window_update_screen_size(); - return irodeo_window_state.screen_height; -} - -void -irodeo_window_screen_width_setVar(uint16_t width) -{ - irodeo_window_state.screen_width = width; -} - -void -irodeo_window_screen_height_setVar(uint16_t height) -{ - irodeo_window_state.screen_height = height; + //irodeo_window_update_screen_size(); + return irodeo_window_state.height; } bool |
