Beispiel #1
0
        // TODO: Map scale?!
        public QuadTree(QuadTree parent, Vector3 position, int size, MapPart.Tri[] triangle, int startX, int startY)
        {
            this.parent = parent;
            this.position = position;
            this.size = size;
            this.startX = startX;
            this.startY = startY;

            // Sets the bounding box, note that the highest and lowest point is set later on
            Vector3 min = new Vector3(position.X, position.Y, position.Z);
            Vector3 max = new Vector3(position.X + (float)size, position.Y, position.Z + (float)size);
            this.boundingBox = new BoundingBox(min, max);

            SetupNode(triangle);
        }
Beispiel #2
0
 public void Load()
 {
     parts = new MapPart[1, 1];
     parts[0, 0] = new MapPart(this, Vector3.Zero, MapPartSize + 1, MapPartScale);
     parts[0, 0].LoadMapData("0002829.map");
 }
Beispiel #3
0
 public void Load()
 {
     parts       = new MapPart[1, 1];
     parts[0, 0] = new MapPart(this, Vector3.Zero, MapPartSize + 1, MapPartScale);
     parts[0, 0].LoadMapData("0002829.map");
 }
Beispiel #4
0
        public void SetupNode(MapPart.Tri[] triangle)
        {
            float highestPoint = 0f;
            float lowestPoint = 0f;

            if (size > PreferredSize)
            {
                nodes = new List<QuadTree>(4);

                int nodeSize = size / 2;
                for (int i = 0; i < 4; i++)
                {
                    int nodeX = i % 2;
                    int nodeY = i / 2;
                    Vector3 nodePos = new Vector3(position.X + (float)(nodeSize * nodeX),
                                                    position.Y,
                                                    position.Z + (float)(nodeSize * nodeY));

                    QuadTree newNode = new QuadTree(this, nodePos, nodeSize, triangle, startX + (nodeSize * nodeX), startY + (nodeSize * nodeY));
                    nodes.Add(newNode);

                    if (newNode.BoundingBox.Max.Y > highestPoint)
                        highestPoint = newNode.BoundingBox.Max.Y;

                    if (newNode.BoundingBox.Min.Y < lowestPoint)
                        lowestPoint = newNode.BoundingBox.Min.Y;
                }

                this.boundingBox.Min.Y = lowestPoint;
                this.boundingBox.Max.Y = highestPoint;
            }
            else
            {
                triangles = new List<int>();

                int mapSize = GetSize();
                for (int y = startY; y < (startY + size); y++)
                {
                    for (int x = startX; x < (startX + size); x++)
                    {
                        int tID = (x + y * mapSize) * 2;

                        if (tID < triangle.Length)
                        {
                            triangles.Add(tID);
                            triangles.Add(tID + 1);

                            if (triangle[tID].p1.Y > highestPoint)
                                highestPoint = triangle[tID].p1.Y;
                            if (triangle[tID].p2.Y > highestPoint)
                                highestPoint = triangle[tID].p2.Y;
                            if (triangle[tID].p3.Y > highestPoint)
                                highestPoint = triangle[tID].p3.Y;

                            if (triangle[tID].p1.Y < lowestPoint)
                                lowestPoint = triangle[tID].p1.Y;
                            if (triangle[tID].p2.Y < lowestPoint)
                                lowestPoint = triangle[tID].p2.Y;
                            if (triangle[tID].p3.Y < lowestPoint)
                                lowestPoint = triangle[tID].p3.Y;

                            if (triangle[tID + 1].p1.Y > highestPoint)
                                highestPoint = triangle[tID + 1].p1.Y;
                            if (triangle[tID + 1].p2.Y > highestPoint)
                                highestPoint = triangle[tID + 1].p2.Y;
                            if (triangle[tID + 1].p3.Y > highestPoint)
                                highestPoint = triangle[tID + 1].p3.Y;

                            if (triangle[tID + 1].p1.Y < lowestPoint)
                                lowestPoint = triangle[tID + 1].p1.Y;
                            if (triangle[tID + 1].p2.Y < lowestPoint)
                                lowestPoint = triangle[tID + 1].p2.Y;
                            if (triangle[tID + 1].p3.Y < lowestPoint)
                                lowestPoint = triangle[tID + 1].p3.Y;
                        }
                    }
                }

                this.boundingBox.Min.Y = lowestPoint;
                this.boundingBox.Max.Y = highestPoint;
            }
        }