-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Labels
Description
https://github.com/syoyo/tinyobjloader-c/blob/master/examples/viewer/trackball.c#L177
here you end up doing a asin and then a sin and cos on the result.
However to get a quaternion that rotates from one direction v1 to another v2 you only need to do
float q[4];
vnorm(v1);
vnorm(v2);
q[3] = vdot(v1, v2) +1;
vcross(v1, v2, q);
normalize_quat(q);The plus 1 on the dot product is to get the quaternion representing the half rotation than when you would take just the dot and cross.
On the note of normalize: the magnitude you are dividing with should be the sqrt of the dot product with itself.
You can also opt to not do the normalize of the quaternion (and spare the sqrt) and adjust the matrix generation by dividing each q[...] * q[...] with q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]