quaternion: fix init_from_array and get_rotation_axis
In cogl_quaternion_init_from_array we were passing the address of the x component as the destination for memcpy, but that was wrong at least because w is actually the first member in the structure. Another concern raised was whether it was safe to assume that there was no padding within the CoglQuaternion struct with some compilers so we also switch to explicitly indexing each element of the array we want to copy. In practice I think it's pretty safe to assume that padding will only be introduced to ensure members are naturally aligned, but being explicit is readable and it can't hurt to be extra cautious. Another good catch in bug #655228 was that in cogl_quaternion_get_rotation_axis we had a copy and paste error at the end where we finally extract the axis and we were repeatedly calculating just the x component. Now we calculate the y and z components too. Thanks to Bug #655228 for identifying these issues. https://bugzilla.gnome.org/show_bug.cgi?id=655228 Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
parent
565e2cabd8
commit
b8b37f6c41
@ -121,7 +121,10 @@ void
|
|||||||
cogl_quaternion_init_from_array (CoglQuaternion *quaternion,
|
cogl_quaternion_init_from_array (CoglQuaternion *quaternion,
|
||||||
const float *array)
|
const float *array)
|
||||||
{
|
{
|
||||||
memcpy (&quaternion->x, array, sizeof (float) * 4);
|
quaternion->w = array[0];
|
||||||
|
quaternion->x = array[1];
|
||||||
|
quaternion->y = array[2];
|
||||||
|
quaternion->z = array[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -389,8 +392,8 @@ cogl_quaternion_get_rotation_axis (const CoglQuaternion *quaternion,
|
|||||||
one_over_sin_angle_over_2 = 1.0f / sqrtf (sin_half_angle_sqr);
|
one_over_sin_angle_over_2 = 1.0f / sqrtf (sin_half_angle_sqr);
|
||||||
|
|
||||||
vector->x = quaternion->x * one_over_sin_angle_over_2;
|
vector->x = quaternion->x * one_over_sin_angle_over_2;
|
||||||
vector->x = quaternion->x * one_over_sin_angle_over_2;
|
vector->y = quaternion->y * one_over_sin_angle_over_2;
|
||||||
vector->x = quaternion->x * one_over_sin_angle_over_2;
|
vector->z = quaternion->z * one_over_sin_angle_over_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user