码迷,mamicode.com
首页 > 编程语言 > 详细

【unity2D】API-学习记录12-四元数类Quaternion

时间:2021-05-24 08:25:35      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:情况下   返回   使用   expect   table   ons   numbers   ever   function   

目标

了解并能够应用某些方法来旋转物体


API对Quaternion的(部分)说明

Quaternion

Description
描述
Quaternions are used to represent rotations.
四元数用于表示旋转。

They are compact, don‘t suffer from gimbal lock and can easily be interpolated.
它们结构紧凑,不受万向锁影响,可以轻松插值。

Unity internally uses Quaternions to represent all rotations.
 Unity 内部使用四元数来表示所有旋转。
 
 
They are based on complex numbers and are not easy to understand intuitively. 
它们基于复数,不容易理解。

You almost never access or modify individual Quaternion components (x,y,z,w); 
您几乎不会有机会访问或修改单个四元数分量(x、y、z、w);
 
 most often you would just take existing rotations (e.g. from the Transform)
大多数情况下,您只需要获取现有旋转(例如,来自 Transform),
  
and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). 
然后使用它们构造新的旋转 (例如,在两个旋转之间平滑插值)。
  
The Quaternion functions that you use 99% of the time are: Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity.
您绝大多数时间使用的四元数函数为: Quaternion.LookRotation、Quaternion.Angle、Quaternion.Euler、Quaternion.Slerp、Quaternion.FromToRotation 和 Quaternion.identity。

(The other functions are only for exotic uses.)
(其他函数仅用于一些十分奇特的用例。)

Note that Unity expects Quaternions to be normalized.
注意,Unity 使用的是标准化的四元数。

API中列举了在绝大多数时候使用到的四元数方法,下面来总结它们的用法。


常用的四元数方法

方法 函数原型 函数解释
Euler public static Quaternion Euler (float x, float y, float z); 返回一个旋转,它分别绕 z、x、y轴旋转 z、x、y 度(按该顺序应用)
Angle public static float Angle(Quaternion a, Quaternion b); 返回两个旋转之间的角度(以度为单位)。
FromToRotation public static Quaternion FromToRotation (Vector3 fromDirection, Vector3 toDirection); 创建一个从 fromDirection 旋转到 toDirection 的旋转。通常情况下,使用该方法对Transform进行旋转,使其的一个轴(例如 Y 轴)跟随世界空间中的目标方向
LookRotation public static Quaternion LookRotation (Vector3 forward, Vector3 upwards= Vector3.up); 使用指定的 forward 和 upwards 方向创建旋转。Z 轴将与forward对齐,X 轴与 forward 和 upwards 之间的差积对齐,Y 轴与 Z 和 X 之间的差积对齐。如果 forward 或 upwards 量值为零 或 forward 和 upwards 共线,则返回恒等。

做2D游戏的旋转,上表中的前三个方法用得比较多,尤其是Euler,非常省事。

做3D游戏用得到第四个方法。

【unity2D】API-学习记录12-四元数类Quaternion

标签:情况下   返回   使用   expect   table   ons   numbers   ever   function   

原文地址:https://www.cnblogs.com/OtusScops/p/14758413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!