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  minbounds,
Vector3  maxbounds 
)
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
minboundsMinimum euler-angle bounds
maxboundsMaximum euler-angle bounds
Returns

Definition at line 64 of file AVR_Utils.cs.

65  {
66  q.x /= q.w;
67  q.y /= q.w;
68  q.z /= q.w;
69  q.w = 1.0f;
70 
71  float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.x);
72  angleX = Mathf.Clamp(angleX, -minbounds.x, maxbounds.x);
73  q.x = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleX);
74 
75  float angleY = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.y);
76  angleY = Mathf.Clamp(angleY, -minbounds.y, maxbounds.y);
77  q.y = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleY);
78 
79  float angleZ = 2.0f * Mathf.Rad2Deg * Mathf.Atan(q.z);
80  angleZ = Mathf.Clamp(angleZ, -minbounds.z, maxbounds.z);
81  q.z = Mathf.Tan(0.5f * Mathf.Deg2Rad * angleZ);
82 
83  return q;
84  }