Esempio n. 1
0
        public static Mesh2D Paddle(P3 topLeft, float width, float height, P3 position, float roofPct)
        {
            P3[] vertices = new P3[paddleVerts.Length + 2];

            int i; float dx = width / (paddleVerts.Length - 1), dy = roofPct * height;

            for (i = 0; i < paddleVerts.Length; i++)
            {
                vertices[i] = V3.New(topLeft.X + dx * i, topLeft.Y + dy * (1 - (float)paddleVerts[i]), 0);
            }
            vertices[i]     = new V3(topLeft.X + width, topLeft.Y + height, 0);     //br
            vertices[i + 1] = new V3(topLeft.X, topLeft.Y + height, 0);             //bl
            return(new Mesh2D(vertices, position));
        }
Esempio n. 2
0
        public Result IntersectsWith(Edge other, out P3 intersectionPoint)
        {
            intersectionPoint = null;
            float denom = ((other.Tail.Y - other.Head.Y) * (Tail.X - Head.X)) - ((other.Tail.X - other.Head.X) * (Tail.Y - Head.Y));
            float numeA = ((other.Tail.X - other.Head.X) * (Head.Y - other.Head.Y)) - ((other.Tail.Y - other.Head.Y) * (Head.X - other.Head.X));
            float numeB = ((Tail.X - Head.X) * (Head.Y - other.Head.Y)) - ((Tail.Y - Head.Y) * (Head.X - other.Head.X));

            if (denom == 0)
            {
                if (numeA == 0 && numeB == 0)                   //find out if coincident seg touches us
                {
                    V3   n     = other.ToVector().Perpendicular2DLeftHanded().UnitVector;
                    Edge perp  = new Edge(other.Head + n, other.Head);
                    Edge perp2 = new Edge(other.Tail + n, other.Tail);
                    P3   o;
                    if (Edge.Result.Intersecting == perp.IntersectsWith(this, out o))
                    {
                        intersectionPoint = o;
                        return(Edge.Result.Intersecting);
                    }
                    if (Edge.Result.Intersecting == perp2.IntersectsWith(this, out o))
                    {
                        intersectionPoint = o;
                        return(Edge.Result.Intersecting);
                    }
                    return(Result.Coincident);
                }
                return(Result.Parallel);
            }
            float ua = numeA / denom;
            float ub = numeB / denom;

            if (ua >= 0 && ua <= 1.0 && ub >= 0 && ub <= 1.0)
            {
                // Get the intersection point.
                intersectionPoint = V3.New(Head.X + ua * (Tail.X - Head.X), Head.Y + ua * (Tail.Y - Head.Y), 0);
                return(Result.Intersecting);
            }
            return(Result.NotIntersecting);
        }
Esempio n. 3
0
 public V3 ToV3()
 {
     return(V3.New(this));
 }