Class HyperellipticalWorldMap

java.lang.Object
com.github.yellowstonegames.world.WorldMapGenerator
com.github.yellowstonegames.world.HyperellipticalWorldMap

public class HyperellipticalWorldMap extends WorldMapGenerator
A concrete implementation of WorldMapGenerator that projects the world map onto a shape that resembles a mix part-way between an ellipse and a rectangle. This is an equal-area projection, like EllipticalWorldMap, so effects that fill areas on a map like PoliticalMapper will fill (almost) equally on any part of the map. This has less distortion around all the edges than the other maps here, especially when comparing the North and South poles with RoundSideWorldMap. This uses the Tobler hyperelliptical projection.
This is my (Tommy Ettinger's) personal favorite projection here, because it can be close enough to the familiar rectangular map projections used in many atlases, while still keeping the poles as single points and minimizing most kinds of shape distortion. Thank you, Waldo Tobler, RIP.
Example map.
  • Field Details

    • terrainFreq

      protected static final float terrainFreq
      See Also:
    • terrainLayeredFreq

      protected static final float terrainLayeredFreq
      See Also:
    • heatFreq

      protected static final float heatFreq
      See Also:
    • moistureFreq

      protected static final float moistureFreq
      See Also:
    • otherFreq

      protected static final float otherFreq
      See Also:
    • minHeat0

      protected float minHeat0
    • maxHeat0

      protected float maxHeat0
    • minHeat1

      protected float minHeat1
    • maxHeat1

      protected float maxHeat1
    • minWet0

      protected float minWet0
    • maxWet0

      protected float maxWet0
    • terrainRidged

      public final com.github.yellowstonegames.grid.NoiseWrapper terrainRidged
    • heat

      public final com.github.yellowstonegames.grid.NoiseWrapper heat
    • moisture

      public final com.github.yellowstonegames.grid.NoiseWrapper moisture
    • otherRidged

      public final com.github.yellowstonegames.grid.NoiseWrapper otherRidged
    • terrainBasic

      public final com.github.yellowstonegames.grid.NoiseWrapper terrainBasic
    • xPositions

      public final float[][] xPositions
    • yPositions

      public final float[][] yPositions
    • zPositions

      public final float[][] zPositions
    • edges

      protected final int[] edges
    • alpha

      public final float alpha
    • kappa

      public final float kappa
    • epsilon

      public final float epsilon
  • Constructor Details

    • HyperellipticalWorldMap

      public HyperellipticalWorldMap()
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Always makes a 200x100 map. Uses Noise as its noise generator, with 1f as the octave multiplier affecting detail. If you were using HyperellipticalWorldMap(long, int, int, INoise, float), then this would be the same as passing the parameters 0x1337BABE1337D00DL, 200, 100, new Noise(DEFAULT_NOISE), 1f. Example map, showing special shape
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(int mapWidth, int mapHeight)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes only the width/height of the map. The initial seed is set to the same large long every time, and it's likely that you would set the seed when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Uses Noise as its noise generator, with 1f as the octave multiplier affecting detail.
      Parameters:
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed and the width/height of the map. The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Uses Noise as its noise generator, with 1f as the octave multiplier affecting detail.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight, float octaveMultiplier)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed and the width/height of the map. The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Uses Noise as its noise generator, with the given octave multiplier affecting detail.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
      octaveMultiplier - used to adjust the level of detail, with 0.5f at the bare-minimum detail and 1f normal
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight, com.github.yellowstonegames.grid.INoise noiseGenerator)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed and the width/height of the map. The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Uses the given noise generator, with 1f as the octave multiplier affecting detail. The suggested Noise implementation to use is Noise.instance.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
      noiseGenerator - an instance of a noise generator capable of 3D noise, usually Noise
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight, com.github.yellowstonegames.grid.INoise noiseGenerator, float octaveMultiplier)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed, the width/height of the map, and parameters for noise generation (a Noise implementation, where Noise.instance is suggested, and a multiplier on how many octaves of noise to use, with 1f being normal (high) detail and higher multipliers producing even more detailed noise when zoomed-in). The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Noise will be the fastest 3D generator to use for noiseGenerator, and the seed it's constructed with doesn't matter because this will change the seed several times at different scales of noise (it's fine to use the static Noise.instance because it has no changing state between runs of the program). The octaveMultiplier parameter should probably be no lower than 0.5f, but can be arbitrarily high if you're willing to spend much more time on generating detail only noticeable at very high zoom; normally 1f is fine and may even be too high for maps that don't require zooming.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
      noiseGenerator - an instance of a noise generator capable of 3D noise, usually Noise
      octaveMultiplier - used to adjust the level of detail, with 0.5f at the bare-minimum detail and 1f normal
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight, com.github.yellowstonegames.grid.INoise noiseGenerator, float octaveMultiplier, float alpha, float kappa)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed, the width/height of the map, and parameters for noise generation (a Noise implementation, where Noise.instance is suggested, and a multiplier on how many octaves of noise to use, with 1f being normal (high) detail and higher multipliers producing even more detailed noise when zoomed-in). The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Noise will be the fastest 3D generator to use for noiseGenerator, and the seed it's constructed with doesn't matter because this will change the seed several times at different scales of noise (it's fine to use the static Noise.instance because it has no changing state between runs of the program). The octaveMultiplier parameter should probably be no lower than 0.5f, but can be arbitrarily high if you're willing to spend much more time on generating detail only noticeable at very high zoom; normally 1f is fine and may even be too high for maps that don't require zooming.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
      noiseGenerator - an instance of a noise generator capable of 3D noise, usually Noise
      octaveMultiplier - used to adjust the level of detail, with 0.5f at the bare-minimum detail and 1f normal
      alpha - one of the Tobler parameters; 0.0625f is the default and this can range from 0f to 1f at least
      kappa - one of the Tobler parameters; 2.5f is the default but 2f-5f range values are also often used
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(long initialSeed, int mapWidth, int mapHeight, com.github.yellowstonegames.grid.INoise terrainRidgedNoise, com.github.yellowstonegames.grid.INoise terrainBasicNoise, com.github.yellowstonegames.grid.INoise heatNoise, com.github.yellowstonegames.grid.INoise moistureNoise, com.github.yellowstonegames.grid.INoise otherRidgedNoise, float octaveMultiplier, float alpha, float kappa)
      Constructs a concrete WorldMapGenerator for a map that can be used to display a projection of a globe onto an ellipse without distortion of the sizes of features but with significant distortion of shape. Takes an initial seed, the width/height of the map, and parameters for noise generation (a Noise implementation, where Noise.instance is suggested, and a multiplier on how many octaves of noise to use, with 1f being normal (high) detail and higher multipliers producing even more detailed noise when zoomed-in). The initialSeed parameter may or may not be used, since you can specify the seed to use when you call WorldMapGenerator.generate(long, long). The width and height of the map cannot be changed after the fact, but you can zoom in. Noise will be the fastest 3D generator to use for noiseGenerator, and the seed it's constructed with doesn't matter because this will change the seed several times at different scales of noise (it's fine to use the static Noise.instance because it has no changing state between runs of the program). The octaveMultiplier parameter should probably be no lower than 0.5f, but can be arbitrarily high if you're willing to spend much more time on generating detail only noticeable at very high zoom; normally 1f is fine and may even be too high for maps that don't require zooming.
      Parameters:
      initialSeed - the seed for the FlowRandom this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
      terrainRidgedNoise - an instance of a noise generator capable of 3D noise, usually Noise
      terrainBasicNoise - an instance of a noise generator capable of 3D noise, usually Noise
      heatNoise - an instance of a noise generator capable of 3D noise, usually Noise
      moistureNoise - an instance of a noise generator capable of 3D noise, usually Noise
      otherRidgedNoise - an instance of a noise generator capable of 3D noise, usually Noise
      octaveMultiplier - used to adjust the level of detail, with 0.5f at the bare-minimum detail and 1f normal
      alpha - one of the Tobler parameters; 0.0625f is the default and this can range from 0f to 1f at least
      kappa - one of the Tobler parameters; 2.5f is the default but 2f-5f range values are also often used
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(HyperellipticalWorldMap other)
      Copies the HyperellipticalWorldMap other to construct a new one that is exactly the same. References will only be shared to Noise classes.
      Parameters:
      other - a HyperellipticalWorldMap to copy
    • HyperellipticalWorldMap

      public HyperellipticalWorldMap(int width, int height, String serialized)
      Creates a new generator from the given serialized String, produced by stringSerialize(), but this also requires width and height that match the first two lines of the given String (in Base.BASE86). It is almost always easier to use recreateFromString(String) instead.
      Parameters:
      width - width of the map or maps to generate; must match the first line of the given String in Base.BASE86
      height - height of the map or maps to generate; must match the second line of the given String in Base.BASE86
      serialized - should have been produced by stringSerialize()
  • Method Details

    • stringSerialize

      public String stringSerialize()
      Serializes this generator's entire state to a String; it can be read back when creating a new instance of this type with HyperellipticalWorldMap(int, int, String) or (preferably) recreateFromString(String). Uses Base.BASE86 to represent values very concisely, but not at all readably. The String this produces tends to be very long because it includes several 2D arrays and a Region as Strings.
      Overrides:
      stringSerialize in class WorldMapGenerator
      Returns:
      a String that stores the entire state of this generator
    • recreateFromString

      public static HyperellipticalWorldMap recreateFromString(String data)
      Creates a new instance of this class from a serialized String produced by stringSerialize(). This can get the width and height from the String, which makes this probably preferable to using the constructor HyperellipticalWorldMap(int, int, String). This stores the last-generated map in this WorldMapGenerator, where it can be used by other code like a WorldMapView.
      Parameters:
      data - the output of stringSerialize()
      Returns:
      the map that was serialized, as a new generator
    • wrapX

      public int wrapX(int x, int y)
      Overrides:
      wrapX in class WorldMapGenerator
    • wrapY

      public int wrapY(int x, int y)
      Overrides:
      wrapY in class WorldMapGenerator
    • zoomOut

      public void zoomOut(int zoomAmount, int zoomCenterX, int zoomCenterY)
      Description copied from class: WorldMapGenerator
      Halves the resolution of the map and floats the area it covers repeatedly, halving zoomAmount times; the 2D arrays this uses keep their sizes. This version of zoomOut allows you to specify where the zoom should be centered, using the current coordinates (if the map size is 256x256, then coordinates should be between 0 and 255, and will refer to the currently used area and not necessarily the full world size).
      Only has an effect if you have previously zoomed in using WorldMapGenerator.zoomIn(int, int, int) or its overload.
      Overrides:
      zoomOut in class WorldMapGenerator
      Parameters:
      zoomCenterX - the center X position to zoom out from; if too close to an edge, this will stop moving before it would extend past an edge
      zoomCenterY - the center Y position to zoom out from; if too close to an edge, this will stop moving before it would extend past an edge
    • zoomIn

      public void zoomIn(int zoomAmount, int zoomCenterX, int zoomCenterY)
      Description copied from class: WorldMapGenerator
      Floats the resolution of the map and halves the area it covers repeatedly, doubling zoomAmount times; the 2D arrays this uses keep their sizes. This version of zoomIn allows you to specify where the zoom should be centered, using the current coordinates (if the map size is 256x256, then coordinates should be between 0 and 255, and will refer to the currently used area and not necessarily the full world size).
      Although there is no technical restriction on maximum zoom, zooming in more than 5 times (64x scale or greater) will make the map appear somewhat less realistic due to rounded shapes appearing more bubble-like and less like a normal landscape.
      Overrides:
      zoomIn in class WorldMapGenerator
      Parameters:
      zoomCenterX - the center X position to zoom in to; if too close to an edge, this will stop moving before it would extend past an edge
      zoomCenterY - the center Y position to zoom in to; if too close to an edge, this will stop moving before it would extend past an edge
    • project

      public com.github.yellowstonegames.grid.Coord project(float latitude, float longitude)
      Given a latitude and longitude in radians (the conventional way of describing points on a globe), this gets the (x,y) Coord on the map projection this generator uses that corresponds to the given lat-lon coordinates. If this generator does not represent a globe (if it is toroidal, for instance) or if there is no "good way" to calculate the projection for a given lat-lon coordinate, this returns null. This implementation never returns null. If this is a supported operation and the parameters are valid, this returns a Coord with x between 0 and WorldMapGenerator.width, and y between 0 and WorldMapGenerator.height, both exclusive. Automatically wraps the Coord's values using wrapX(int, int) and wrapY(int, int).
      Overrides:
      project in class WorldMapGenerator
      Parameters:
      latitude - the latitude, from -TrigTools.HALF_PI to TrigTools.HALF_PI
      longitude - the longitude, from 0f to TrigTools.PI2
      Returns:
      the point at the given latitude and longitude, as a Coord with x between 0 and WorldMapGenerator.width and y between 0 and WorldMapGenerator.height, or null if unsupported
    • regenerate

      protected void regenerate(int startX, int startY, int usedWidth, int usedHeight, float landMod, float heatMod, long stateA, long stateB)
      Specified by:
      regenerate in class WorldMapGenerator
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object