Fixed quat to yaw, pitch and roll functions and rotation arc not matching up to actual rotation

dev
Shariq Shah 6 years ago
parent 01746870da
commit bd90620bdf
  1. 25
      src/common/linmath.c
  2. 5
      todo.txt

@ -802,23 +802,32 @@ void quat_get_right(vec3* res, const quat* q)
float quat_get_pitch(const quat* q) float quat_get_pitch(const quat* q)
{ {
float check = 2.0f * (-q->y * q->z + q->w * q->x); float check = 2.0f * (-q->y * q->z + q->w * q->x);
if(check < -0.995f || check > 0.995f) if(check < -0.995f)
return 0.f; return -90.f;
else if(check > 0.995)
return 90.f;
else else
return TO_DEGREES(atan2f(2.f * (q->x * q->z + q->w * q->y), 1.f - 2.f * (q->x * q->x + q->y * q->y))); return TO_DEGREES(asinf(check));
//return TO_DEGREES(atan2f(2.f * (q->y * q->z + q->w * q->x), q->w * q->w - q->x * q->x - q->y * q->y + q->z * q->z));
} }
float quat_get_yaw(const quat* q) float quat_get_yaw(const quat* q)
{ {
float result = (float)asin(-2 * (q->x * q->z - q->w * q->y)); float check = 2.0f * (-q->y * q->z + q->w * q->x);
return TO_DEGREES(result); if(check > 0.995f || check < -0.995f)
return 0.f;
else
return TO_DEGREES(atan2f(2.0f * (q->x * q->z + q->w * q->y), 1.0f - 2.0f * (q->x * q->x + q->y * q->y)));
} }
float quat_get_roll(const quat* q) float quat_get_roll(const quat* q)
{ {
float result = atan2(2 * (q->x * q->y + q->w * q->z), q->w * q->w + q->x * q->x - q->y * q->y - q->z * q->z); float check = 2.0f * (-q->y * q->z + q->w * q->x);
return TO_DEGREES(result); if(check < -0.955f)
return TO_DEGREES(-atan2f(2.0f * (q->x * q->z - q->w * q->y), 1.0f - 2.0f * (q->y * q->y + q->z * q->z)));
else if(check > 0.995f)
return TO_DEGREES(atan2f(2.0f * (q->x * q->z - q->w * q->y), 1.0f - 2.0f * (q->y * q->y + q->z * q->z)));
else
return TO_DEGREES(atan2f(2.0f * (q->x * q->y + q->w * q->z), 1.0f - 2.0f * (q->x * q->x + q->z * q->z)));
} }
void quat_mul_mat4(quat* res, quat* val, mat4* mat) void quat_mul_mat4(quat* res, quat* val, mat4* mat)

@ -98,8 +98,7 @@ Bugs:
- Investigate memory usage increase when window is minimized - Investigate memory usage increase when window is minimized
- Fix hang on fullscreen toggle - Fix hang on fullscreen toggle
- Fix axis lines not aligning with grid lines - Fix axis lines not aligning with grid lines
- Fix rotation arc starting and ending degree calculations - Fix arc angles resetting when rotating
- Fix broken spot light degree/radian conversions
Done: Done:
* Input * Input
@ -285,4 +284,6 @@ Done:
* Highlight if we are about to select an entity or perform the tool action like translate when mouse is hovered and an entity can be selected at that location * Highlight if we are about to select an entity or perform the tool action like translate when mouse is hovered and an entity can be selected at that location
* Display the projected position if we perform the action for example display what the new location would be right next to the tool mesh * Display the projected position if we perform the action for example display what the new location would be right next to the tool mesh
* Tooltips for current action or hovered entity * Tooltips for current action or hovered entity
* Fix broken spot light degree/radian conversions
* Fix rotation arc starting and ending degree calculations

Loading…
Cancel
Save