From 11b2f2da149b335659dea0c7ed3628e06d52465d Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Sat, 14 Dec 2019 15:04:39 +1100 Subject: [PATCH] Fixed gimbal lock by fixing the quaternion multiplication order when getting absolute rotation for camera entity --- src/game/player.c | 14 +++++--------- src/game/transform.c | 3 ++- todo.txt | 6 ++++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/game/player.c b/src/game/player.c index 9243053..0d481ca 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -77,10 +77,10 @@ void player_update(struct Player* player, struct Scene* scene, float dt) vec3 rot_axis_pitch = { 1, 0, 0 }; vec3 rot_axis_yaw = { 0, 1, 0 }; - if(input_map_state_get("Turn_Up", KS_PRESSED)) pitch += player->turn_speed; - if(input_map_state_get("Turn_Down", KS_PRESSED)) pitch -= player->turn_speed; - if(input_map_state_get("Turn_Right", KS_PRESSED)) yaw += player->turn_speed; - if(input_map_state_get("Turn_Left", KS_PRESSED)) yaw -= player->turn_speed; + if(input_map_state_get("Turn_Up", KS_PRESSED)) pitch += player->turn_speed; + if(input_map_state_get("Turn_Down", KS_PRESSED)) pitch -= player->turn_speed; + if(input_map_state_get("Turn_Right", KS_PRESSED)) yaw += player->turn_speed; + if(input_map_state_get("Turn_Left", KS_PRESSED)) yaw -= player->turn_speed; int cursor_yaw, cursor_pitch; input_mouse_delta_get(&cursor_yaw, &cursor_pitch); @@ -106,14 +106,10 @@ void player_update(struct Player* player, struct Scene* scene, float dt) } if(yaw != 0.f) - { - transform_rotate(player->camera_node, &rot_axis_yaw, -yaw, TS_WORLD); - } + transform_rotate(player, &rot_axis_yaw, -yaw, TS_WORLD); if(pitch != 0.f) - { transform_rotate(player->camera_node, &rot_axis_pitch, pitch, TS_LOCAL); - } /* Movement */ float move_speed = player->move_speed; diff --git a/src/game/transform.c b/src/game/transform.c index 827e636..dcb7cf8 100755 --- a/src/game/transform.c +++ b/src/game/transform.c @@ -319,7 +319,8 @@ void transform_get_absolute_rot(struct Entity* entity, quat* res) done = true; break; } - quat_mul(res, res, &parent->transform.rotation); + //quat_mul(res, res, &parent->transform.rotation); + quat_mul(res, &parent->transform.rotation, res); parent = parent->transform.parent; } } diff --git a/todo.txt b/todo.txt index 703288d..c90ca67 100644 --- a/todo.txt +++ b/todo.txt @@ -1,10 +1,11 @@ Todo: - - Fix gimbal lock in fps camera + - Fix hierarchical transforms not working in editor mode - Fix weird rotational bug when rotation resets or inverts after 180 degrees - Better, more accurate picking - Add editor undo for transformation operations - Add material export for blender exporter? - Remove flickering from selection in editor + - Fix crash when exiting from fullscreen mode - Allow renaming scene objects in editor - Check if we still need to rotate by 90 degrees when exporting from blender - Fire an event when the game mode is changed so that editor camera state and other game related systems know when to update @@ -354,4 +355,5 @@ Done: * Fixed cameras not resizing to current resolution when scene is loaded/reloaded * Added parameter to entity_load command that renames the newly loaded object to whatever the second specified parameter is * Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes - * Add simple player fps controls \ No newline at end of file + * Add simple player fps controls + * Fixed gimbal lock in fps camera by fixing the order of quaternion multiplication when getting absolute rotation \ No newline at end of file