Exemple #1
0
    // http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html#sunbresenhamarticle
    private static void fillBottomFlatTriangle(MUVVertex v1, MUVVertex v2, MUVVertex v3, Texture2D texture)
    {
        Debug.Log ("fillBottomFlatTriangle " + v1.ToString()+ v2.ToString()+v3.ToString());

        float width = (float)texture.width;

        float invslope1 = (v2.UV.x - v1.UV.x) / (v2.UV.y - v1.UV.y);
        float invslope2 = (v3.UV.x - v1.UV.x) / (v3.UV.y - v1.UV.y);

        float curx1 = v1.UV.x;
        float curx2 = v1.UV.x;

        for (float scanlineY = v1.UV.y; scanlineY <= v2.UV.y; scanlineY++)
        {
            DrawScanline(new Vector2(curx1 * width, scanlineY* width), new Vector2( curx2* width, scanlineY* width), texture);
            curx1 += invslope1;
            curx2 += invslope2;
        }
    }
Exemple #2
0
    // http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html#sunbresenhamarticle
    private static void fillTopFlatTriangle(MUVVertex v1, MUVVertex v2, MUVVertex v3, Texture2D texture)
    {
        float width = (float)texture.width;

        float invslope1 = (v3.UV.x - v1.UV.x) / (v3.UV.y - v1.UV.y);
        float invslope2 = (v3.UV.x - v2.UV.x) / (v3.UV.y - v2.UV.y);

        float curx1 = v3.UV.x;
        float curx2 = v3.UV.x;

        for (int scanlineY = (int)v3.UV.y; scanlineY > (int)v1.UV.y; scanlineY--)
        {
            curx1 -= invslope1;
            curx2 -= invslope2;
            DrawScanline(new Vector2(curx1* width, scanlineY* width), new Vector2( curx2* width, scanlineY* width), texture);
        }
    }
Exemple #3
0
 public MVertex(Vector3 position, Vector3 normal, Vector3 uv)
 {
     this.position = position;
     this.normal = normal;
     this.uv = new MUVVertex(new Vector2(uv.x,uv.y));
     this.parents = new List<MTriangle>();
 }
Exemple #4
0
 private void AddEdge(MUVVertex from, MUVVertex to)
 {
     MUVEdge edge = new MUVEdge(from,to);
     if (parent.UVEdges.Contains(edge))
     {
         int index = parent.UVEdges.IndexOf(edge);
         if (parent.UVEdges[index].Parents.Contains(this) == false) parent.UVEdges[index].Parents.Add(this);
         this.edges.Add(edge);
     }
     else
     {
         edge.Parents.Add(this);
         this.edges.Add(edge);
         parent.UVEdges.Add(edge);
     }
 }
Exemple #5
0
 public bool Contains(MUVVertex uvVertex)
 {
     if (from == uvVertex || to == uvVertex)
         return true;
     else
         return false;
 }
Exemple #6
0
        public MUVEdge(MUVVertex from, MUVVertex to)
        {
            this.from = from;
            this.to = to;

            this.parents = new List<MUVTriangle>();
        }