3 ms·
Hey, I did a write-up (and implementation, in ProcessingJS) of quaternion multiplication for Arcball interface (aka spinning 3D objects around with mouse). You
by romwell 8y ago
Hey, I did a write-up (and implementation, in ProcessingJS) of quaternion multiplication for Arcball interface (aka spinning 3D objects around with mouse).
You can play with the implementation at [1] and see the source (and maths explained!) at [2].
Quick summary:
1. Quaternion (cos(a), sin(a) u)--> rotation about the axis u by angle 2a (u is a unit vector in R^3)
2. (x,u) * (y,v) = (xy - u . v, xv + yu + u X v),
where . stands for the dot product, and X stands for the vector cross product.
If you look at the source, you can see that I was lazy and used trig / inverse trig. However, once you grasp how it works, it is not hard to improve this code according to the article.
The article is good once you know how quaternions work; my write-up aims to explain that. If the article scared you away, check [1] out - hope it helps!
The code is Java-like, so should be readable, and has plenty of comments.
[1]http://www.math.tamu.edu/~romwell/arcball_js/index.html http://www.math.tamu.edu/~romwell/arcball_js/index.html
[2]http://www.math.tamu.edu/~romwell/arcball_js/arcball.pde http://www.math.tamu.edu/~romwell/arcball_js/arcball.pde