VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
static Quaternion AVR.Core.Utils.Geom.ClampQuaternionRotation ( Quaternion  q,
Vector3  bounds 
)
inlinestatic

Clamps the rotation to a quaternion to the given euler-angle bounds. Eg ClampQuaternionRotation(q, new Vector3(30, 0, 120)) will clamp q to a min/max rotation of +/- 30 deg around the x Axis etc.

Parameters
qQuaternion to be clamped
boundsEuler-angle bounds. (Will count as both positive and negative.
Returns

Definition at line 35 of file AVR_Utils.cs.

36  {
37  q.x /= q.w;
38  q.y /= q.w;
39  q.z /= q.w;
40  q.w = 1.0f;
41 
42  float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
43  angleX = Mathf.Clamp(angleX, -bounds.x, bounds.x);
44  q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
45 
46  float angleY = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.y);
47  angleY = Mathf.Clamp(angleY, -bounds.y, bounds.y);
48  q.y = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleY);
49 
50  float angleZ = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.z);
51  angleZ = Mathf.Clamp(angleZ, -bounds.z, bounds.z);
52  q.z = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleZ);
53 
54  return q;
55  }