コード例 #1
0
    virtual public bool LineTo(float x, float y, FDrawingCursor previousCursor)
    {
        //Main line (no caps, caps are drawn on Flush, MoveTo)
        FDrawingQuad quad;

        quad = new FDrawingQuad(color);
        if (!quad.SetLineVertices(position, new Vector2(x, y), thickness, this))
        {
            return(false);
        }
        AddLineSideBorders(quad, quad);
        _quads.AddLast(quad);
        lineQuad = quad;

        lineFromValid    = true;
        lineFromPosition = position;
        position.x       = x;
        position.y       = y;

        if (previousCursor != null)
        {
            DrawJoint(previousCursor);
        }
        return(true);
    }
コード例 #2
0
    virtual public void MoveTo(float x, float y, FDrawingCursor firstCursor)
    {
        Flush(firstCursor);

        position.x = x;
        position.y = y;
    }
コード例 #3
0
 public void Copy(FDrawingCursor model)
 {
     _quads           = model.GetQuads();
     lineFromValid    = model.lineFromValid;
     thickness        = model.thickness;
     jointType        = model.jointType;
     capType          = model.capType;
     color            = model.color;
     position         = model.position;
     lineFromPosition = model.lineFromPosition;
     direction        = model.direction;
     //topQuad=model.topQuad;
     //bottomQuad=model.bottomQuad;
     lineQuad = model.lineQuad;
     if (model.borders != null)
     {
         borders = new List <FDrawingBorder>(model.borders.Count);
         int n = model.borders.Count;
         for (int i = 0; i < n; i++)
         {
             FDrawingBorder border = model.borders[i];
             borders.Add(border.Clone());
         }
     }
     else
     {
         borders = null;
     }
 }
コード例 #4
0
 virtual public void Flush(FDrawingCursor firstCursor)
 {
     if (lineFromValid)
     {
         DrawEndCap();
     }
     if (firstCursor != null)
     {
         firstCursor.DrawStartCap();
     }
     lineFromValid = false;
 }
コード例 #5
0
 virtual public void Loop(FDrawingCursor firstCursor, FDrawingCursor previousCursor)
 {
     if (firstCursor != null)
     {
         LineTo(firstCursor.lineFromPosition.x, firstCursor.lineFromPosition.y, previousCursor);
         firstCursor.DrawJoint(this);
         lineFromValid = false;
     }
     else
     {
         Flush(firstCursor);
     }
 }
コード例 #6
0
    public FDrawingSprite(FAtlasElement element) : base()
    {
        _quads              = new LinkedList <FDrawingQuad>();
        _cursor             = new FDrawingCursor(_quads);
        _firstLineCursor    = null;
        _previousLineCursor = null;

        Init(FFacetType.Quad, element, 0);        //this will call HandleElementChanged(), which will call Setup();

        _isAlphaDirty = true;

        UpdateLocalVertices();
    }
コード例 #7
0
    virtual public void Clear()
    {
        _quads              = new LinkedList <FDrawingQuad>();
        _cursor             = new FDrawingCursor(_quads);
        _firstLineCursor    = null;
        _previousLineCursor = null;

        //Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call Setup();

        _isAlphaDirty = true;

        UpdateLocalVertices();
        Setup();
    }
コード例 #8
0
    public virtual void MoveTo(float x,float y,FDrawingCursor firstCursor)
    {
        Flush (firstCursor);

        position.x=x;
        position.y=y;
    }
コード例 #9
0
    public virtual bool LineTo(float x,float y,FDrawingCursor previousCursor)
    {
        //Main line (no caps, caps are drawn on Flush, MoveTo)
        FDrawingQuad quad;
        quad=new FDrawingQuad(color);
        if (!quad.SetLineVertices(position,new Vector2(x,y),thickness,this)) {
            return false;
        }
        AddLineSideBorders(quad,quad);
        _quads.AddLast(quad);
        lineQuad=quad;
        /*
        if (color.a>=1) {
            quad=new FDrawingQuad(color);
            if (!quad.SetLineVertices(position,new Vector2(x,y),thickness,this)) {
                return false;
            }
            AddLineSideBorders(quad,quad);
            _quads.AddLast(quad);
            topQuad=quad;
            bottomQuad=null;
        } else {
            Vector2 lineTo=new Vector2(x,y);
            quad=new FDrawingQuad(color);
            if (!quad.SetLineVertices(this.position,lineTo,thickness,this)) {
                return false;
            }
            AddLineSideBorders(quad,quad);
            //split the quad in 2 parts (bottom and top)
            bottomQuad=new FDrawingQuad(color);
            bottomQuad.tlVertice=position;
            bottomQuad.blVertice=quad.blVertice;
            bottomQuad.trVertice=lineTo;
            bottomQuad.brVertice=quad.brVertice;
            //Debug
            //bottomQuad.blColor=new Color(1.0f,1.0f,1.0f,0.5f);
            //bottomQuad.tlColor=new Color(0.0f,0.0f,1.0f,0.5f);
            _quads.AddLast(bottomQuad);

            topQuad=quad;
            topQuad.blVertice=position;
            topQuad.brVertice=lineTo;
            //Debug
            //topQuad.blColor=new Color(1.0f,0.0f,0.0f,0.5f);
            //topQuad.tlColor=new Color(0.0f,0.0f,1.0f,0.5f);
            _quads.AddLast(topQuad);
        }
        */

        lineFromValid=true;
        lineFromPosition=position;
        position.x=x;
        position.y=y;

        if (previousCursor!=null) {
            DrawJoint(previousCursor);
        }
        return true;
    }
コード例 #10
0
 public virtual void Loop(FDrawingCursor firstCursor,FDrawingCursor previousCursor)
 {
     if (firstCursor!=null) {
         LineTo (firstCursor.lineFromPosition.x,firstCursor.lineFromPosition.y,previousCursor);
         firstCursor.DrawJoint(this);
         lineFromValid=false;
     } else {
         Flush (firstCursor);
     }
 }
コード例 #11
0
    public virtual void DrawJoint(FDrawingCursor previousCursor)
    {
        Vector2 prevOrtho=new Vector2(-previousCursor.direction.y,previousCursor.direction.x);
        Vector2 ortho=new Vector2(-direction.y,direction.x);
        float dot=Vector2.Dot(prevOrtho,direction);

        //Cut inside of the turn
        bool medianDone=false;
        Vector2 median=Vector2.zero;
        if (borders!=null) {
            if (borders.Count>0) {
                median=prevOrtho+ortho;
                median.Normalize();
                medianDone=true;
                if (median==Vector2.zero) {
                    //???
                } else {
                    Vector2 A=lineFromPosition;
                    Vector2 B=lineFromPosition+median;
                    float S,T;
                    bool ret;
                    if (dot<0) { //bottomQuad
                        int n=borders.Count;
                        for (int i=0;i<n;i++) {
                            FDrawingBorder border = borders[i];
                            FDrawingBorder previousBorder=previousCursor.borders[i];

                            //Previous line
                            //bottom line
                            ret=VectorUtils.LinesIntersect(A,B,previousBorder.bottomQuad.blVertice,previousBorder.bottomQuad.brVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                previousBorder.bottomQuad.brVertice = A + S * (B - A);
                            } else {
                                ret=VectorUtils.LinesIntersect(A,B,previousBorder.bottomQuad.tlVertice,previousBorder.bottomQuad.blVertice,out S,out T);
                                if ((ret)&&(T>=0)&&(T<=1)) {
                                    previousBorder.bottomQuad.brVertice = A + S * (B - A);
                                    previousBorder.bottomQuad.blVertice = previousBorder.bottomQuad.brVertice;
                                }
                            }
                            //topline
                            ret=VectorUtils.LinesIntersect(A,B,previousBorder.bottomQuad.tlVertice,previousBorder.bottomQuad.trVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                previousBorder.bottomQuad.trVertice = A + S * (B - A);
                            }

                            //Current line
                            //bottom line
                            ret=VectorUtils.LinesIntersect(A,B,border.bottomQuad.blVertice,border.bottomQuad.brVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                border.bottomQuad.blVertice = A + S * (B - A);
                            } else {
                                ret=VectorUtils.LinesIntersect(A,B,border.bottomQuad.trVertice,border.bottomQuad.brVertice,out S,out T);
                                if ((ret)&&(T>=0)&&(T<=1)) {
                                    border.bottomQuad.brVertice = A + S * (B - A);
                                    border.bottomQuad.blVertice = border.bottomQuad.brVertice;
                                }
                            }
                            //topline
                            ret=VectorUtils.LinesIntersect(A,B,border.bottomQuad.tlVertice,border.bottomQuad.trVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                border.bottomQuad.tlVertice = A + S * (B - A);
                            }
                            i++;
                        }
                    } else if (dot>0) { //topQuad
                        int n=borders.Count;
                        for (int i=0;i<n;i++) {
                            FDrawingBorder border = borders[i];
                            FDrawingBorder previousBorder=previousCursor.borders[i];
                            //Previous line
                            //top line
                            ret=VectorUtils.LinesIntersect(A,B,previousBorder.topQuad.tlVertice,previousBorder.topQuad.trVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                previousBorder.topQuad.trVertice = A + S * (B - A);
                            } else {
                                ret=VectorUtils.LinesIntersect(A,B,previousBorder.topQuad.tlVertice,previousBorder.topQuad.blVertice,out S,out T);
                                if ((ret)&&(T>=0)&&(T<=1)) {
                                    previousBorder.topQuad.trVertice = A + S * (B - A);
                                    previousBorder.topQuad.tlVertice = previousBorder.topQuad.trVertice;
                                }
                            }
                            //bottom line
                            ret=VectorUtils.LinesIntersect(A,B,previousBorder.topQuad.blVertice,previousBorder.topQuad.brVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                previousBorder.topQuad.brVertice = A + S * (B - A);
                            }

                            //Current line
                            //top line
                            ret=VectorUtils.LinesIntersect(A,B,border.topQuad.tlVertice,border.topQuad.trVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                border.topQuad.tlVertice = A + S * (B - A);
                            } else {
                                ret=VectorUtils.LinesIntersect(A,B,border.topQuad.trVertice,border.topQuad.trVertice,out S,out T);
                                if ((ret)&&(T>=0)&&(T<=1)) {
                                    border.topQuad.trVertice = A + S * (B - A);
                                    border.topQuad.tlVertice = border.topQuad.trVertice;
                                }
                            }
                            //bottom line
                            ret=VectorUtils.LinesIntersect(A,B,border.topQuad.blVertice,border.topQuad.brVertice,out S,out T);
                            if ((ret)&&(T>=0)&&(T<=1)) {
                                border.topQuad.blVertice = A + S * (B - A);
                            }

                            i++;
                        }
                    }
                }
            }
        }

        Vector2 center=lineFromPosition;

        //if ((color.a<1)&&(previousCursor.color.a<1)) { //not necessary for solid colors but removing overlapping mught help performances anyway
        if (!medianDone) {
            median=prevOrtho+ortho;
            median.Normalize();
            medianDone=true;
        }
        if (median==Vector2.zero) {
            //???
        } else {
            Vector2 A=lineFromPosition;
            Vector2 B=lineFromPosition+median;
            float S,T;
            bool ret;
            if (dot<0) { //bottomQuad
                //Previous line
                ret=VectorUtils.LinesIntersect(A,B,previousCursor.lineQuad.blVertice,previousCursor.lineQuad.brVertice,out S,out T);
                if ((ret)&&(T>=0)&&(T<=1)) {
                    center=previousCursor.lineQuad.brVertice = A + S * (B - A);
                }
                //Current line
                ret=VectorUtils.LinesIntersect(A,B,lineQuad.blVertice,lineQuad.brVertice,out S,out T);
                if ((ret)&&(T>=0)&&(T<=1)) {
                    center=lineQuad.blVertice = A + S * (B - A);
                }
            } else if (dot>0) { //topQuad
                //Previous line
                ret=VectorUtils.LinesIntersect(A,B,previousCursor.lineQuad.tlVertice,previousCursor.lineQuad.trVertice,out S,out T);
                if ((ret)&&(T>=0)&&(T<=1)) {
                    center=previousCursor.lineQuad.trVertice = A + S * (B - A);
                }
                //Current line
                ret=VectorUtils.LinesIntersect(A,B,lineQuad.tlVertice,lineQuad.trVertice,out S,out T);
                if ((ret)&&(T>=0)&&(T<=1)) {
                    center=lineQuad.tlVertice = A + S * (B - A);
                }
            }
        }
        //}

        //Draw joint
        if (jointType==FTDrawingJointStyle.BEVEL) {
            if (dot<0) {
                FDrawingQuad quad=new FDrawingQuad(this.color);
                quad.tlVertice=previousCursor.position+prevOrtho*previousCursor.thickness*0.5f;
                quad.blVertice=center;
                quad.brVertice=center;
                quad.trVertice=lineFromPosition+ortho*thickness*0.5f;
                _quads.AddLast(quad);

                AddBorders (quad.tlVertice,quad.tlColor,prevOrtho,quad.trVertice,quad.trColor,ortho);
            } else if (dot>0) {
                FDrawingQuad quad=new FDrawingQuad(this.color);
                quad.blVertice=previousCursor.position-prevOrtho*previousCursor.thickness*0.5f;
                quad.tlVertice=center;
                quad.trVertice=center;
                quad.brVertice=lineFromPosition-ortho*thickness*0.5f;
                _quads.AddLast(quad);

                AddBorders (quad.blVertice,quad.blColor,-prevOrtho,quad.brVertice,quad.brColor,-ortho);
            } else {
                // What else?
                // Parallel lines, no joint necessary
            }
        } else if (jointType==FTDrawingJointStyle.ROUND) {
            if (dot<0) {
                float angleDiff=Mathf.Abs(Mathf.Acos(Vector2.Dot(previousCursor.direction,direction)));
                int nbQuads=(int)(this.thickness*0.5f*angleDiff *0.5f *0.5f *0.5f)*2+2;

                float angle=0;
                //2 triangles by quads
                float deltaAngle=0.5f*angleDiff/nbQuads;
                for (int i=0;i<nbQuads;i++) {
                    FDrawingQuad quad=new FDrawingQuad(color);
                    //FDrawingQuad quad=new FDrawingQuad(new Color(1,(float)i/(float)nbQuads,(float)i/(float)nbQuads,1));
                    quad.trVertice=center;
                    quad.brVertice=previousCursor.position+prevOrtho*thickness*0.5f*Mathf.Cos(angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(angle);
                    angle+=deltaAngle;
                    quad.blVertice=previousCursor.position+prevOrtho*thickness*0.5f*Mathf.Cos(angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(angle);
                    angle+=deltaAngle;
                    quad.tlVertice=previousCursor.position+prevOrtho*thickness*0.5f*Mathf.Cos(angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(angle);
                    _quads.AddLast(quad);
                }
            } else if (dot>0) {
                float angleDiff=Mathf.Abs(Mathf.Acos(Vector2.Dot(previousCursor.direction,direction)));
                int nbQuads=(int)(this.thickness*0.5f*angleDiff *0.5f *0.5f *0.5f)*2+2;

                float angle=0;
                //2 triangles by quads
                float deltaAngle=0.5f*angleDiff/nbQuads;
                for (int i=0;i<nbQuads;i++) {
                    FDrawingQuad quad=new FDrawingQuad(color);
                    //FDrawingQuad quad=new FDrawingQuad(new Color(1,(float)i/(float)nbQuads,(float)i/(float)nbQuads,1));
                    quad.trVertice=center;
                    quad.brVertice=previousCursor.position-prevOrtho*thickness*0.5f*Mathf.Cos(-angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(-angle);
                    angle-=deltaAngle;
                    quad.blVertice=previousCursor.position-prevOrtho*thickness*0.5f*Mathf.Cos(-angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(-angle);
                    angle-=deltaAngle;
                    quad.tlVertice=previousCursor.position-prevOrtho*thickness*0.5f*Mathf.Cos(-angle)+previousCursor.direction*thickness*0.5f*Mathf.Sin(-angle);
                    _quads.AddLast(quad);
                }
            } else {
                // What else?
                // Parallel lines, no joint necessary
            }
            if ((borders!=null)&&(borders.Count>0)) {
                throw new FutileException("Joint type "+jointType+" not suported with borders. "+supportedJointTypesWithBorders);
            }
        } else if (jointType==FTDrawingJointStyle.MITER) {
            if (dot<0) {
                FDrawingQuad quad=new FDrawingQuad(this.color);
                quad.tlVertice=previousCursor.position+prevOrtho*previousCursor.thickness*0.5f;
                quad.blVertice=center;
                quad.brVertice=lineFromPosition+ortho*thickness*0.5f;
                bool valid;
                quad.trVertice=VectorUtils.LinesIntersectPoint(quad.tlVertice, quad.tlVertice+previousCursor.direction, quad.brVertice, quad.brVertice-direction, out valid);
                if (!valid) {
                    quad.trVertice=quad.brVertice;
                }
                _quads.AddLast(quad);
            } else if (dot>0) {
                FDrawingQuad quad=new FDrawingQuad(this.color);
                quad.blVertice=previousCursor.position-prevOrtho*previousCursor.thickness*0.5f;
                quad.tlVertice=center;
                quad.trVertice=lineFromPosition-ortho*thickness*0.5f;
                bool valid;
                quad.brVertice=VectorUtils.LinesIntersectPoint(quad.blVertice, quad.blVertice-previousCursor.direction, quad.trVertice, quad.trVertice+direction, out valid);
                if (!valid) {
                    quad.brVertice=quad.trVertice;
                }
                _quads.AddLast(quad);

            } else {
                // What else?
                // Parallel lines, no joint necessary
            }
            if ((borders!=null)&&(borders.Count>0)) {
                throw new FutileException("Joint type "+jointType+" not suported with borders. "+supportedJointTypesWithBorders);
            }
        }
    }
コード例 #12
0
 public virtual void Flush(FDrawingCursor firstCursor)
 {
     if (lineFromValid) {
         DrawEndCap();
     }
     if (firstCursor!=null) {
         firstCursor.DrawStartCap();
     }
     lineFromValid=false;
 }
コード例 #13
0
 public FDrawingCursor(FDrawingCursor model)
     : base()
 {
     Copy(model);
 }
コード例 #14
0
 public void Copy(FDrawingCursor model)
 {
     _quads=model.GetQuads();
     lineFromValid=model.lineFromValid;
     thickness=model.thickness;
     jointType=model.jointType;
     capType=model.capType;
     color=model.color;
     position=model.position;
     lineFromPosition=model.lineFromPosition;
     direction=model.direction;
     //topQuad=model.topQuad;
     //bottomQuad=model.bottomQuad;
     lineQuad=model.lineQuad;
     if (model.borders!=null) {
         borders=new List<FDrawingBorder>(model.borders.Count);
         int n=model.borders.Count;
         for (int i=0;i<n;i++) {
             FDrawingBorder border=model.borders[i];
             borders.Add(border.Clone());
         }
     } else {
         borders=null;
     }
 }
コード例 #15
0
ファイル: FDrawingSprite.cs プロジェクト: tanis2000/Futile
    public virtual void Clear()
    {
        _quads=new LinkedList<FDrawingQuad>();
        _cursor=new FDrawingCursor(_quads);
        _firstLineCursor=null;
        _previousLineCursor=null;

        //Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call Setup();

        _isAlphaDirty = true;

        UpdateLocalVertices();
        Setup();
    }
コード例 #16
0
 public FDrawingCursor(FDrawingCursor model) : base()
 {
     Copy(model);
 }
コード例 #17
0
    public bool SetLineVertices(Vector2 fromPosition,Vector2 toPosition,float thickness, FDrawingCursor cursor)
    {
        Vector2 direction=toPosition-fromPosition;
        float dist=Mathf.Sqrt(Vector2.SqrMagnitude(direction));
        if (dist<0.5f) {
            return false;
        }
        direction/=dist;
        Vector2 ortho=new Vector2(-direction.y,direction.x);
        tlVertice=fromPosition+ortho*thickness*0.5f;
        blVertice=fromPosition-ortho*thickness*0.5f;

        trVertice=toPosition+ortho*thickness*0.5f;
        brVertice=toPosition-ortho*thickness*0.5f;

        if (cursor!=null) cursor.direction=direction;
        return true;
    }
コード例 #18
0
    public bool SetLineVertices(Vector2 fromPosition, Vector2 toPosition, float thickness, FDrawingCursor cursor)
    {
        Vector2 direction = toPosition - fromPosition;
        float   dist      = Mathf.Sqrt(Vector2.SqrMagnitude(direction));

        if (dist < 0.5f)
        {
            return(false);
        }
        direction /= dist;
        Vector2 ortho = new Vector2(-direction.y, direction.x);

        tlVertice = fromPosition + ortho * thickness * 0.5f;
        blVertice = fromPosition - ortho * thickness * 0.5f;

        trVertice = toPosition + ortho * thickness * 0.5f;
        brVertice = toPosition - ortho * thickness * 0.5f;

        if (cursor != null)
        {
            cursor.direction = direction;
        }
        return(true);
    }
コード例 #19
0
    virtual public void DrawJoint(FDrawingCursor previousCursor)
    {
        Vector2 prevOrtho = new Vector2(-previousCursor.direction.y, previousCursor.direction.x);
        Vector2 ortho     = new Vector2(-direction.y, direction.x);
        float   dot       = Vector2.Dot(prevOrtho, direction);


        //Cut inside of the turn
        bool    medianDone = false;
        Vector2 median     = Vector2.zero;

        if (borders != null)
        {
            if (borders.Count > 0)
            {
                median = prevOrtho + ortho;
                median.Normalize();
                medianDone = true;
                if (median == Vector2.zero)
                {
                    //???
                }
                else
                {
                    Vector2 A = lineFromPosition;
                    Vector2 B = lineFromPosition + median;
                    float   S, T;
                    bool    ret;
                    if (dot < 0)                     //bottomQuad
                    {
                        int n = borders.Count;
                        for (int i = 0; i < n; i++)
                        {
                            FDrawingBorder border = borders[i];
                            if (border.bottom)
                            {
                                FDrawingBorder previousBorder = previousCursor.borders[i];

                                //Previous line
                                //bottom line
                                ret = VectorUtils.LinesIntersect(A, B, previousBorder.bottomQuad.blVertice, previousBorder.bottomQuad.brVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    previousBorder.bottomQuad.brVertice = A + S * (B - A);
                                }
                                else
                                {
                                    ret = VectorUtils.LinesIntersect(A, B, previousBorder.bottomQuad.tlVertice, previousBorder.bottomQuad.blVertice, out S, out T);
                                    if ((ret) && (T >= 0) && (T <= 1))
                                    {
                                        previousBorder.bottomQuad.brVertice = A + S * (B - A);
                                        previousBorder.bottomQuad.blVertice = previousBorder.bottomQuad.brVertice;
                                    }
                                }
                                //topline
                                ret = VectorUtils.LinesIntersect(A, B, previousBorder.bottomQuad.tlVertice, previousBorder.bottomQuad.trVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    previousBorder.bottomQuad.trVertice = A + S * (B - A);
                                }

                                //Current line
                                //bottom line
                                ret = VectorUtils.LinesIntersect(A, B, border.bottomQuad.blVertice, border.bottomQuad.brVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    border.bottomQuad.blVertice = A + S * (B - A);
                                }
                                else
                                {
                                    ret = VectorUtils.LinesIntersect(A, B, border.bottomQuad.trVertice, border.bottomQuad.brVertice, out S, out T);
                                    if ((ret) && (T >= 0) && (T <= 1))
                                    {
                                        border.bottomQuad.brVertice = A + S * (B - A);
                                        border.bottomQuad.blVertice = border.bottomQuad.brVertice;
                                    }
                                }
                                //topline
                                ret = VectorUtils.LinesIntersect(A, B, border.bottomQuad.tlVertice, border.bottomQuad.trVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    border.bottomQuad.tlVertice = A + S * (B - A);
                                }
                            }
                            //i++;
                        }
                    }
                    else if (dot > 0)                       //topQuad
                    {
                        int n = borders.Count;
                        for (int i = 0; i < n; i++)
                        {
                            FDrawingBorder border = borders[i];
                            if (border.top)
                            {
                                FDrawingBorder previousBorder = previousCursor.borders[i];
                                //Previous line
                                //top line
                                ret = VectorUtils.LinesIntersect(A, B, previousBorder.topQuad.tlVertice, previousBorder.topQuad.trVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    previousBorder.topQuad.trVertice = A + S * (B - A);
                                }
                                else
                                {
                                    ret = VectorUtils.LinesIntersect(A, B, previousBorder.topQuad.tlVertice, previousBorder.topQuad.blVertice, out S, out T);
                                    if ((ret) && (T >= 0) && (T <= 1))
                                    {
                                        previousBorder.topQuad.trVertice = A + S * (B - A);
                                        previousBorder.topQuad.tlVertice = previousBorder.topQuad.trVertice;
                                    }
                                }
                                //bottom line
                                ret = VectorUtils.LinesIntersect(A, B, previousBorder.topQuad.blVertice, previousBorder.topQuad.brVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    previousBorder.topQuad.brVertice = A + S * (B - A);
                                }

                                //Current line
                                //top line
                                ret = VectorUtils.LinesIntersect(A, B, border.topQuad.tlVertice, border.topQuad.trVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    border.topQuad.tlVertice = A + S * (B - A);
                                }
                                else
                                {
                                    ret = VectorUtils.LinesIntersect(A, B, border.topQuad.trVertice, border.topQuad.trVertice, out S, out T);
                                    if ((ret) && (T >= 0) && (T <= 1))
                                    {
                                        border.topQuad.trVertice = A + S * (B - A);
                                        border.topQuad.tlVertice = border.topQuad.trVertice;
                                    }
                                }
                                //bottom line
                                ret = VectorUtils.LinesIntersect(A, B, border.topQuad.blVertice, border.topQuad.brVertice, out S, out T);
                                if ((ret) && (T >= 0) && (T <= 1))
                                {
                                    border.topQuad.blVertice = A + S * (B - A);
                                }
                            }
                            //i++;
                        }
                    }
                }
            }
        }

        Vector2 center = lineFromPosition;

        //if ((color.a<1)&&(previousCursor.color.a<1)) { //not necessary for solid colors but removing overlapping mught help performances anyway
        if (!medianDone)
        {
            median = prevOrtho + ortho;
            median.Normalize();
            medianDone = true;
        }
        if (median == Vector2.zero)
        {
            //???
        }
        else
        {
            Vector2 A = lineFromPosition;
            Vector2 B = lineFromPosition + median;
            float   S, T;
            bool    ret;
            if (dot < 0)             //bottomQuad
            //Previous line
            {
                ret = VectorUtils.LinesIntersect(A, B, previousCursor.lineQuad.blVertice, previousCursor.lineQuad.brVertice, out S, out T);
                if ((ret) && (T >= 0) && (T <= 1))
                {
                    center = previousCursor.lineQuad.brVertice = A + S * (B - A);
                }
                //Current line
                ret = VectorUtils.LinesIntersect(A, B, lineQuad.blVertice, lineQuad.brVertice, out S, out T);
                if ((ret) && (T >= 0) && (T <= 1))
                {
                    center = lineQuad.blVertice = A + S * (B - A);
                }
            }
            else if (dot > 0)               //topQuad
            //Previous line
            {
                ret = VectorUtils.LinesIntersect(A, B, previousCursor.lineQuad.tlVertice, previousCursor.lineQuad.trVertice, out S, out T);
                if ((ret) && (T >= 0) && (T <= 1))
                {
                    center = previousCursor.lineQuad.trVertice = A + S * (B - A);
                }
                //Current line
                ret = VectorUtils.LinesIntersect(A, B, lineQuad.tlVertice, lineQuad.trVertice, out S, out T);
                if ((ret) && (T >= 0) && (T <= 1))
                {
                    center = lineQuad.tlVertice = A + S * (B - A);
                }
            }
        }
        //}

        //Draw joint
        if (jointType == FTDrawingJointStyle.BEVEL)
        {
            if (dot < 0)
            {
                FDrawingQuad quad = new FDrawingQuad(this.color);
                quad.tlVertice = previousCursor.position + prevOrtho * previousCursor.thickness * 0.5f;
                quad.blVertice = center;
                quad.brVertice = center;
                quad.trVertice = lineFromPosition + ortho * thickness * 0.5f;
                _quads.AddLast(quad);

                AddBorders(quad.tlVertice, quad.tlColor, prevOrtho, quad.trVertice, quad.trColor, ortho, true);
            }
            else if (dot > 0)
            {
                FDrawingQuad quad = new FDrawingQuad(this.color);
                quad.blVertice = previousCursor.position - prevOrtho * previousCursor.thickness * 0.5f;
                quad.tlVertice = center;
                quad.trVertice = center;
                quad.brVertice = lineFromPosition - ortho * thickness * 0.5f;
                _quads.AddLast(quad);

                AddBorders(quad.blVertice, quad.blColor, -prevOrtho, quad.brVertice, quad.brColor, -ortho, false);
            }
            else
            {
                // What else?
                // Parallel lines, no joint necessary
            }
        }
        else if (jointType == FTDrawingJointStyle.ROUND)
        {
            if (dot < 0)
            {
                float angleDiff = Mathf.Abs(Mathf.Acos(Vector2.Dot(previousCursor.direction, direction)));
                int   nbQuads   = (int)(this.thickness * 0.5f * angleDiff * 0.5f * 0.5f * 0.5f) * 2 + 2;

                float angle = 0;
                //2 triangles by quads
                float deltaAngle = 0.5f * angleDiff / nbQuads;
                for (int i = 0; i < nbQuads; i++)
                {
                    FDrawingQuad quad = new FDrawingQuad(color);
                    //FDrawingQuad quad=new FDrawingQuad(new Color(1,(float)i/(float)nbQuads,(float)i/(float)nbQuads,1));
                    quad.trVertice = center;
                    quad.brVertice = previousCursor.position + prevOrtho * thickness * 0.5f * Mathf.Cos(angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(angle);
                    angle         += deltaAngle;
                    quad.blVertice = previousCursor.position + prevOrtho * thickness * 0.5f * Mathf.Cos(angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(angle);
                    angle         += deltaAngle;
                    quad.tlVertice = previousCursor.position + prevOrtho * thickness * 0.5f * Mathf.Cos(angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(angle);
                    _quads.AddLast(quad);
                }
            }
            else if (dot > 0)
            {
                float angleDiff = Mathf.Abs(Mathf.Acos(Vector2.Dot(previousCursor.direction, direction)));
                int   nbQuads   = (int)(this.thickness * 0.5f * angleDiff * 0.5f * 0.5f * 0.5f) * 2 + 2;

                float angle = 0;
                //2 triangles by quads
                float deltaAngle = 0.5f * angleDiff / nbQuads;
                for (int i = 0; i < nbQuads; i++)
                {
                    FDrawingQuad quad = new FDrawingQuad(color);
                    //FDrawingQuad quad=new FDrawingQuad(new Color(1,(float)i/(float)nbQuads,(float)i/(float)nbQuads,1));
                    quad.trVertice = center;
                    quad.brVertice = previousCursor.position - prevOrtho * thickness * 0.5f * Mathf.Cos(-angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(-angle);
                    angle         -= deltaAngle;
                    quad.blVertice = previousCursor.position - prevOrtho * thickness * 0.5f * Mathf.Cos(-angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(-angle);
                    angle         -= deltaAngle;
                    quad.tlVertice = previousCursor.position - prevOrtho * thickness * 0.5f * Mathf.Cos(-angle) + previousCursor.direction * thickness * 0.5f * Mathf.Sin(-angle);
                    _quads.AddLast(quad);
                }
            }
            else
            {
                // What else?
                // Parallel lines, no joint necessary
            }
            if ((borders != null) && (borders.Count > 0))
            {
                throw new FutileException("Joint type " + jointType + " not suported with borders. " + supportedJointTypesWithBorders);
            }
        }
        else if (jointType == FTDrawingJointStyle.MITER)
        {
            if (dot < 0)
            {
                FDrawingQuad quad = new FDrawingQuad(this.color);
                quad.tlVertice = previousCursor.position + prevOrtho * previousCursor.thickness * 0.5f;
                quad.blVertice = center;
                quad.brVertice = lineFromPosition + ortho * thickness * 0.5f;
                bool valid;
                quad.trVertice = VectorUtils.LinesIntersectPoint(quad.tlVertice, quad.tlVertice + previousCursor.direction, quad.brVertice, quad.brVertice - direction, out valid);
                if (!valid)
                {
                    quad.trVertice = quad.brVertice;
                }
                _quads.AddLast(quad);
            }
            else if (dot > 0)
            {
                FDrawingQuad quad = new FDrawingQuad(this.color);
                quad.blVertice = previousCursor.position - prevOrtho * previousCursor.thickness * 0.5f;
                quad.tlVertice = center;
                quad.trVertice = lineFromPosition - ortho * thickness * 0.5f;
                bool valid;
                quad.brVertice = VectorUtils.LinesIntersectPoint(quad.blVertice, quad.blVertice - previousCursor.direction, quad.trVertice, quad.trVertice + direction, out valid);
                if (!valid)
                {
                    quad.brVertice = quad.trVertice;
                }
                _quads.AddLast(quad);
            }
            else
            {
                // What else?
                // Parallel lines, no joint necessary
            }
            if ((borders != null) && (borders.Count > 0))
            {
                throw new FutileException("Joint type " + jointType + " not suported with borders. " + supportedJointTypesWithBorders);
            }
        }
    }
コード例 #20
0
    public FDrawingSprite(FAtlasElement element)
        : base()
    {
        _quads=new LinkedList<FDrawingQuad>();
        _cursor=new FDrawingCursor(_quads);
        _firstLineCursor=null;
        _previousLineCursor=null;

        Init(FFacetType.Quad, element,0); //this will call HandleElementChanged(), which will call Setup();

        _isAlphaDirty = true;

        UpdateLocalVertices();
    }
コード例 #21
0
ファイル: FDrawingSprite.cs プロジェクト: tanis2000/Futile
    public virtual bool LineTo(float x,float y,FDrawingCursor previousCursor)
    {
        //Main line (no caps, caps are drawn on Flush, MoveTo)
        FDrawingQuad quad;
        quad=new FDrawingQuad(color);
        if (!quad.SetLineVertices(position,new Vector2(x,y),thickness,this)) {
            return false;
        }
        AddLineSideBorders(quad,quad);
        _quads.AddLast(quad);
        lineQuad=quad;

        lineFromValid=true;
        lineFromPosition=position;
        position.x=x;
        position.y=y;

        if (previousCursor!=null) {
            DrawJoint(previousCursor);
        }
        return true;
    }