The question is answered, right answer in comments
Multiplying Quaternion.Euler(0f,0f,0f);
I've been trying to figure out how to add a Quaternion rotation to another one. I found that multiplying quaternions is in actual fact adding them together. But in my code that doesn't work and it also doesn't make sense to me. Since when a quaternion is 0, how could it be multiplied and result in anything else than 0?
Quaternion q1 = Quaternion.Euler(0f,0f,0f);
Quaternion q2 = Quaternion.Euler(0f,10f,0f);
q1 *= q2;
This would always result in q1 still being 0, right? So how would I add 10 degrees to the Y axis in this case?
What I'm trying to do in my code is add q2 to q1 and then set this Quaternion to the rotation of a Transform, then add q2 again etc. Thus incrementing the rotation.
Can anyone shed some light on what I don't understand here?
I don't really understand what you exactly want, but i think you should use q1 = Quaternion.Euler(0f, q1.y + 10f, 0f); This would add 10 degrees to the y-angle everytime you call it
No, no, no ^^ That's completely wrong :) the "y" component of a quaternion doesn't contain an angle. A quaternion doesn't work with eulerangles at all. The static method "Euler" converts eulerangles into a quaternion.
Quaternions are quite complicated. They aren't just some eulerangles. They represent a 4 component complex number. The identity quaternion doesn't have the values 0,0,0,0 as the quaternion is usually a unit quaternion so it always has a length of 1.
You shouldn't be bothered how quaternions work. If you do:
q1 *= q2 // which is the short form of q1 = q1 * q2
You will rotate q1 by q2
http://de.mathworks.com/help/aeroblks/quaternionmultiplication.html
Two things: Quaternion.Euler(0,0,0) isn't an all-zero quaternion -- it creates a Quaternion from angles x=0, y=0, z=0. That Quaternion isn't all zeroes. new Quaternion(0,0,0,0) would be an all-zero quaternion (which I think is just a garbage value.)
But more importantly, *
is just a symbol. For classes and structs, it does nothing until you overload it, and than it does whatever you want it to do. q1*q2
is really calling the function Quaternion.add(q1, q2).
As to why mathematicians use multiply to add them, ins$$anonymous$$d of +, they just felt like it. But, for real, the "add angles" equations involve times and plus, but more times, so they used that symbol for it (I think.)
Uhm, no :) You actually are multiplying the two quaternions together. An addition would be pointless for rotations. The multiplication is called the Hamilton product. Since Quaternions are essentially some sort of complex numbers the product works very similar.
While complex numbers only have one imaginary part, quaternions have three. The special relation between those three imaginary number actually make the product non commutative. Quaternions behave like matrices though are smaller and easier to manage. If you have two rotation matrices you have to multiply them together to get a combined rotation matrix.
So the multiplication of two quaternions has nothing to do with adding. Unity's quaternion struct doesn't even implement an "Add" method as it has no use when dealing with rotations.
Thanks again for your answers, this actually helped me a lot. I finally know how to deal with these things now.