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
  • 1
    \$\begingroup\$ Have you tried reversing the order of multiplication of the quaternions in your second example? \$\endgroup\$
    – DMGregory
    Commented Feb 22, 2019 at 22:37

1 Answer 1

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\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .