示例#1
0
 public void DrawFilledPolys(Polygon[] polygons, Matrix View, Color color)
 {
     int len = 0;
     for (int x = 0; x < polygons.Length; x++)
     {
         len += polygons[x].Edges.Length * 3;
     }
     be.View = View;
     be.CurrentTechnique.Passes[0].Apply();
     VertexPositionColor[] vertices = new VertexPositionColor[len];
     int count = 0;
     for (int x = 0; x < polygons.Length; x++)
     {
         for (int y = 0; y < polygons[x].Edges.Length; y++)
         {
             vertices[count] = new VertexPositionColor(new Microsoft.Xna.Framework.Vector3(polygons[x].Edges[y].Start.X, polygons[x].Edges[y].Start.Z, 0), color);
             vertices[count + 1] = new VertexPositionColor(new Microsoft.Xna.Framework.Vector3(polygons[x].Edges[y].End.X, polygons[x].Edges[y].End.Z, 0), color);
             vertices[count + 2] = new VertexPositionColor(new Microsoft.Xna.Framework.Vector3(polygons[x].Center.X, polygons[x].Center.Z, 0), color);
             count += 3;
         }
     }
     if (len < 2)
         return;
     device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, len / 3, VertexPositionColor.VertexDeclaration);
 }
示例#2
0
 public Structure(Map map, Vector3 position, Vector3[] vertices, string characterfile, int teamID)
 {
     this.position = position;
     this.collisionPolygon = new Polygon(vertices);
     this.characterFile = characterfile;
     info = new CharacterInfo(characterfile);
     health = info.maxHealth;
     this.teamID = teamID;
     this.map = map;
 }
示例#3
0
 public Structure(Map map, BinaryReader reader)
 {
     position = reader.ReadVector3();
     collisionPolygon = new Polygon(reader);
     characterFile = reader.ReadString();
     teamID = reader.ReadInt32();
     info = new CharacterInfo(characterFile);
     health = info.maxHealth;
     this.map = map;
 }
示例#4
0
 public Collision(Vector3[] vertices)
 {
     collisionPolygon = new Polygon(vertices);
 }
示例#5
0
 public Collision(BinaryReader reader)
 {
     collisionPolygon = new Polygon(reader);
 }
示例#6
0
文件: Bush.cs 项目: MyEyes/MobaAI
 public Bush(int id, Vector3[] vertices)
 {
     this.id = id;
     this.boundary = new Polygon(vertices);
 }
示例#7
0
文件: Bush.cs 项目: MyEyes/MobaAI
 public Bush(BinaryReader reader)
 {
     id = reader.ReadInt32();
     boundary = new Polygon(reader);
 }
示例#8
0
文件: Polygon.cs 项目: MyEyes/MobaAI
        private bool InternalSATIntersect(Polygon polygon)
        {
            //For every normal check if the projection of this polygon
            //intersects with the projection of the other one
            //If yes try next normal, if not we don't intersect
            Vector3 extent = Vector3.Zero;
            for (int x = 0; x < satHelpers.Length; x++)
            {
                extent.X = float.MaxValue;
                extent.Y = float.MinValue;

                for (int y = 0; y < polygon.edges.Length; y++)
                {
                    float proj = Vector3.Dot(edges[x].Normal, polygon.edges[y].Start - center);
                    if (proj < extent.X)
                        extent.X = proj;
                    if (proj > extent.Y)
                        extent.Y = proj;
                }
                if (!RangeOverlaps(satHelpers[x], extent))
                    return false;
            }
            return true;
        }
示例#9
0
文件: Polygon.cs 项目: MyEyes/MobaAI
        // 1. iterate through each Vertex on the source
        // 2. iterate through each of this polygons normals
        // 3. calculate time to that each vertex in source will collide against this's normals
        // 4. the vertex with the lowest time to collide against a normal is the one we collide with soonest
        // 5. store vertex -> T (inverse time to collide)
        // 6. find the vertex with the lowest T
        private void FindFirstCollidingEdge(Polygon source, Vector3 velocity, out Edge edgeCollidedWith, out float collideTime)
        {
            Edge collidesFirstEdge = new Edge();
            float collidesFirstTime = float.MaxValue;

            foreach (Vector3 vertex in source.points)
            {
                Edge closestEdge = new Edge();
                float closestEdgeTime = 0;
                float closestNotEdgeTime = float.MaxValue;
                bool found = false;

                foreach (Edge edge in this.edges)
                {
                    // time = -(nx*px)+(ny*py)/(vx*nx)+(vy*ny)
                    float top = Vector3.Dot(vertex - edge.Start, edge.Normal);
                    float bot = Vector3.Dot(velocity, edge.Normal);
                    float time = -((top) / bot);
                    bool facing = top >= 0;

                    // the normal with the highest T is the one we collide with soonest
                    if (facing && time > closestEdgeTime)
                    {
                        closestEdge = edge;
                        closestEdgeTime = time;
                        found = true;
                    }
                    else if (!facing && time > 0 && time < closestNotEdgeTime)
                    {
                        closestNotEdgeTime = time;
                    }
                }

                // the vertex with the lowest T is the vertex that will collide first
                if (found && closestEdgeTime < collidesFirstTime && closestEdgeTime < closestNotEdgeTime)
                {
                    collidesFirstEdge = closestEdge;
                    collidesFirstTime = closestEdgeTime;
                }
            }

            edgeCollidedWith = collidesFirstEdge;
            collideTime = collidesFirstTime;
        }
示例#10
0
文件: Polygon.cs 项目: MyEyes/MobaAI
 public bool Intersects(Polygon polygon)
 {
     //Check SAT, SAT will yield correct negatives for all polygons
     //But may yield false positives for concave polygons
     //So we check SAT first since we expect most things not to intersect
     //And if SAT says we collide and one polygon is not convex we test more intensively
     if (!InternalSATIntersect(polygon))
         return false;
     if (!polygon.InternalSATIntersect(this))
         return false;
     //For convex polygons SAT is sufficient
     if (IsConvex && polygon.IsConvex)
         return true;
     //TODO: For concave polygons we will need a more extensive check
     return true;
 }
示例#11
0
文件: Polygon.cs 项目: MyEyes/MobaAI
        public static void FindCollidingEdge(Polygon source, Polygon dest, Vector3 velocity, out Edge thatCollidesWith)
        {
            Edge edgeSource;
            float timeSource;

            Edge edgeDest;
            float timeDest;

            source.FindFirstCollidingEdge(dest, -velocity, out edgeSource, out timeSource);
            dest.FindFirstCollidingEdge(source, velocity, out edgeDest, out timeDest);

            thatCollidesWith = timeSource < timeDest ? edgeSource : edgeDest;
        }
示例#12
0
文件: Bush.cs 项目: MyEyes/MobaAI
 public Bush(int id, Vector3[] vertices)
 {
     this.id       = id;
     this.boundary = new Polygon(vertices);
 }
示例#13
0
文件: Bush.cs 项目: MyEyes/MobaAI
 public Bush(BinaryReader reader)
 {
     id       = reader.ReadInt32();
     boundary = new Polygon(reader);
 }