1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 |
/* * parentQuate:需要变换的对像 * angleX,angleY,angleZ: 旋转哪个方向 * angle:需要旋转的角度 0~360 */ static
public Quaternion ChangeRotation(GameObject parnetQuate, float
angleX, float
angleY, float
angleZ, float
angle, bool
IsAnimation, float
duration) { Quaternion ans = Quaternion.identity; if ( parnetQuate == null
) return
ans; float
norm; float
ccc, sss; angle *= 3.14f / 180.0f; ans.w = ans.x = ans.y = ans.z = 0.0f; norm = angleX * angleX + angleY * angleY + angleZ * angleZ; if (norm <= 0.0f) { if ( IsAnimation) TweenRotation.Begin(parnetQuate,duration,ans); return
ans; } norm = 1.0f / Mathf.Sqrt(norm); angleX *= norm; angleY *= norm; angleZ *= norm; ccc = Mathf.Cos(0.5f * angle); sss = Mathf.Sin(0.5f * angle); ans.w = ccc; ans.x = sss * angleX; ans.y = sss * angleY; ans.z = sss * angleZ; if ( IsAnimation) TweenRotation.Begin(parnetQuate,duration,ans); return
ans; } |
原文:http://www.cnblogs.com/chenan/p/3547668.html