Ejemplo n.º 1
0
        public static Vector2 StaticScale(Vector2 start, Vector2 currentEnd, float Amt)
        {
            Velocity temp = new Velocity(currentEnd.X - start.X, currentEnd.Y - start.Y, false);

            temp.M = Amt;
            return(temp.Move(start));
        }
Ejemplo n.º 2
0
 public bool PointingInward(Vector2 position, float angle)
 {
     Velocity tmp = new Velocity(2*(bounds.Width + bounds.Height), angle, true);
     Vector2 limit = tmp.Move(position);
     int clip = 0;
     int count = 0;
     for (int i = 0; i < NumberOfSides(); i++)
     {
         ColisionInfo info = LineManager.LinesIntersect(position, limit, GetCorner(i), GetCorner((i + 1) % NumberOfSides()));
         switch(info.Type)
         {
             case 0:
                 break;
             case 1:
                 if (FloatHelp.ApproxEquals(info.IntersectionPointA.Value, position, .01f))
                 { }
                 else
                 {
                     clip++;
                 }
                 break;
             case 2:
                 break;
             case 3:
                 count++;
                 break;
         }
     }
     return (count + (clip/2)) % 2 == 1;
 }
Ejemplo n.º 3
0
        public static void DrawArrow(Vector2 start, Vector2 end, float flangeLength, float flangeAngle, SpriteBatch sb, Color c)
        {
            Camera.drawLineGeneric(start, end, sb, c);
            Velocity tmp = new Velocity(flangeLength, LocationManager.getRotation(end, start) + flangeAngle, true);

            Camera.drawLineGeneric(end, tmp.Move(end), sb, c);
            tmp = new Velocity(flangeLength, LocationManager.getRotation(end, start) - flangeAngle, true);
            Camera.drawLineGeneric(end, tmp.Move(end), sb, c);
        }
Ejemplo n.º 4
0
        public static bool DoSingleColision_Debug(Polygon MovingPoly, Polygon StationaryPoly, Velocity velocity, List <Vector2[]> lines, List <Color> linecolors)
        {
            Vector2[][] MovingLines     = new Vector2[MovingPoly.NumberOfSides()][];
            Vector2[][] StationaryLines = new Vector2[StationaryPoly.NumberOfSides()][];
            bool        doWork          = false;

            for (int i = 0; i < MovingLines.Length; i++)
            {
                MovingLines[i] = new Vector2[] { velocity.Move(MovingPoly.GetCorner(i), -1f), velocity.Move(MovingPoly.GetCorner(i), 1f) };
                lines.Add(MovingLines[i]);
                linecolors.Add(Color.Blue);
                if (!doWork && LocationManager.getBounds(MovingLines[i]).Intersects(StationaryPoly.Bounds))
                {
                    doWork = true;
                }
            }
            for (int i = 0; i < StationaryLines.Length; i++)
            {
                StationaryLines[i] = new Vector2[] { velocity.Move(StationaryPoly.GetCorner(i), -1f), velocity.Move(StationaryPoly.GetCorner(i), 1f) };
                lines.Add(StationaryLines[i]);
                linecolors.Add(Color.Green);
                if (!doWork && LocationManager.getBounds(StationaryLines[i]).Intersects(MovingPoly.Bounds))
                {
                    doWork = true;
                }
            }
            if (!doWork)
            {
                foreach (Vector2[] v in LocationManager.RectangleEdges(MovingPoly.Bounds))
                {
                    lines.Add(v);
                    linecolors.Add(Color.Yellow);
                }
                foreach (Vector2[] v in LocationManager.RectangleEdges(StationaryPoly.Bounds))
                {
                    lines.Add(v);
                    linecolors.Add(Color.Yellow);
                }
                return(false);
            }

            int     lowindex     = -1;
            int     otherindex   = -1;
            float   lowdistance  = 0;
            bool    movingcloser = false;
            Vector2 intersect    = new Vector2();

            for (int i = 0; i < MovingLines.Length; i++)
            {
                for (int i2 = 0; i2 < StationaryLines.Length; i2++)
                {
                    Vector2?V2 = LocationManager.getIntersectionPoint(StationaryPoly.GetEdge(i2), MovingLines[i]);
                    if (V2.HasValue)
                    {
                        if (lowindex == -1 || LocationManager.distanceCheck(V2.Value, MovingLines[i][0], lowdistance))
                        {
                            lowdistance  = LocationManager.getDistance(V2.Value, MovingLines[i][0]);
                            lowindex     = i;
                            otherindex   = i2;
                            movingcloser = true;
                            intersect    = V2.Value;
                        }
                    }
                }
            }
            for (int i = 0; i < StationaryLines.Length; i++)
            {
                for (int i2 = 0; i2 < MovingLines.Length; i2++)
                {
                    Vector2?V2 = LocationManager.getIntersectionPoint(MovingPoly.GetEdge(i2), StationaryLines[i]);
                    if (V2.HasValue)
                    {
                        //Console.Out.WriteLine("Intersection at {0}::{1} => Point at {2}", MovingPoly.GetEdge(i2)[0] + "," + MovingPoly.GetEdge(i2)[1], StationaryLines[i][0] + "," + StationaryLines[i][1], V2.Value);
                        if (lowindex == -1 || LocationManager.distanceCheck(V2.Value, StationaryLines[i][1], lowdistance))
                        {
                            lowdistance  = velocity.M - LocationManager.getDistance(V2.Value, StationaryLines[i][0]);
                            lowindex     = i;
                            otherindex   = i2;
                            movingcloser = false;
                            intersect    = V2.Value;
                        }
                    }
                }
            }

            if (lowindex != -1)
            {
                Velocity AddToVelocity = new Velocity();
                if (movingcloser)
                {
                    float angle = LocationManager.getRotation(intersect, LocationManager.getReflectionLine(MovingLines[lowindex], StationaryPoly.GetEdge(otherindex))[1]);
                    AddToVelocity.A = angle;
                    AddToVelocity.M = velocity.M;
                    lines.Add(new Vector2[] { MovingLines[lowindex][0], MovingLines[lowindex][1] });
                    linecolors.Add(Color.Red);
                }
                else
                {
                    float angle = LocationManager.getRotation(intersect, LocationManager.getReflectionLine(StationaryLines[lowindex], MovingPoly.GetEdge(otherindex))[1]);
                    AddToVelocity.A = angle;
                    AddToVelocity.M = velocity.M;
                    lines.Add(new Vector2[] { StationaryLines[lowindex][0], StationaryLines[lowindex][1] });
                    linecolors.Add(Color.Red);
                }

                velocity.X = AddToVelocity.X;
                velocity.Y = AddToVelocity.Y;

                MovingPoly.Position = LocationManager.moveByRotation(MovingPoly.Position, lowdistance, velocity.A);
                return(true);
            }
            return(false);
        }