Ejemplo n.º 1
0
            public float GetHeight(WorldLocation location, TileManager tiles, SceneryDrawer scenery)
            {
                location.Normalize();

                // First, ensure we have the tile in question cached.
                var tile = Tiles.FirstOrDefault(t => t.TileX == location.TileX && t.TileZ == location.TileZ);

                if (tile == null)
                {
                    Tiles.Add(tile = new Tile(location.TileX, location.TileZ, Divisions));
                }

                // Remove excess entries.
                if (Tiles.Count > TileCount)
                {
                    Tiles.RemoveAt(0);
                }

                // Now calculate division to query.
                var x = (int)((location.Location.X + 1024) / BlockSize);
                var z = (int)((location.Location.Z + 1024) / BlockSize);

                // If we don't have it cached, load it.
                if (tile.Height[x, z] == float.MinValue)
                {
                    var position = new WorldLocation(location.TileX, location.TileZ, (x + 0.5f) * BlockSize - 1024, 0, (z + 0.5f) * BlockSize - 1024);
                    tile.Height[x, z] = Math.Max(tiles.GetElevation(position), scenery.GetBoundingBoxTop(position, BlockSize));
                    tile.Used++;
                }

                return(tile.Height[x, z]);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate back the World location corresponding to given area coordinate
        /// </summary>
        /// <param name="areaX">X-coordinate on the area (in pixels)</param>
        /// <param name="areaY">Y-coordinate on the area (in pixels)</param>
        /// <returns>Corresponding world location</returns>
        private WorldLocation GetWorldLocation(int areaX, int areaY)
        {
            double        x        = (OffsetX + (areaX) / Scale);
            double        z        = (OffsetZ + (AreaH - areaY) / Scale);
            WorldLocation location = new WorldLocation(0, 0, (float)x, 0, (float)z);

            location.Normalize();
            return(location);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculate back the World location corresponding to given area coordinate
        /// </summary>
        /// <param name="areaX">X-coordinate on the area (in pixels)</param>
        /// <param name="areaY">Y-coordinate on the area (in pixels)</param>
        /// <returns>Corresponding world location</returns>
        private WorldLocation GetWorldLocation(int areaX, int areaY)
        {
            double x = (OffsetX + (areaX) / Scale);
            double z = (OffsetZ + (AreaH - areaY) / Scale);
            //WorldLocation location = new WorldLocation(0, 0, cornerIndexX, 0, cornerIndexZ);
            //we now do pre-normalization. This normalization is more efficient than Coordinates.normalization
            int tileX = (int)x / 2048;

            x -= (tileX * 2048);
            int tileZ = (int)z / 2048;

            z -= tileZ * 2048;
            WorldLocation location = new WorldLocation(tileX, tileZ, (float)x, 0, (float)z);

            location.Normalize();
            return(location);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Do the dragging itself, meaning moving the label to a different position and show that
        /// </summary>
        internal void OnLeftMouseMoved()
        {
            if (!dragging)
            {
                return;
            }

            //We have three locations. Where the original/reference label. Where the dragging starts, and where the mouse now is
            //The new location is then 'original' + 'current' - 'start'.
            draggingStartLocation.NormalizeTo(drawArea.MouseLocation.TileX, drawArea.MouseLocation.TileZ);
            WorldLocation shiftedLocation = new WorldLocation(
                draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
                draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
                draggingLabelToReplace.WorldLocation.Location.X + drawArea.MouseLocation.Location.X - draggingStartLocation.Location.X,
                0,
                draggingLabelToReplace.WorldLocation.Location.Z + drawArea.MouseLocation.Location.Z - draggingStartLocation.Location.Z
                );

            shiftedLocation.Normalize();
            draggingLabel = new StorableLabel(shiftedLocation, draggingLabelToReplace.LabelText);
        }