Example #1
0
        public quat(AxisAngle aa)
        {
            angle half = aa.angle * 0.5f;

            vec = aa.axis * half.Sin;
            w   = half.Cos;
            normalize();
        }
Example #2
0
        public quat rotation(vec2 from, vec2 to)
        {
            vec3  f     = transform(from);
            vec3  t     = transform(to);
            vec3  axis  = vec3.cross(f, t).Normalized;
            angle angle = vec3.AngleBetween(f, t);

            return(new quat(AxisAngle.RightHandAround(axis, angle)));
        }
Example #3
0
        public static quat Slerp(quat a, float v, quat b)
        {
            float d = dot(a, b);

            if (d > 0.9995f)
            {
                return(lerp(a, v, b));
            }
            d = math1.Within(-1, d, 1);
            angle theta0 = angle.Acos(d);
            angle theta  = theta0 * v;

            quat q = (b - a * d).Normalized;

            return(a * theta.Cos + q * theta.Sin);/*
                                                   * float cosOmega = a.x * b.x +
                                                   * a.y * b.y +
                                                   * a.z * b.z +
                                                   * a.w * b.w;
                                                   *
                                                   * float sign = (cosOmega < 0.0f) ? (-1.0f) : (1.0f);
                                                   * cosOmega *= sign;
                                                   *
                                                   * float scaleFrom;
                                                   * float scaleTo;
                                                   * const float DELTA = 0.0001f;
                                                   * if ((1.0f - cosOmega) > DELTA)
                                                   * {
                                                   * // regular slerp
                                                   * angle omega = angle.Acos(cosOmega);
                                                   * float sinOmega = omega.Sin;
                                                   * scaleFrom = (float)Math.Sin((1.0f - v) * omega.inRadians) / sinOmega;
                                                   * scaleTo = (float)Math.Sin(v * omega.inRadians) / sinOmega;
                                                   * }
                                                   * else
                                                   * {
                                                   * // from and to are close, do a linear interpolation to speed things up a little
                                                   * scaleFrom = 1.0f - v;
                                                   * scaleTo = v;
                                                   * }
                                                   * scaleTo *= sign;
                                                   *
                                                   * return new quat(
                                                   * scaleFrom * a.w + scaleTo * b.w, new vec3(
                                                   * scaleFrom * a.x + scaleTo * b.x,
                                                   * scaleFrom * a.y + scaleTo * b.y,
                                                   * scaleFrom * a.z + scaleTo * b.z));*/
        }
Example #4
0
 private AxisAngle(vec3 axis, angle angle)
 {
     this.axis  = axis;
     this.angle = angle;
 }
Example #5
0
 public static AxisAngle RightHandAround(vec3 axis, angle angle)
 {
     return(new AxisAngle(axis, angle));
 }