Fixed gimbal lock by fixing the quaternion multiplication order when getting absolute rotation for camera entity

dev
Shariq Shah 6 years ago
parent 7134d23e6b
commit 11b2f2da14
  1. 14
      src/game/player.c
  2. 3
      src/game/transform.c
  3. 6
      todo.txt

@ -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_pitch = { 1, 0, 0 };
vec3 rot_axis_yaw = { 0, 1, 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_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_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_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_Left", KS_PRESSED)) yaw -= player->turn_speed;
int cursor_yaw, cursor_pitch; int cursor_yaw, cursor_pitch;
input_mouse_delta_get(&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) if(yaw != 0.f)
{ transform_rotate(player, &rot_axis_yaw, -yaw, TS_WORLD);
transform_rotate(player->camera_node, &rot_axis_yaw, -yaw, TS_WORLD);
}
if(pitch != 0.f) if(pitch != 0.f)
{
transform_rotate(player->camera_node, &rot_axis_pitch, pitch, TS_LOCAL); transform_rotate(player->camera_node, &rot_axis_pitch, pitch, TS_LOCAL);
}
/* Movement */ /* Movement */
float move_speed = player->move_speed; float move_speed = player->move_speed;

@ -319,7 +319,8 @@ void transform_get_absolute_rot(struct Entity* entity, quat* res)
done = true; done = true;
break; 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; parent = parent->transform.parent;
} }
} }

@ -1,10 +1,11 @@
Todo: 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 - Fix weird rotational bug when rotation resets or inverts after 180 degrees
- Better, more accurate picking - Better, more accurate picking
- Add editor undo for transformation operations - Add editor undo for transformation operations
- Add material export for blender exporter? - Add material export for blender exporter?
- Remove flickering from selection in editor - Remove flickering from selection in editor
- Fix crash when exiting from fullscreen mode
- Allow renaming scene objects in editor - Allow renaming scene objects in editor
- Check if we still need to rotate by 90 degrees when exporting from blender - 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 - 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 * 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 * 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 * Implment/Test reading/writing scene that has a mixture of default entites and entity archetypes
* Add simple player fps controls * Add simple player fps controls
* Fixed gimbal lock in fps camera by fixing the order of quaternion multiplication when getting absolute rotation
Loading…
Cancel
Save