diff options
| author | realtradam <[email protected]> | 2023-06-13 17:50:34 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-06-13 17:50:34 -0400 |
| commit | 425516a9c53183179c43517f1b6501a790378a05 (patch) | |
| tree | 9b4d905a0dd79364cf44ab52332f5973cc974f17 | |
| parent | dcf3e1da9e9e1048604eaf2286bca055eff05be9 (diff) | |
| download | RodeoKit-425516a9c53183179c43517f1b6501a790378a05.tar.gz RodeoKit-425516a9c53183179c43517f1b6501a790378a05.zip | |
finish implementing letterbox functionality
| -rw-r--r-- | include/rodeo/gfx.h | 6 | ||||
| -rw-r--r-- | src/gfx/rodeo_gfx.c | 457 | ||||
| -rw-r--r-- | src/input/rodeo_input.c | 16 |
3 files changed, 265 insertions, 214 deletions
diff --git a/include/rodeo/gfx.h b/include/rodeo/gfx.h index 05ce7d0..0195f49 100644 --- a/include/rodeo/gfx.h +++ b/include/rodeo/gfx.h @@ -25,6 +25,12 @@ rodeo_gfx_width_get(void); float rodeo_gfx_height_get(void); +rodeo_rectangle_t +rodeo_gfx_letterbox_first_get(void); + +rodeo_rectangle_t +rodeo_gfx_letterbox_second_get(void); + cstr rodeo_gfx_renderer_name_get(void); diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c index 5f7b35c..33c4be3 100644 --- a/src/gfx/rodeo_gfx.c +++ b/src/gfx/rodeo_gfx.c @@ -19,7 +19,7 @@ static irodeo_gfx_state_t irodeo_gfx_state = {0}; -void + void rodeo_gfx_init(float width, float height) { @@ -45,7 +45,7 @@ rodeo_gfx_init(float width, float height) bgfx_init_ctor(&init); //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); + //SDL_GetWindowSize(irodeo_gfx_state.window, &irodeo_gfx_state.screen_width, &irodeo_gfx_state.screen_height); init.resolution.width = rodeo_window_height_get(); init.resolution.height = rodeo_window_width_get(); init.resolution.reset = BGFX_RESET_VSYNC; @@ -55,17 +55,17 @@ rodeo_gfx_init(float width, float height) bgfx_set_debug(BGFX_DEBUG_TEXT); //bgfx_set_state(BGFX_STATE_CULL_CCW, 0); - + bgfx_dbg_text_clear(0x0, false); bgfx_set_view_clear( - 0, - BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, - //0x443355FF, - 0x000000FF, - 1.0f, - 0 - ); + 0, + BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, + //0x443355FF, + 0x000000FF, + 1.0f, + 0 + ); rodeo_log(rodeo_logLevel_info, "Setting up default render pipeline..."); // set up vertex layout @@ -80,62 +80,62 @@ rodeo_gfx_init(float width, float height) // load shaders cstr shader_path = cstr_lit("???"); switch(bgfx_get_renderer_type()) { - case BGFX_RENDERER_TYPE_NOOP: + case BGFX_RENDERER_TYPE_NOOP: rodeo_log( - rodeo_logLevel_error, - "BGFX failed to get determine an appropriate renderer" - ); + rodeo_logLevel_error, + "BGFX failed to get determine an appropriate renderer" + ); exit(EXIT_FAILURE); - case BGFX_RENDERER_TYPE_OPENGLES: + case BGFX_RENDERER_TYPE_OPENGLES: cstr_assign( - &shader_path, - "shaders/100_es/" - ); + &shader_path, + "shaders/100_es/" + ); break; - case BGFX_RENDERER_TYPE_VULKAN: + case BGFX_RENDERER_TYPE_VULKAN: cstr_assign( - &shader_path, - "shaders/spirv/" - ); + &shader_path, + "shaders/spirv/" + ); break; - case BGFX_RENDERER_TYPE_OPENGL: + case BGFX_RENDERER_TYPE_OPENGL: cstr_assign( - &shader_path, - "shaders/opengl/" - ); + &shader_path, + "shaders/opengl/" + ); break; default: rodeo_log( - rodeo_logLevel_error, - "No shaders implemented for BGFX renderer chosen" - ); + rodeo_logLevel_error, + "No shaders implemented for BGFX renderer chosen" + ); exit(EXIT_FAILURE); - } + } cstr vertex_shader_path = cstr_lit("simple.vertex.bin"); cstr fragment_shader_path = cstr_lit("simple.fragment.bin"); cstr_insert_s( - &vertex_shader_path, - 0, - shader_path - ); + &vertex_shader_path, + 0, + shader_path + ); cstr_insert_s( - &fragment_shader_path, - 0, - shader_path - ); + &fragment_shader_path, + 0, + shader_path + ); irodeo_gfx_state.vertex_shader = irodeo_gfx_shader_load(vertex_shader_path); irodeo_gfx_state.fragment_shader = irodeo_gfx_shader_load(fragment_shader_path); irodeo_gfx_state.program_shader = bgfx_create_program( - irodeo_gfx_state.vertex_shader, - irodeo_gfx_state.fragment_shader, - true - ); + irodeo_gfx_state.vertex_shader, + irodeo_gfx_state.fragment_shader, + true + ); rodeo_log( - rodeo_logLevel_info, - "Default render pipeline finished setup" - ); + rodeo_logLevel_info, + "Default render pipeline finished setup" + ); //bgfx_texture_handle_t default_bgfx_texture = rodeo_texture_2d_create_default(); @@ -154,17 +154,17 @@ rodeo_gfx_init(float width, float height) irodeo_gfx_state.default_texture.internal_texture->texture_bgfx = bgfx_create_texture_2d( - 1, - 1, - false, - 0, - BGFX_TEXTURE_FORMAT_RGBA8, - BGFX_SAMPLER_UVW_CLAMP | BGFX_SAMPLER_MAG_POINT, - bgfx_copy( - &default_texture_data, - sizeof(default_texture_data) - ) - ); + 1, + 1, + false, + 0, + BGFX_TEXTURE_FORMAT_RGBA8, + BGFX_SAMPLER_UVW_CLAMP | BGFX_SAMPLER_MAG_POINT, + bgfx_copy( + &default_texture_data, + sizeof(default_texture_data) + ) + ); irodeo_gfx_state.default_texture.width = 1; irodeo_gfx_state.default_texture.height = 1; @@ -174,19 +174,19 @@ rodeo_gfx_init(float width, float height) SDL_SetWindowResizable(irodeo_window_get(), true); bgfx_reset( - (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 - ); + (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 + ); rodeo_random_seed_set(SDL_GetTicks64()); irodeo_gfx_state.frame_end = (uint32_t)SDL_GetPerformanceCounter(); } -void + void rodeo_gfx_deinit(void) { @@ -196,19 +196,19 @@ rodeo_gfx_deinit(void) bgfx_shutdown(); } -void + void rodeo_gfx_frame_begin(void) { //vec3 eye = {0.0f, 0.0f, -35.0f}; //vec3 center = {0.0f, 0.0f, 0.0f}; //vec3 up = {0, 1, 0}; - + //glm_lookat(eye, center, up, view); - + glm_mat4_identity(irodeo_gfx_state.view_matrix); //glm_perspective(glm_rad(60.f), 640.f / 480.f, 0.1f, 100.0f, proj); - + // scale the game screen to fit window size with letterbox // what size we declare the game screen to be within const float target_width = irodeo_gfx_state.target_width; @@ -238,14 +238,14 @@ rodeo_gfx_frame_begin(void) }; glm_ortho_rh_zo( - 0, - result_width, - result_height, - 0, - -100.0f, - 100.0f, - irodeo_gfx_state.proj_matrix - ); + 0, + result_width, + result_height, + 0, + -100.0f, + 100.0f, + irodeo_gfx_state.proj_matrix + ); glm_translated(irodeo_gfx_state.proj_matrix, offset); @@ -258,16 +258,16 @@ rodeo_gfx_frame_begin(void) irodeo_gfx_state.frame_start = irodeo_gfx_state.frame_end; } -void + void rodeo_gfx_frame_end(void) { rodeo_gfx_renderer_flush(); bgfx_frame(false); - #ifndef __EMSCRIPTEN__ - irodeo_gfx_frame_stall(); - #endif +#ifndef __EMSCRIPTEN__ + irodeo_gfx_frame_stall(); +#endif irodeo_gfx_state.frame_count += 1; irodeo_gfx_state.frame_end = (uint32_t)SDL_GetPerformanceCounter(); // @@ -279,25 +279,78 @@ rodeo_gfx_frame_end(void) #endif } -float + float rodeo_gfx_width_get(void) { return irodeo_gfx_state.target_width; } -float + float rodeo_gfx_height_get(void) { return irodeo_gfx_state.target_height; } -float + rodeo_rectangle_t +rodeo_gfx_letterbox_first_get(void) +{ + const float target_width = irodeo_gfx_state.target_width; + const float target_height = irodeo_gfx_state.target_height; + // what the calculated size is to fit in the window + 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_width_get()/(float)rodeo_window_height_get(); + if(window_aspect > game_aspect) + { + result_width /= (game_aspect) / window_aspect; + } + else if(window_aspect < game_aspect) + { + result_height *= (game_aspect) / window_aspect; + } + + rodeo_rectangle_t result = {0}; + + // while checking for float equality should generally never be done + // in this case it is ok because the case where they are exactly equal + // causes the letterboxes to fill the screen instead of not existing. + // this is avoided this by leaving the rectangle size at 0 in that case. + if(window_aspect != game_aspect) + { + result = (rodeo_rectangle_t){ + .x = (-result_width + target_width) / 2, + .y = (-result_height + target_height) / 2, + .width = (result_width*( (window_aspect > game_aspect) ? 0 : 1 )) + ((result_width - target_width) / 2), + .height = (result_height*( (window_aspect < game_aspect) ? 0 : 1 )) + ((result_height - target_height) / 2), + }; + } + + return result; +} + + rodeo_rectangle_t +rodeo_gfx_letterbox_second_get(void) +{ + rodeo_rectangle_t result = rodeo_gfx_letterbox_first_get(); + if(rodeo_gfx_width_get() != result.width) + { // second box needs to be offset to the right + result.x += rodeo_gfx_width_get() + result.width; + } + else + { // second box needs to be offset downward + result.y += rodeo_gfx_height_get() + result.height; + } + return result; +} + + float rodeo_gfx_frame_time_get(void) { return irodeo_gfx_state.frame_time; //(float)bgfx_get_stats()->cpuTimeFrame; } -float + float rodeo_gfx_frame_perSecond_get(void) { return 1.0f / (rodeo_gfx_frame_time_get() / 1000.0f); @@ -306,14 +359,14 @@ rodeo_gfx_frame_perSecond_get(void) // measures how much time there is left in the remaining frame until // the frame target time is reached. If we surpassed the target time // then this will be negative -float + float irodeo_gfx_frame_remaining_get(void) { - #ifdef __EMSCRIPTEN__ - float target = 60.0f; - #else - float target = (float)rodeo_gfx_frame_limit_get(); - #endif +#ifdef __EMSCRIPTEN__ + float target = 60.0f; +#else + float target = (float)rodeo_gfx_frame_limit_get(); +#endif float result = (1/target * 1000.0f) - ((float)(SDL_GetPerformanceCounter() - irodeo_gfx_state.frame_start) / (float)SDL_GetPerformanceFrequency() * 1000.0f); @@ -323,7 +376,7 @@ irodeo_gfx_frame_remaining_get(void) // used internally at the end of every frame to fill for time // in order to reach the desired framerate -void + void irodeo_gfx_frame_stall(void) { // if no frame limit then run as fast as possible @@ -347,48 +400,48 @@ irodeo_gfx_frame_stall(void) } } -void + void rodeo_gfx_renderer_flush(void) { // set default texture bgfx_set_texture( - 0, - irodeo_gfx_state.texture_uniforms[0], - rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx, - UINT32_MAX - ); + 0, + irodeo_gfx_state.texture_uniforms[0], + rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx, + UINT32_MAX + ); if(irodeo_gfx_state.active_texture_p != NULL) { // set dynamic texture bgfx_set_texture( - 1, - irodeo_gfx_state.texture_uniforms[1], - *irodeo_gfx_state.active_texture_p, - UINT32_MAX - ); + 1, + irodeo_gfx_state.texture_uniforms[1], + *irodeo_gfx_state.active_texture_p, + UINT32_MAX + ); } else { // set to default if none exists bgfx_set_texture( - 1, - irodeo_gfx_state.texture_uniforms[1], - rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx, - UINT32_MAX - ); + 1, + irodeo_gfx_state.texture_uniforms[1], + rodeo_gfx_texture_2d_default_get().internal_texture->texture_bgfx, + UINT32_MAX + ); } if(irodeo_gfx_state.vertex_size > 0) { bgfx_set_state( - BGFX_STATE_CULL_CW | - BGFX_STATE_WRITE_RGB | - BGFX_STATE_WRITE_A | - //BGFX_STATE_DEPTH_TEST_LESS | - //BGFX_STATE_MSAA | - BGFX_STATE_BLEND_ALPHA, - 0 - ); + BGFX_STATE_CULL_CW | + BGFX_STATE_WRITE_RGB | + BGFX_STATE_WRITE_A | + //BGFX_STATE_DEPTH_TEST_LESS | + //BGFX_STATE_MSAA | + BGFX_STATE_BLEND_ALPHA, + 0 + ); // upload remaining batched vertices bgfx_set_transient_vertex_buffer(0, &irodeo_gfx_state.vertex_buffer_handle, 0, irodeo_gfx_state.vertex_size); @@ -416,24 +469,24 @@ rodeo_gfx_renderer_flush(void) irodeo_gfx_state.active_texture_p = NULL; } -rodeo_gfx_texture_2d_t + rodeo_gfx_texture_2d_t rodeo_gfx_texture_2d_default_get(void) { return irodeo_gfx_state.default_texture; } -rodeo_gfx_texture_2d_t + rodeo_gfx_texture_2d_t rodeo_gfx_texture_2d_create_from_RGBA8( - const uint16_t width, - const uint16_t height, - const uint8_t memory[] -) + const uint16_t width, + const uint16_t height, + const uint8_t memory[] + ) { rodeo_gfx_texture_2d_t texture; texture.internal_texture = malloc(sizeof(irodeo_gfx_texture_internal_t)); bgfx_copy(memory, (uint32_t)width * (uint32_t)height * sizeof(uint8_t) * 4); texture.internal_texture->texture_bgfx = - bgfx_create_texture_2d( + bgfx_create_texture_2d( width, height, false, @@ -441,7 +494,7 @@ rodeo_gfx_texture_2d_create_from_RGBA8( BGFX_TEXTURE_FORMAT_RGBA8, BGFX_SAMPLER_UVW_CLAMP | BGFX_SAMPLER_MAG_POINT, bgfx_copy(memory, (uint32_t)width * (uint32_t)height * sizeof(uint8_t) * 4) - ); + ); texture.width = width; texture.height = height; @@ -449,38 +502,38 @@ rodeo_gfx_texture_2d_create_from_RGBA8( return texture; } -void + void rodeo_gfx_texture_2d_destroy(rodeo_gfx_texture_2d_t texture) { bgfx_destroy_texture(texture.internal_texture->texture_bgfx); free(texture.internal_texture); } -void + void rodeo_gfx_rectangle_draw( - const rodeo_rectangle_t rectangle, - const rodeo_color_RGBAFloat_t color -) + const rodeo_rectangle_t rectangle, + const rodeo_color_RGBAFloat_t color + ) { rodeo_gfx_texture_2d_draw( - rectangle, - (rodeo_rectangle_t){ 0, 0, (float)rodeo_gfx_texture_2d_default_get().width, (float)rodeo_gfx_texture_2d_default_get().height }, - color, - rodeo_gfx_texture_2d_default_get() - ); + rectangle, + (rodeo_rectangle_t){ 0, 0, (float)rodeo_gfx_texture_2d_default_get().width, (float)rodeo_gfx_texture_2d_default_get().height }, + color, + rodeo_gfx_texture_2d_default_get() + ); } void rodeo_gfx_texture_2d_draw( - // cant be NULL - const rodeo_rectangle_t destination, - // default: entire texture - const rodeo_rectangle_t source, - // default: white - const rodeo_color_RGBAFloat_t color, - // default: default texture - const rodeo_gfx_texture_2d_t texture -) + // cant be NULL + const rodeo_rectangle_t destination, + // default: entire texture + const rodeo_rectangle_t source, + // default: white + const rodeo_color_RGBAFloat_t color, + // default: default texture + const rodeo_gfx_texture_2d_t texture + ) { // whether to use default or custom texture float texture_uniform_slot = 0.0; @@ -490,18 +543,18 @@ rodeo_gfx_texture_2d_draw( { source_applied = (rodeo_rectangle_t){ .x = source.x / (float)texture.width, - .y = source.y / (float)texture.height, - .width = source.width / (float)texture.width, - .height = source.height / (float)texture.height, + .y = source.y / (float)texture.height, + .width = source.width / (float)texture.width, + .height = source.height / (float)texture.height, }; } else { source_applied = (rodeo_rectangle_t){ .x = 0.0f, - .y = 0.0f, - .width = 1.0f, - .height = 1.0f, + .y = 0.0f, + .width = 1.0f, + .height = 1.0f, }; } @@ -578,8 +631,8 @@ rodeo_gfx_texture_2d_draw( { 0, 1, 3, 1, 2, 3 - //2, 1, 0, - //2, 3, 1 + //2, 1, 0, + //2, 3, 1 }; irodeo_gfx_state.batched_indices[irodeo_gfx_state.index_size] = irodeo_gfx_state.index_count + indices[0]; irodeo_gfx_state.index_size += 1; @@ -602,7 +655,7 @@ rodeo_gfx_texture_2d_draw( } } -rodeo_gfx_texture_2d_t + rodeo_gfx_texture_2d_t rodeo_gfx_texture_2d_create_from_path(cstr path) { // load image to surface @@ -610,10 +663,10 @@ rodeo_gfx_texture_2d_create_from_path(cstr path) if(surface == NULL) { rodeo_log( - rodeo_logLevel_error, - "Loading texture from image failed: %s", - IMG_GetError() - ); + rodeo_logLevel_error, + "Loading texture from image failed: %s", + IMG_GetError() + ); return (rodeo_gfx_texture_2d_t){0}; } @@ -628,29 +681,29 @@ rodeo_gfx_texture_2d_create_from_path(cstr path) // convert pixel format of surface into RGBA8 SDL_Surface *converted_surface = SDL_ConvertSurfaceFormat( - surface, - // pixel format needs to be backwards - // of what bgfx uses for some reason - SDL_PIXELFORMAT_ABGR8888, - 0 - ); + surface, + // pixel format needs to be backwards + // of what bgfx uses for some reason + SDL_PIXELFORMAT_ABGR8888, + 0 + ); if(converted_surface == NULL) { rodeo_log( - rodeo_logLevel_error, - "Converting image to RGBA8 while loading texture failed: %s", - SDL_GetError() - ); + rodeo_logLevel_error, + "Converting image to RGBA8 while loading texture failed: %s", + SDL_GetError() + ); SDL_FreeSurface(surface); return (rodeo_gfx_texture_2d_t){0}; } // load the pixel data into our own texture rodeo_gfx_texture_2d_t texture = rodeo_gfx_texture_2d_create_from_RGBA8( - (uint16_t)converted_surface->w, - (uint16_t)converted_surface->h, - converted_surface->pixels - ); + (uint16_t)converted_surface->w, + (uint16_t)converted_surface->h, + converted_surface->pixels + ); SDL_FreeSurface(surface); SDL_FreeSurface(converted_surface); @@ -658,44 +711,44 @@ rodeo_gfx_texture_2d_create_from_path(cstr path) return texture; } -uint64_t + uint64_t rodeo_gfx_frame_count_get(void) { return irodeo_gfx_state.frame_count; } -void + void rodeo_gfx_frame_limit_set(uint32_t limit) { - #ifdef __EMSCRIPTEN__ - rodeo_log( +#ifdef __EMSCRIPTEN__ + rodeo_log( rodeo_logLevel_warning, "Framerate limit cannot be set on web platform. Limit is enforced by platform to 60fps" - ); - #else - irodeo_gfx_state.frame_limit = limit; - #endif + ); +#else + irodeo_gfx_state.frame_limit = limit; +#endif } -uint32_t + uint32_t rodeo_gfx_frame_limit_get(void) { - #ifdef __EMSCRIPTEN__ - return 60; - #else - return irodeo_gfx_state.frame_limit; - #endif +#ifdef __EMSCRIPTEN__ + return 60; +#else + return irodeo_gfx_state.frame_limit; +#endif } -cstr + cstr rodeo_gfx_renderer_name_get(void) { return cstr_from( - bgfx_get_renderer_name(bgfx_get_renderer_type()) - ); + bgfx_get_renderer_name(bgfx_get_renderer_type()) + ); } -bgfx_shader_handle_t + bgfx_shader_handle_t irodeo_gfx_shader_load(const cstr path) { const char* path_cstr = cstr_str(&path); @@ -705,10 +758,10 @@ irodeo_gfx_shader_load(const cstr path) if(!file) { rodeo_log( - rodeo_logLevel_error, - "Shader file \"%s\" not found", - path_cstr - ); + rodeo_logLevel_error, + "Shader file \"%s\" not found", + path_cstr + ); return (bgfx_shader_handle_t)BGFX_INVALID_HANDLE; } @@ -717,23 +770,23 @@ irodeo_gfx_shader_load(const cstr path) if(file_size_temp < 0) { rodeo_log( - rodeo_logLevel_error, - "Failed to get current file position of given stream(ftell() error)" - ); + rodeo_logLevel_error, + "Failed to get current file position of given stream(ftell() error)" + ); exit(EXIT_FAILURE); } if((file_size_temp + 1) > UINT32_MAX) { rodeo_log( - rodeo_logLevel_error, - "File size larger then what bgfx can allocate" - ); + rodeo_logLevel_error, + "File size larger then what bgfx can allocate" + ); exit(EXIT_FAILURE); } uint32_t file_size = (uint32_t)file_size_temp; fseek(file, 0, SEEK_SET); - + const bgfx_memory_t *mem = bgfx_alloc(file_size + 1); fread(mem->data, 1, file_size, file); mem->data[mem->size - 1] = '\0'; @@ -741,15 +794,15 @@ irodeo_gfx_shader_load(const cstr path) bgfx_shader_handle_t shader = bgfx_create_shader(mem); rodeo_log( - rodeo_logLevel_info, - "Shader loaded with idx: %"PRIu8"", - shader.idx - ); + rodeo_logLevel_info, + "Shader loaded with idx: %"PRIu8"", + shader.idx + ); return shader; } -void + void irodeo_gfx_render_buffer_transient_alloc(void) { bgfx_alloc_transient_vertex_buffer(&irodeo_gfx_state.vertex_buffer_handle, mrodeo_vertex_size_max, &irodeo_gfx_state.vertex_layout); diff --git a/src/input/rodeo_input.c b/src/input/rodeo_input.c index 2801718..8d5c1bd 100644 --- a/src/input/rodeo_input.c +++ b/src/input/rodeo_input.c @@ -74,7 +74,6 @@ irodeo_input_screen_to_world_dx(float input) 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) { @@ -82,9 +81,7 @@ irodeo_input_screen_to_world_dx(float input) } else { - float remainder = (win_width - ((gfx_aspect) * win_height)) / 2.0f; - float conversion = win_width * aspect_compare; - return ((input - remainder) / conversion) * gfx_width; + return (input / win_height) * gfx_height; } } @@ -97,19 +94,14 @@ irodeo_input_screen_to_world_dy(float input) 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) + 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; + return input * (gfx_width / win_width); } else { - //return (input / win_height) * gfx_height; - return input; + return (input / win_height) * gfx_height; } } |
