个人笔记,来源unity官网教程
3D图形数学?点乘,欧拉角,四元数;
查手册查手册
Quaternion 手册描述
Project包含数个Tutorial
Tutorial —— Quaternions and Euler angles
Well, For starters, Quaternions are just how just Unity handles rotations. It’s a very effective way for rotations to occur in game development.(这是一个非常有效的旋转方式发生在游戏开发中。)It’s nothing to be afraid of , just know it’s how Unity handle rotations.
(草,真是体贴人意a,四元数什么的听起来就很难的样子,作者很贴心的说别怕2333)
These degrees, along the specific axis is the Euler Angle. (所以意思是,在这里设置的角度就都是欧拉角了)
What happening underneath the hood is that Unity is using Quaternions to handle the rotation and they’re representing it to us in an Euler Angle fashion because it’s just more readable. (原来如此吗,一个主外一个主内233)
Quaternions have an x, y, z and w rotation. But, because we are not really comfortable or familiar with the w rotation, Unity converts it to Euler Angles to be more readable.(w什么鬼
Now, with Quaternions it’s recommended that you always handle your rotations through Quaternions. You should never modify rotations using the Euler Angles and the reason of that is because of something called a Gimbal lock(万向锁).
Gimbal lock is the loss of one degree of freedom in a three dimensional 3 Gimbal mechanism.(万向节锁是在三维3万向节机构中失去一个自由度,,,说人话好吗)
That means that there are occasions where your y Euler Angle and your z Euler Angle may align and it will break the rotation.
(这意味着,在某些情况下,y Euler角和z Euler角可能对齐, waht?为什么会这样?)
To avoid gimbal lock we use Quaternions and then Unity will represent that Quaternion as an Euler Angle to you so that you can make sense of it.(emm
Tutorial——Quaternion Identity
And then typically what you’ll see here is when we instantiate an object, oftentimes we’ll type Quaternion.identity. And what this means is no rotation.
如果想要旋转角度的话
And if we look at the definition for Euler, it’s going to return a rotation
**
Tutorial——Quaternion Look Rotation
**
作用:we can specify one object to target or look at another object.
要让物体朝向另一个物体,需要一个方向,方向的公式就是direction = destination - source 目标物体的位置减我们的位置,返回值为Vector3
目标位置要如何取得,In order to get the sphere, i need a reference to it. So i’m going to create a variable type(变量) , Transform ,
to store the reference to that sphere. Using a serialized filed attribute, i can then assign it in the inspector.
然后把物体拖进来就行
access(访问) out current rotation. We assign(分配) it to the Quaternion look rotation method.
注释部分也叫pseudo code(伪代码),,Open parentheses(打开括号。。就是指看方法的重载) 填入方法参数叫pass in
**
Tutorial——Quaternion Slerp
**
Now Slerp is the equivalent of linear interpolation(线性插值等价), but spherically. And what that means that instead of just snapping to our target, If we use slerp with LookRotation , it would allow us to basically control going from point A to point B. So basically it would be able to smoothly , spherically interpolate between the current rotation to the target rotation. (就是让转动变得丝滑~)(不过为什么叫interpolate
第一步: We’re going to store this Look Rotation ,in a Quaternion variable.
第二步: Set it equal to Quaternion .slerp
第三 : current rotation=transform.rotation & target rotation=Look Rotation=direction to face.
所以说,方向终点minus起点得到一个Vector3 值,将这个 Vector3 代入Quaternion.LookRotation()再返回一个rotation
ps:文档对于LookRotation的描述:Creates a rotation with the specified forward and upwards directions.
而且 Quaternion are use to represent rotations
不用猜了,查文档,果然rotation就是四元数
结束