Пример #1
0
 /// <summary>
 /// Sets the value of this axis-angle to the rotational component of
 /// the passed matrix.
 /// </summary>
 /// <remarks>
 /// Sets the value of this axis-angle to the rotational component of
 /// the passed matrix.
 /// If the specified matrix has no rotational component, the value
 /// of this AxisAngle4d is set to an angle of 0 about an axis of (0,1,0).
 /// </remarks>
 /// <param name="m1">the matrix4f</param>
 public void Set(Matrix4f m1)
 {
     Matrix3d m3d = new Matrix3d();
     m1.Get(m3d);
     x = (float)(m3d.m21 - m3d.m12);
     y = (float)(m3d.m02 - m3d.m20);
     z = (float)(m3d.m10 - m3d.m01);
     double mag = x * x + y * y + z * z;
     if (mag > Eps)
     {
         mag = Math.Sqrt(mag);
         double sin = 0.5 * mag;
         double cos = 0.5 * (m3d.m00 + m3d.m11 + m3d.m22 - 1.0);
         angle = (float)Math.Atan2(sin, cos);
         double invMag = 1.0 / mag;
         x = x * invMag;
         y = y * invMag;
         z = z * invMag;
     }
     else
     {
         x = 0.0f;
         y = 1.0f;
         z = 0.0f;
         angle = 0.0f;
     }
 }
Пример #2
0
 /// <summary>
 /// Sets the value of this axis-angle to the rotational component of
 /// the passed matrix.
 /// </summary>
 /// <remarks>
 /// Sets the value of this axis-angle to the rotational component of
 /// the passed matrix.
 /// If the specified matrix has no rotational component, the value
 /// of this AxisAngle4f is set to an angle of 0 about an axis of (0,1,0).
 /// </remarks>
 /// <param name="m1">the matrix4f</param>
 public void Set(Matrix4f m1)
 {
     Matrix3f m3f = new Matrix3f();
     m1.Get(m3f);
     x = m3f.m21 - m3f.m12;
     y = m3f.m02 - m3f.m20;
     z = m3f.m10 - m3f.m01;
     double mag = x * x + y * y + z * z;
     if (mag > Eps)
     {
         mag = Math.Sqrt(mag);
         double sin = 0.5 * mag;
         double cos = 0.5 * (m3f.m00 + m3f.m11 + m3f.m22 - 1.0);
         angle = (float)Math.Atan2(sin, cos);
         double invMag = 1.0 / mag;
         x = (float)(x * invMag);
         y = (float)(y * invMag);
         z = (float)(z * invMag);
     }
     else
     {
         x = 0.0f;
         y = 1.0f;
         z = 0.0f;
         angle = 0.0f;
     }
 }