0
\$\begingroup\$

If was trying to set the correct position of my sun billboard in my 3d game. I tried long until it worked correctly, but I wonder why this code must be so complicated:

sun.sprite.Position = Vector3.Transform(Vector3.Transform(-sun.lightDir, 
Quaternion.Inverse(world.Rotation)), Quaternion.Inverse(myRelativeRotation));

Can I simplify this expression? I tried changing it at least to this:

sun.sprite.Position = Vector3.Transform(-sun.lightDir,
Quaternion.Inverse(world.Rotation) * Quaternion.Inverse(myRelativeRotation)) 

But this is giving me different results, so the sun is at the wrong position.

\$\endgroup\$
  • 1
    \$\begingroup\$ Have you tried reversing the order of multiplication of the quaternions in your second example? \$\endgroup\$ – DMGregory Feb 22 at 22:37
0
\$\begingroup\$

In the end I found a solution and made it even simpler:

sun.sprite.Position = Vector3.Transform(-sun.lightDir, 
    Quaternion.Inverse(myRelativeRotation * world.Rotation));

Because according to this explanation is:

A^-1 * B^-1 = (B * A)^-1
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.