/// <summary> /// Sets the value of this quaternion to one that represents rotation by given angle around Z-axis. /// </summary> /// <param name="r">Angle of rotation in radians.</param> public void SetRotationAroundZ(float r) { float s, c; MathHelpers.SinCos(r * 0.5f, out s, out c); this.W = c; this.V.X = 0; this.V.Y = 0; this.V.Z = s; }
/// <summary> /// Sets value of this quaternion to value that represents rotation to given vector from /// <see cref="Vector3.Up" />(?) vector. /// </summary> /// <param name="vdir"> /// <see cref="Vector3" /> that represents direction to which we need to find a rotation. /// </param> /// <param name="r">Angle of rotation around forward axis to apply to new quaternion.</param> /// <seealso cref="Quaternion.SetRotationToViewDirection(Vector3)"/> public void SetRotationToViewDirection(Vector3 vdir, float r) { this.SetRotationToViewDirection(vdir); float sy, cy; MathHelpers.SinCos(r * 0.5f, out sy, out cy); float vx = this.V.X, vy = this.V.Y; this.V.X = vx * cy - this.V.Z * sy; this.V.Y = this.W * sy + vy * cy; this.V.Z = this.V.Z * cy + vx * sy; this.W = this.W * cy - vy * sy; }
/// <summary> /// Sets this matrix to represent rotation around fixed Axes. /// </summary> /// <param name="rad"><see cref="EulerAngles"/> that defines rotations around XYZ.</param> public void SetRotationFromAngles(EulerAngles rad) { double sx, cx; MathHelpers.SinCos(rad.Pitch, out sx, out cx); double sy, cy; MathHelpers.SinCos(rad.Roll, out sy, out cy); double sz, cz; MathHelpers.SinCos(rad.Yaw, out sz, out cz); double sycz = (sy * cz), sysz = (sy * sz); this.M00 = (float)(cy * cz); this.M01 = (float)(sycz * sx - cx * sz); this.M02 = (float)(sycz * cx + sx * sz); this.M10 = (float)(cy * sz); this.M11 = (float)(sysz * sx + cx * cz); this.M12 = (float)(sysz * cx - sx * cz); this.M20 = (float)(-sy); this.M21 = (float)(cy * sx); this.M22 = (float)(cy * cx); }
/// <summary> /// Sets the value of this quaternion to one that represents rotation defined by Euler angles. /// </summary> /// <param name="angle"><see cref="Vector3" /> that defines Euler angles.</param> public void SetRotationAroundXYZAxes(Vector3 angle) { float sx; float cx; MathHelpers.SinCos(angle.X * 0.5f, out sx, out cx); float sy; float cy; MathHelpers.SinCos(angle.Y * 0.5f, out sy, out cy); float sz; float cz; MathHelpers.SinCos(angle.Z * 0.5f, out sz, out cz); this.W = cx * cy * cz + sx * sy * sz; this.V.X = cz * cy * sx - sz * sy * cx; this.V.Y = cz * sy * cx + sz * cy * sx; this.V.Z = sz * cy * cx - cz * sy * sx; }