Open ratchetfreak opened 8 years ago
trackball.c is grabbed from famous and legacy OpenGL example code, and I'm just using it. Its just working so I have no strong reason to improve it.
Also I have no strong reason to stick to using trackball.c once there is a cleaner & recent good implementation of trackball functionality.
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 anotherv2
you only need to doThe 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[...]
withq[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]