コード例 #1
0
ファイル: PolygonTrigger.cs プロジェクト: hofi171/OpenSAGE
        internal void Load(SaveFileReader reader)
        {
            reader.ReadVersion(1);

            var numPoints = reader.ReadUInt32();

            if (numPoints != Points.Length)
            {
                throw new InvalidDataException();
            }

            for (var i = 0; i < numPoints; i++)
            {
                Points[i] = MapVector3i.Parse(reader.Inner);
            }

            var topLeft     = reader.ReadPoint2D();
            var bottomRight = reader.ReadPoint2D();

            Bounds = Rectangle.FromCorners(topLeft, bottomRight);

            // The following value is what you get if you do this calculation:
            // width = (bottomRight.X - topLeft.X) * 0.5
            // height = (bottomRight.Y + topLeft.Y) * 0.5
            // value = sqrt(width * width + height * height)
            //
            // This looks like it's supposed to be a radius for this polygon trigger,
            // presumably used for quick distance tests prior to testing if
            // a point is inside the actual polygon.
            //
            // But there's a mistake... the height should instead be:
            // height = (bottomRight.Y - topLeft.Y) * 0.5
            //
            // As it is, this "radius" is significantly larger than it should be.
            var _ = reader.ReadSingle();

            Radius = MathF.Sqrt(Bounds.Width * Bounds.Width + Bounds.Height * Bounds.Height);

            var unknown = reader.ReadBoolean();

            if (unknown)
            {
                throw new InvalidDataException();
            }
        }