How do I rotate a Quaternion with 2nd Quaternion on its local or world axes without using transform.Rotate?

Ruzihm

Transform.Rotate has a very helpful interface for selecting whether or not a rotation should be made relative to world axes or the local axes.

Behind the scenes, it's doing some math to the transform's rotation, a Quaternion, with another Quaternion. And the exact nature of this math changes depending on if you choose the local or world flag.

How can I do this sort of math without assigning the first Quaternion to a Transform's rotation (wasting memory and/or time) just to do some math with it?

Suppose my first Quaternion is Quaternion q1 = Quaternion.Euler(0f,0f,90f); and the second is Quaternion q2 = Quaternion.Euler(90f,0f,0f).

Applying the second to the first along its local axes would give a rotation that rotates its right side to face down and its front to face right.

Applying the second to the first along the original axes would give a rotation that rotates its back to face down and its top to face right.

Ruzihm

Use the Quaternion operator *.

In Unity, when you multiply two quaternions, it applies the second quaternion (expressed in global axes) to the first quaternion along the local axes produced after the first Quaternion).

So, if you want to do the equivalent of Rotate(q2, Space.Self), where q1 is the transform's original rotation, and q3 is the transform's new rotation, you want Quaternion q3 = q1 * q2.


What do you do if you want to apply q2 to q1 along the axes before q1 applies (i.e., along the global axes)? Well, it turns out that is equivalent to applying q1 along the local axes of q2.

As an example, applying q2 along the global axes of q1 rotates its back to face down and its top to face right. Consider that that applying q1 along the local axes of p2 also rotates its back to face down and its top to face right. They result in the same orientation!

So what does that mean? If you want to apply q2 to q1 along the axes before q1 applies, then do Quaternion q3 = q2 * q1.

This is the equivalent of doing Rotate(q2, Space.World) where q1 is the transform's original rotation, and q3 is the new rotation.


Unlike Rotate, you can use this operator to rotate an object relative to its parent's axes! If you do transform.localRotation = q2 * transform.localRotation, you will be rotating the object relative to the axis of the parent.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How can I convert a Quaternion to an angle?

分類Dev

How to write vertical text from bottom to top without using transform rotate?

分類Dev

How to write vertical text from bottom to top without using transform rotate?

分類Dev

How to write vertical text from bottom to top without using transform rotate?

分類Dev

How do I get my canvas image to rotate 90 degrees each time, its only rotating 180 degrees

分類Dev

CSS transform and rotate with animation

分類Dev

How to rotate 4 children within a circle 90 degrees every 3 seconds using CSS custom properties and transform?

分類Dev

How do I groupby with one key column, using condition on 2nd column and adding third column separately for weekday and weekend?

分類Dev

How to rotate material icon in flutter without animation?

分類Dev

How to stop an image returning to its starting point using CSS3 rotate3d

分類Dev

vueJS transform rotate style inline

分類Dev

I want to rotate image which is generated from its thumbnail

分類Dev

I do not understand how the 2nd loop has O(i^2)?

分類Dev

How to rotate logs in laravel using logrotate?

分類Dev

How to rotate an arc in canvas using context?

分類Dev

How to Rotate a GameObject around its center, from script?

分類Dev

How to rotate a TextView in a ConstraintLayout along with its constraint bounds

分類Dev

How to rotate a Line or an image from its bottom to 180 degree

分類Dev

Rotate when already using an animation to rotate?

分類Dev

How can I access a shared folder from R on Ubuntu to a 2nd Ubuntu machine using Samba?

分類Dev

How to rotate a 2D line in PyOpenGL?

分類Dev

How to rotate Cubemap face without memory copy in OpenGL?

分類Dev

How to rotate in R?

分類Dev

How to rotate desktop background?

分類Dev

transform: rotate is creating unwanted white space

分類Dev

style.transform = "rotate()"を複数回?

分類Dev

`player.animate([{transform:" rotate(10) "`?

分類Dev

How do you rotate (circular shift) of a Scala collection

分類Dev

How to rotate image using glide library? (Like in picasso)

Related 関連記事

  1. 1

    How can I convert a Quaternion to an angle?

  2. 2

    How to write vertical text from bottom to top without using transform rotate?

  3. 3

    How to write vertical text from bottom to top without using transform rotate?

  4. 4

    How to write vertical text from bottom to top without using transform rotate?

  5. 5

    How do I get my canvas image to rotate 90 degrees each time, its only rotating 180 degrees

  6. 6

    CSS transform and rotate with animation

  7. 7

    How to rotate 4 children within a circle 90 degrees every 3 seconds using CSS custom properties and transform?

  8. 8

    How do I groupby with one key column, using condition on 2nd column and adding third column separately for weekday and weekend?

  9. 9

    How to rotate material icon in flutter without animation?

  10. 10

    How to stop an image returning to its starting point using CSS3 rotate3d

  11. 11

    vueJS transform rotate style inline

  12. 12

    I want to rotate image which is generated from its thumbnail

  13. 13

    I do not understand how the 2nd loop has O(i^2)?

  14. 14

    How to rotate logs in laravel using logrotate?

  15. 15

    How to rotate an arc in canvas using context?

  16. 16

    How to Rotate a GameObject around its center, from script?

  17. 17

    How to rotate a TextView in a ConstraintLayout along with its constraint bounds

  18. 18

    How to rotate a Line or an image from its bottom to 180 degree

  19. 19

    Rotate when already using an animation to rotate?

  20. 20

    How can I access a shared folder from R on Ubuntu to a 2nd Ubuntu machine using Samba?

  21. 21

    How to rotate a 2D line in PyOpenGL?

  22. 22

    How to rotate Cubemap face without memory copy in OpenGL?

  23. 23

    How to rotate in R?

  24. 24

    How to rotate desktop background?

  25. 25

    transform: rotate is creating unwanted white space

  26. 26

    style.transform = "rotate()"を複数回?

  27. 27

    `player.animate([{transform:" rotate(10) "`?

  28. 28

    How do you rotate (circular shift) of a Scala collection

  29. 29

    How to rotate image using glide library? (Like in picasso)

ホットタグ

アーカイブ