// Token: 0x06002730 RID: 10032 RVA: 0x000B5A1C File Offset: 0x000B3C1C private Quaternion SingleDegree() { Vector3 target = GenericMath.TransformVector(this.axis, this.joint.transform.localRotation); float num; Vector3 rhs; GenericMath.QuaternionToAngleAxis(GenericMath.ApplyQuaternion(GenericMath.RotateFromTo(this.axis, target), this.joint.localRotation), out num, out rhs); float x = this.hingLimit.x; float y = this.hingLimit.y; float num2 = Vector3.Dot(this.axis, rhs); num = GenericMath.Clamp(num * num2, x, y); this.joint.localRotation = GenericMath.QuaternionFromAngleAxis(num, this.axis); return(this.joint.localRotation); }
/// <summary> /// Limit the motion to 1 Degree of freedom /// </summary> /// <param name="_localRot"></param> /// <returns></returns> private Quaternion SingleDegree() { float angle; Vector3 axis; //Hinge only Quaternion Vector3 _localAxis = GenericMath.TransformVector(this.axis, joint.transform.localRotation); Quaternion _delta = GenericMath.RotateFromTo(this.axis, _localAxis); Quaternion _legalRot = GenericMath.ApplyQuaternion(_delta, joint.localRotation); GenericMath.QuaternionToAngleAxis(_legalRot, out angle, out axis); float min = hingLimit.x; float max = hingLimit.y; float dot = Vector3.Dot(this.axis, axis); //clamp values //angle = Mathf.Clamp(angle * dot, min, max); //Unity's Clamp gives NaN values in particular cases so use our own angle = GenericMath.Clamp(angle * dot, min, max); joint.localRotation = GenericMath.QuaternionFromAngleAxis(angle, this.axis); return(joint.localRotation); }
// Token: 0x060034A8 RID: 13480 RVA: 0x000E5E2C File Offset: 0x000E402C public static Quaternion RotateFromTo(Vector3 _source, Vector3 _target) { _source.Normalize(); _target.Normalize(); return(Quaternion.Inverse(GenericMath.QuaternionFromAngleAxis(GenericMath.VectorsAngle(_source, _target), Vector3.Cross(_source, _target).normalized))); }