Interface IMap<TPoint>
An IMap maps 2D world coordinates to Grid coordinates and vice versa.
Most of the methods of this class are meant to be chained to the constructor.The last command in the chain is suaully a conversion to IMap3D, which converts the 2D coordinates to 3D for use in the game engine.
The order of chained calls sometimes make a difference.
The standard order is this: - set grid point transforms - set cell anchoring - set world transforms (such as translate, rotate) - do layout (using WithWindow) - convert to 3D
Transformations only apply to the world points returned and processed by the map, the grid contents is not transformed.
For example, applying scale to the map, will not scale the cells
Built-in 2D grids generally have associated built-in maps.See the Grid Index for the list.
You can also provide your own maps, either as implementations of IMap, or IMap3D.
[Version(1, 0, 0)]
public interface IMap<TPoint> : IGridToWorldMap<TPoint> where TPoint : IGridPoint<TPoint>
Type Parameters
TPoint
- Inherited Members
- Extension Methods
Properties
GridPointTransform
The transformation applied to points before they are returned from the map.
Func<TPoint, TPoint> GridPointTransform { get; }
Property Value
- Func<TPoint, TPoint>
InverseGridPointTransform
The transformation applied to points before they are processed by the map.
Func<TPoint, TPoint> InverseGridPointTransform { get; }
Property Value
- Func<TPoint, TPoint>
this[Vector2]
Gets a grid point given a world point.
TPoint this[Vector2 point] { get; }
Parameters
point
Vector2
Property Value
- TPoint
Methods
AnchorCellBottom()
Returns an IMap that anchors the grid cells to the bottom.
IMap<TPoint> AnchorCellBottom()
Returns
- IMap<TPoint>
AnchorCellBottomCenter()
Returns an IMap that anchors the grid cells to the bottom center.
IMap<TPoint> AnchorCellBottomCenter()
Returns
- IMap<TPoint>
AnchorCellBottomLeft()
Returns an IMap that anchors the grid cells to the bottom left.
IMap<TPoint> AnchorCellBottomLeft()
Returns
- IMap<TPoint>
AnchorCellBottomRight()
Returns an IMap that anchors the grid cells to the bottom right.
IMap<TPoint> AnchorCellBottomRight()
Returns
- IMap<TPoint>
AnchorCellCenter()
Returns an IMap that anchors the grid cells horizontally to the center.
IMap<TPoint> AnchorCellCenter()
Returns
- IMap<TPoint>
AnchorCellLeft()
Returns an IMap that anchors the grid cells to the left.
IMap<TPoint> AnchorCellLeft()
Returns
- IMap<TPoint>
AnchorCellMiddle()
Returns an IMap that anchors the grid cells vertically to the middle.
IMap<TPoint> AnchorCellMiddle()
Returns
- IMap<TPoint>
AnchorCellMiddleCenter()
Returns an IMap that anchors the grid cells to the middle center.
IMap<TPoint> AnchorCellMiddleCenter()
Returns
- IMap<TPoint>
AnchorCellMiddleLeft()
Returns an IMap that anchors the grid cells to the middle left.
IMap<TPoint> AnchorCellMiddleLeft()
Returns
- IMap<TPoint>
AnchorCellMiddleRight()
Returns an IMap that anchors the grid cells to the middle right.
IMap<TPoint> AnchorCellMiddleRight()
Returns
- IMap<TPoint>
AnchorCellRight()
Returns an IMap that anchors the grid cells to the right.
IMap<TPoint> AnchorCellRight()
Returns
- IMap<TPoint>
AnchorCellTop()
Returns an IMap that anchors the grid cells to the top.
IMap<TPoint> AnchorCellTop()
Returns
- IMap<TPoint>
AnchorCellTopCenter()
Returns an IMap that anchors the grid cells vertically to the top center.
IMap<TPoint> AnchorCellTopCenter()
Returns
- IMap<TPoint>
AnchorCellTopLeft()
Returns an IMap that anchors the grid cells vertically to the top left.
IMap<TPoint> AnchorCellTopLeft()
Returns
- IMap<TPoint>
AnchorCellTopRight()
Returns an IMap that anchors the grid cells vertically to the top right.
IMap<TPoint> AnchorCellTopRight()
Returns
- IMap<TPoint>
CalcAnchorBottomLeft(IGridSpace<TPoint>)
Vector2 CalcAnchorBottomLeft(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcAnchorDimensions(IGridSpace<TPoint>)
Vector2 CalcAnchorDimensions(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcBottomLeft(IGridSpace<TPoint>)
Vector2 CalcBottomLeft(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
CalcGridDimensions(IGridSpace<TPoint>)
Vector2 CalcGridDimensions(IGridSpace<TPoint> grid)
Parameters
grid
IGridSpace<TPoint>
Returns
FlipXY()
Returns an IMap where grid cells positioned with x-and y-coordinates (in world space) flipped.
IMap<TPoint> FlipXY()
Returns
- IMap<TPoint>
GetAnchorTranslation()
Vector2 GetAnchorTranslation()
Returns
GetCellDimensions()
Vector2 GetCellDimensions()
Returns
GetCellDimensions(TPoint)
Vector2 GetCellDimensions(TPoint point)
Parameters
point
TPoint
Returns
GridToWorld(TPoint)
This method maps a grid point to a world point.
Vector2 GridToWorld(TPoint worldPoint)
Parameters
worldPoint
TPoint
Returns
RawWorldToGrid(Vector2)
This method maps a world point to a grid point without making any compensation based on the anchoring.
This method should be used for calculations in maps, rather than the index methods. (The index methods do the anchor compensation.If you use that method instead of this one internally, you may compensate more than one time.
TPoint RawWorldToGrid(Vector2 worldPoint)
Parameters
worldPoint
Vector2
Returns
- TPoint
ReflectAboutX()
Returns an IMap where grid cells are reflected about the X-point in world space.
IMap<TPoint> ReflectAboutX()
Returns
- IMap<TPoint>
ReflectAboutY()
Returns an IMap where grid cells are reflected about the Y-point in world space.
IMap<TPoint> ReflectAboutY()
Returns
- IMap<TPoint>
Rotate(float)
Returns an IMap where grid cells are rotated about the origin by the given angle.
IMap<TPoint> Rotate(float angle)
Parameters
angle
float
Returns
- IMap<TPoint>
Rotate180()
Returns an IMap where grid cells are scaled about the origin by 180 degrees.
IMap<TPoint> Rotate180()
Returns
- IMap<TPoint>
Rotate90()
Returns an IMap where grid cells are rotated about the origin by 90 degrees.
IMap<TPoint> Rotate90()
Returns
- IMap<TPoint>
RotateAround(float, Vector2)
Returns an IMap where grid cells are rotated about the given point by the given angle.
IMap<TPoint> RotateAround(float angle, Vector2 point)
Parameters
Returns
- IMap<TPoint>
Scale(float)
Returns an IMap where grid cells are scaled by factor.
IMap<TPoint> Scale(float factor)
Parameters
factor
float
Returns
- IMap<TPoint>
Scale(float, float)
Returns an IMap where grid cells are scaled by the factors in each direction.
IMap<TPoint> Scale(float factorX, float factorY)
Parameters
Returns
- IMap<TPoint>
Scale(Vector2)
IMap<TPoint> Scale(Vector2 factor)
Parameters
factor
Vector2
Returns
- IMap<TPoint>
SetGridPointTransforms(Func<TPoint, TPoint>, Func<TPoint, TPoint>)
IMap<TPoint> SetGridPointTransforms(Func<TPoint, TPoint> coordinateTransformation, Func<TPoint, TPoint> inverseCoordinateTransformation)
Parameters
Returns
- IMap<TPoint>
To3DXY()
The same as To3DX(float z), but with z set to 0.
IMap3D<TPoint> To3DXY()
Returns
- IMap3D<TPoint>
To3DXY(float)
Returns a IMap3D which maps a grid point to Vector3 instead of Vector2. The vector3 is the same as the Vector2 that this map would return, with the
z set to the given value.
IMap3D<TPoint> To3DXY(float z)
Parameters
z
float
Returns
- IMap3D<TPoint>
To3DXZ()
The same as To3DZ(float y), but with y set to 0.
IMap3D<TPoint> To3DXZ()
Returns
- IMap3D<TPoint>
To3DXZ(float)
Returns a IMap3D which maps a grid point to Vector3 instead of Vector2. The vector3 is the same as the Vector2 that this map would return, with z of the Vector3 corresponding to y of the Vector2, and with the y set to the given value.
IMap3D<TPoint> To3DXZ(float y)
Parameters
y
float
Returns
- IMap3D<TPoint>
Translate(float, float)
Returns an IMap where grid cells are translated by the give amounts.
IMap<TPoint> Translate(float offsetX, float offsetY)
Parameters
Returns
- IMap<TPoint>
Translate(Vector2)
Returns an IMap where grid cells are translated by the give amount.
IMap<TPoint> Translate(Vector2 offset)
Parameters
offset
Vector2
Returns
- IMap<TPoint>
TranslateX(float)
Returns an IMap where grid cells are translated by the give amount.
IMap<TPoint> TranslateX(float offsetX)
Parameters
offsetX
float
Returns
- IMap<TPoint>
TranslateY(float)
Returns an IMap where grid cells are translated by the give amount.
IMap<TPoint> TranslateY(float offsetY)
Parameters
offsetY
float
Returns
- IMap<TPoint>
WithWindow(Rect)
Returns a WindowedMap based on this map that can be used to lay the grid out in a window.
WindowedMap<TPoint> WithWindow(Rect window)
Parameters
window
Rect
Returns
- WindowedMap<TPoint>
Examples
For example:
var map = new RectMap(cellDimensions)
.WithWindow(screenRect)
.AlignMiddleCenter();