3 ms·
TL;DR: don't read this article, it is amazingly bad. Avoid trig. Look up "arcball interface"[0]. ------------------------------------------------------- Stron
by romwell 7y ago
TL;DR: don't read this article, it is amazingly bad. Avoid trig. Look up "arcball interface"[0].
-------------------------------------------------------
Strong opinion from a math PhD/SWE:
You'll be better off not reading this at all than learning about the subject from this page. You'll have to un-learn it afterwards.
Most importantly, whatever you do, please NEVER write a 3D rotation function and UI this way. It is horrible for many reasons I won't go into here. DO write and use the so-called arcball interaface. Here's an implementation you can play with in a browser[0]. Try it now!
The article is is amazingly bad: not only it is not the right way to think about rotations, it's also bad computationally, features bad code, and nothing is said of the right way to do these things (i.e. how it's actually done by anyone who deals with it).
It also features some "magic math", i.e. unexplained trig formulas. Feel confused? You should be, unless you know this stuff already!
Rotations aren'ta reason to learn trigonometry; if anything, it's a reason to avoid trig. In fact, you should avoid trig when you can. (People smarter than me say so too[1]).
Here are the subjects one need to learn to actually deal with rotations:
* Linear algebra. Rotations are orthogonal transformations. And by using projective coordinates, translations are linear maps. OpenGL stack is all about 4 x 4 matrices!
* Complex analysis and quaternions. All complex number are is rotations & scaling in 2D (the sqrt(-1) stuff is not even necessary to define them). Quaternions generalize complex numbers, and provide an efficent way to interpolate rotations in 3D. Again, see[0].
* Lean about Euler Angles so that you know to not use them.
As a bonus, the unexplained trig identities (like the formula for sin(a+b)) come off naturally from either matrices or complex numbers.
Note that this is not all there is to it; I still used trigonometry in that example. This is altogether not necessary, see Inigo Quilez's article [1].
Most importantly, understand that the operation "rotate an object so that it points in that direction" doesn't require neither angles nor trigonometry. You just need a way to encode the direction (as a vector, quaternion, etc).
[0]http://romankogan.net/math/arcball_js/index.html http://romankogan.net/math/arcball_js/index.html
[1]http://www.iquilezles.org/www/articles/noacos/noacos.htm http://www.iquilezles.org/www/articles/noacos/noacos.htm
- ghusbands 7y agoYou're pushing arcball really quite hard across this discussion, but it's just one of many ways of handling interactive rotation of an object, and the one used in the article (give or take accumulating inaccuracy) is fairly normal, too. Certainly, though, the article will not really help anyone aspiring to write a 3d engine of most any kind.
- cookingrobot 7y agoArcball has some kind of gimbal lock - if you drag far enough it stops rotating. Maybe there's a reason for that, but it feels wrong.