public IFragment[] Process(ITriangle triangle)
 {
     IVertexOutputData[] clips   = triangle.points;
     Vector2[]           screens = Array.ConvertAll <IVertexOutputData, Vector2>(
         clips,
         (IVertexOutputData each) => new Vector2((each.clip.x / each.clip.w * 0.5f + 0.5f) * screenWidth, (each.clip.y / each.clip.w * 0.5f + 0.5f) * screenHeight)
         );
     int[][] iscreens = Array.ConvertAll <Vector2, int[]>(
         screens,
         (Vector2 each) => new int[] { MathS.Clamp((int)each.x, 0, mScreenWidth - 1), MathS.Clamp((int)each.y, 0, mScreenHeight - 1) }
         );
     int[][] pixels = scan.ConvexFill(iscreens);
     if (pixels != null)
     {
         IVertexOutputData[] v2fs = Array.ConvertAll <int[], IVertexOutputData>(
             pixels,
             (int[] each) => gour.Triangle(clips, screens, each)
             );
         IFragment[] frags = new Fragment[v2fs.Length];
         for (int pIndex = 0; pIndex < v2fs.Length; pIndex++)
         {
             IFragment frag = new Fragment();
             frag.pixel    = pixels[pIndex];
             frag.color    = fragShade.Process(v2fs[pIndex]);
             frags[pIndex] = frag;
         }
         return(frags);
     }
     return(null);
 }
Exemple #2
0
    /// <summary>
    /// 球面插值
    /// </summary>
    /// <param name="q1">单位四元数</param>
    /// <param name="q2">单位四元数</param>
    /// <param name="t">0--1</param>
    /// <returns>单位四元数</returns>
    public static Quaternion Slerp(Quaternion q1, Quaternion q2, float t)
    {
        Quaternion uq = q1;

        t = MathS.Clamp(t, 0, 1);
        float dot = Quaternion.Dot(q1, q2);

        if ((1 - dot) > Threshold)
        {
            float radian = MathS.Acos(dot);
            if (radian < 0)
            {
                radian = MathS.PI - radian;
            }
            float sin = MathS.Sin(radian);
            float t1  = MathS.Sin((1 - t) * radian) / sin;
            float t2  = MathS.Sin(t * radian) / sin;
            uq = q1 * t1 + q2 * t2;
        }
        return(uq);
    }
Exemple #3
0
 public static Vector2 Lerp(Vector2 from, Vector2 to, float t)
 {
     t = MathS.Clamp(t, 0, 1);
     return((1 - t) * from + t * to);
 }
Exemple #4
0
 /// <summary>
 /// 线性插值
 /// </summary>
 /// <param name="q1"></param>
 /// <param name="q2"></param>
 /// <param name="t"></param>
 /// <returns></returns>
 public static Quaternion Lerp(Quaternion q1, Quaternion q2, float t)
 {
     t = MathS.Clamp(t, 0, 1);
     return(q1 * (1 - t) + q2 * t);
 }