Hexmap Reference Manual | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
#include <hexmap.h> enum HexDirection; typedef HexDirectionSimple; #define HEX_DIRECTION_SIMPLE_GET_OPPOSITE(dir) #define HEX_DIRECTION_SIMPLE_ROTATE_RIGHT(dir) #define HEX_DIRECTION_SIMPLE_ROTATE_LEFT(dir) #define HEX_DIRECTION_SIMPLE_NUM (i) #define HEX_DIRECTION_SIMPLE_GET_MOD (dir) void hex_direction_simple_get_hex (HexDirectionSimple direction, gint distance, gint old_x, gint old_y, gint *new_x, gint *new_y); HexDirection hex_direction_rotate (HexDirection direction, gint rot); typedef HexOffset; void hex_offset_get_hex (HexOffset *offset, gint old_x, gint old_y, gint *new_x, gint *new_y); void hex_offset_rotate (HexOffset *offset, gint rot); void hex_offset_add (HexOffset *off1, HexOffset *off2); gboolean hex_offset_equal (HexOffset *off1, HexOffset *off2); guint hex_offset_get_distance (HexOffset *offset); void hexes_get_offset (gint x1, gint y1, gint x2, gint y2, HexOffset *offset); guint hexes_get_distance (gint x1, gint y1, gint x2, gint y2); |
This section describes HexDirection, HexDirectionSimple, and HexOffset, which are useful for describing the orientations and relative positions of things on the grid. A function for calculating the distance between hexes is also included.
typedef enum { HEX_DIRECTION_N = 0x1, HEX_DIRECTION_NE = 0x2, HEX_DIRECTION_SE = 0x4, HEX_DIRECTION_S = 0x8, HEX_DIRECTION_SW = 0x10, HEX_DIRECTION_NW = 0x20, HEX_DIRECTION_MASK = 0x3f, HEX_DIRECTION_NONE = 0 } HexDirection; |
A set of bit flags for describing the faces of a hex
One of the six simple flags in HexDirection (i.e. one of N, NE, SE, S, SW, or NW) or HEX_DIRECTION_NONE
#define HEX_DIRECTION_SIMPLE_GET_OPPOSITE(dir) |
returns the opposite direction to dir
#define HEX_DIRECTION_SIMPLE_ROTATE_RIGHT(dir) |
returns the direction to the right of dir
#define HEX_DIRECTION_SIMPLE_ROTATE_LEFT(dir) |
returns the direction to the left of dir
#define HEX_DIRECTION_SIMPLE_NUM(i) |
converts an integer to a direction, with 0 being HEX_DIRECTION_N, and increasing integers corresponding to clockwise rotation
#define HEX_DIRECTION_SIMPLE_GET_MOD(dir) |
returns the modulus of dir, where dir is (1 << modulus)
a HexDirectionSimple, excluding HEX_DIRECTION_NONE
void hex_direction_simple_get_hex (HexDirectionSimple direction, gint distance, gint old_x, gint old_y, gint *new_x, gint *new_y); |
Find the hex which lies a certain distance in a certain direction from a given hex
a HexDirectionSimple, pointing from the old to the new hex
the distance from the old to the new hex
the x coordinate of the old hex
the y coordinate of the old hex
a location to return the x coordinate of the new hex
a location to return the y coordinate of the new hex
HexDirection hex_direction_rotate (HexDirection direction, gint rot); |
rotate a HexDirection
the angle to rotate the direction. Positive is clockwise, and a rotation of 6 returns the original direction
the rotated HexDirection
A structure representing an offset on the grid. Essentially a two dimensional vector represented in grid coordinates
void hex_offset_get_hex (HexOffset *offset, gint old_x, gint old_y, gint *new_x, gint *new_y); |
Find the hex which lies a certain offset from a given hex
the offset from the old to the new hex
the x coordinate of the old hex
the y coordinate of the old hex
a location to return the x coordinate of the new hex
a location to return the y coordinate of the new hex
void hex_offset_rotate (HexOffset *offset, gint rot); |
rotate a HexOffset
the angle to rotate the offset. Positive is clockwise, and a rotation of 6 returns the original offset
void hex_offset_add (HexOffset *off1, HexOffset *off2); |
adds off1 and off2, storing the result in off1
gboolean hex_offset_equal (HexOffset *off1, HexOffset *off2); |
checks whether off1 and off2 are equivalent
TRUE if the offsets are equal, FALSE otherwise
guint hex_offset_get_distance (HexOffset *offset); |
find the length of a HexOffset
the minimum distance, in hexes, from one end of offset to the other
void hexes_get_offset (gint x1, gint y1, gint x2, gint y2, HexOffset *offset); |
Find the offset between two hexes
the x coordinate of the first hex
the y coordinate of the first hex
the x coordinate of the second hex
the y coordinate of the second hex
a location to return the offset from the first hex to the second
guint hexes_get_distance (gint x1, gint y1, gint x2, gint y2); |
Find the minimum distance in hexes between two hexes
the x coordinate of the first hex
the y coordinate of the first hex
the x coordinate of the second hex
the y coordinate of the second hex
the distance