Beispiel #1
0
        private void computeEdges()
        {
            edges.Clear();

            ushort nextEdgeIndex = 0;

            foreach (var point in Points)
            {
                foreach (var adjacent in point.AdjacentNodes)
                {
                    var newEdge = new NavworldEdge();
                    newEdge.A          = point;
                    newEdge.B          = adjacent;
                    newEdge.ChunkIndex = point.ChunkIndex;

                    double squared =
                        Math.Pow(((point.Vec3Pos.X * WEIGHT_SCALE) - (adjacent.Vec3Pos.X * WEIGHT_SCALE)), 2) +
                        Math.Pow(((point.Vec3Pos.Y * WEIGHT_SCALE) - (adjacent.Vec3Pos.Y * WEIGHT_SCALE)), 2) +
                        Math.Pow(((point.Vec3Pos.Z * WEIGHT_SCALE) - (adjacent.Vec3Pos.Z * WEIGHT_SCALE)), 2);

                    double distance = Math.Sqrt(squared);
                    newEdge.Weight = (ushort)distance;

                    bool edgeFound = false;

                    foreach (var edge in edges)
                    {
                        if (newEdge.Equals(edge))
                        {
                            edgeFound = true;
                            break;
                        }
                    }

                    if (!edgeFound)
                    {
                        newEdge.Index = nextEdgeIndex;
                        edges.Add(newEdge);
                        nextEdgeIndex++;
                    }
                }
            }
        }
Beispiel #2
0
        private void writePayload(BinaryWriter writer)
        {
            writePayloadHeader(writer);

            foreach (var point in Points)
            {
                point.WritePosition(writer);
            }

            var padding = Utils.GetPaddingSize((uint)(Points.Count * 6));

            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }

            ushort nextSectionOffset = 0;

            foreach (var point in Points)
            {
                writer.Write(nextSectionOffset);
                writer.Write((ushort)point.ChunkIndex);

                writer.Write((byte)(point.AdjacentNodes.Count));
                writer.Write((byte)(point.ZeroCostNode == null ? 0 : 1));

                nextSectionOffset += (ushort)((point.AdjacentNodes.Count * 2) + (point.ZeroCostNode == null ? 0 : 1));
            }

            padding = Utils.GetPaddingSize((uint)(Points.Count * 6));
            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }

            foreach (var point in Points)
            {
                foreach (var adjacent in point.AdjacentNodes)
                {
                    writer.Write(adjacent.Index);

                    var newEdge = new NavworldEdge();
                    newEdge.A = point;
                    newEdge.B = adjacent;

                    foreach (var edge in edges)
                    {
                        if (newEdge.Equals(edge))
                        {
                            writer.Write(edge.Index);
                            break;
                        }
                    }
                }

                if (point.ZeroCostNode != null)
                {
                    writer.Write(point.ZeroCostNode.Index);
                }
            }

            padding = Utils.GetPaddingSize(getSubsection3LengthWithoutPadding());
            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }

            foreach (var edge in edges)
            {
                writer.Write((ushort)edge.Weight);     // weight
                writer.Write((ushort)edge.ChunkIndex); // subsection5 index
                writer.Write((byte)(edge.A.Index - edge_offsets[edge.A.ChunkIndex]));
                writer.Write((byte)(edge.B.Index - edge_offsets[edge.B.ChunkIndex]));
            }

            padding = Utils.GetPaddingSize((uint)(edges.Count * 6));
            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }

            for (int i = 0; i < num_chunks; i++)
            {
                // TODO: Find what different values mean, flags?
                writer.Write((ushort)1249);
            }

            padding = Utils.GetPaddingSize(2 * num_chunks);
            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }

            foreach (var point in Points)
            {
                writer.Write(point.FaceIndex);
            }

            padding = Utils.GetPaddingSize((uint)(Points.Count * 2));
            for (int i = 0; i < padding; i++)
            {
                writer.Write((byte)0);
            }
        }