Ejemplo n.º 1
0
        public Surface(SurfaceType type, Vector2 start, Vector2 end)
        {
            surfaceLineSegment = new LineSegment(start, end);
            m_type = type;

            construct();
        }
Ejemplo n.º 2
0
        public Surface(Tower a, Tower b, SurfaceType type, Level Parent)
        {
            tower_A = a; tower_A.AddSurface(this);
            tower_B = b; tower_B.AddSurface(this);
            m_type = type;

            surfaceLineSegment = new LineSegment(a.getPosition(), b.getPosition());

            parent = Parent;

            construct();
        }
Ejemplo n.º 3
0
 /* PUBLIC STATIC */
 static bool Intersects(LineSegment first, LineSegment second)
 {
     return false;
 }
Ejemplo n.º 4
0
 static Vector2? IntersectionPoint(LineSegment first, LineSegment second)
 {
     return null;
 }
Ejemplo n.º 5
0
        private float findIntersection(LineSegment segment)
        {
            Vector2 u = End - Start;
            Vector2 v = segment.End - segment.Start;
            Vector2 w = Start - segment.Start;

            Vector2 vPerp = new Vector2(-v.Y, v.X);
            vPerp.Normalize();

            if ((Vector2.Dot(Start - segment.Start, vPerp)) > 0) {
                // Need to flip!!
                //v = segment.Start - segment.End;
            }

            float tIntersect = (v.Y * w.X - v.X * w.Y) / (v.X * u.Y - v.Y * u.X);
            if (tIntersect >= 0f && tIntersect <= 1f) {
                float sIntersect = (u.X * w.Y - u.Y * w.X) / (u.X * v.Y - u.Y * v.X);
                if (sIntersect > 0f && sIntersect < 1f) {
                    return tIntersect * Length;
                }
            }
            return -1f;
        }
Ejemplo n.º 6
0
 public bool IsColliding(LineSegment segment)
 {
     float tIntersect = findIntersection(segment);
     return (tIntersect >= 0f);
 }
Ejemplo n.º 7
0
        public Vector2? FindIntersectionPoint(LineSegment segment)
        {
            float tIntersect = findIntersection(segment);

            if (tIntersect < 0) {
                return null;
            }

            Vector2 u = End - Start;
            u.Normalize();
            Vector2 pIntersect = Start + tIntersect * u;

            return pIntersect;
        }
Ejemplo n.º 8
0
        public float Chomp(LineSegment segment)
        {
            if (!IsColliding(segment)) {
                return 0f;
            }

            float amountToChomp = findIntersection(segment);

            Chomp(amountToChomp);
            return amountToChomp;
        }