liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

lash_game_standard.h (8467B)


      1 #ifndef LASH_GAME_STANDARD_H_
      2 #define LASH_GAME_STANDARD_H_
      3 
      4 #define LASH_GAME_GRAVITY_EARTH 9.8
      5 #define LASH_GAME_ATMOSPHERE_EARTH 101325
      6 
      7 typedef struct lash_game_coords_t {
      8 	unsigned int x;
      9 	unsigned int y;
     10 } lash_game_coords_t;
     11 
     12 typedef struct lash_game_coords_t lash_game_coords_cartesian_t;
     13 
     14 typedef struct lash_game_coords_float_t {
     15 	double x;
     16 	double y;
     17 } lash_game_coords_float_t;
     18 
     19 typedef unsigned long int lash_game_map_index_t;
     20 
     21 typedef struct lash_game_line_t {
     22 	double m;
     23 	double c;
     24 } lash_game_line_t;
     25 
     26 enum lash_anglespan_compare {
     27 	LASH_ANGLESPAN_NONE,
     28 	LASH_ANGLESPAN_MIN,
     29 	LASH_ANGLESPAN_MAX,
     30 	LASH_ANGLESPAN_BOTH,
     31 	LASH_ANGLESPAN_SPLIT
     32 };
     33 
     34 #ifdef __cplusplus 
     35 extern "C" {
     36 #endif
     37 unsigned char lash_getQuadrant(const float rads);
     38 unsigned char lash_getQuadrantFromCartesian(const int dx, const int dy);
     39 float lash_cartesianMagnitude(const int target_x, const int target_y, const int source_x, const int source_y);
     40 float lash_getCartesianMagnitude(const int target_x, const int target_y, const int source_x, const int source_y);
     41 int lash_cartesianToPolar(const int source_x, const int source_y, const int target_x, const int target_y, float *radians, float *radius, const int inv_x, const int inv_y);
     42 int lash_polarToCartesian(const float radians, const float radius, const int source_x, const int source_y, int *target_x, int *target_y);
     43 enum lash_anglespan_compare lash_compareAngleSpan(float old_rad_min, float old_rad_max, float new_rad_min, float new_rad_max);
     44 int lash_getContainedAngle(const double x, const double y, const double m, const double w_container, const double h_container, const int buf_top, const int buf_right, const int buf_bottom, const int buf_left, double *angle_min, double *angle_max, const int include_dcoords, double *x_min, double *y_min, double *x_max, double *y_max);
     45 int lash_getContainedAngleOnly(const double x, const double y, double m, const double w_container, const double h_container, const int buf_top, const int buf_right, const int buf_bottom, const int buf_left, double *angle_min, double *angle_max);
     46 int lash_cartesianToIndex(unsigned long int *index, const unsigned int *w, const unsigned int *h, unsigned int *unit_size, const lash_game_coords_t *coords);
     47 int lash_indexToCartesian(lash_game_coords_cartesian_t *coords, const unsigned int *w, const unsigned int *h, unsigned int *unit_size, const lash_game_map_index_t *index);
     48 int lash_cartesianToFloat(lash_game_coords_float_t *coords_float, const unsigned int *w, const unsigned int *h, const lash_game_coords_cartesian_t *coords_cartesian);
     49 int lash_getManhattanMagnitudeFromCartesian(const lash_game_coords_t targetcoords, const lash_game_coords_t sourcecoords);
     50 int lash_linearIntersect(const lash_game_line_t a, const lash_game_line_t b, lash_game_coords_float_t *coords);
     51 int lash_cartesianToLinear(const lash_game_coords_float_t src, const lash_game_coords_float_t target, lash_game_line_t *result);
     52 float lash_distanceToRadians(const float distance, const float radius);
     53 float lash_normalizeRadians(const float radians);
     54 float lash_normalizeQuadrantRadians(float radians);
     55 void lash_collisionSurfaceDeflectSimple(float *objvel, float *objrad, const float surfacerad, float bounce);
     56 char lash_collisionCheckCircleLine(const lash_game_coords_float_t circle_centre, const float circle_radius, const lash_game_line_t slope, lash_game_coords_float_t *intersect_coords_1, lash_game_coords_float_t *intersect_coords_2);
     57 char lash_collisionCircleLine(const lash_game_coords_float_t circle_centre, const float circle_radius, const lash_game_line_t slope, lash_game_coords_float_t *intersect_coords_1, lash_game_coords_float_t *intersect_coords_2);
     58 
     59 #ifdef __cplusplus 
     60 }
     61 #endif
     62 
     63 #endif // LASH_GAME_STANDARD_H_
     64 
     65 
     66 
     67 /**
     68  * \file lash_game_standard.h
     69  * \brief LASH Game movement angle routines
     70  * 
     71  * \todo rename lash_game_map_index_t to lash_game_index_t, as it does not belong to map
     72  */
     73  
     74 /**
     75  * \var enum lash_anglespan_compare
     76  * \brief Specifies what action should be taken to transform a compared anglespan
     77  * \sa lashCompareAngleSpan
     78  */
     79  
     80 /**
     81  * \fn int lash_getContainedAngle(int x, int y, double m, int w_container, int h_container, int buf_top, int buf_right, int buf_bottom, int buf_left, double *angle_min, double *angle_max, int include_dcoords, int *x_min, int *y_min, int *x_max, int *y_max)
     82  * \brief Determine movement angle contained within world bounds
     83  * \param x the x position in the world
     84  * \param y the y position in the world
     85  * \param m the movement magnitude to check against
     86  * \param w_container the width of the world
     87  * \param h_container the height of the world
     88  * \param buf_top max proximity to world top edge
     89  * \param buf_right max proximity to world right edge
     90  * \param buf_bottom max proximity to world bottom edge
     91  * \param buf_left max proximity to world left edge
     92  * \param *angle_min resulting minimum movement angle in radians
     93  * \param *angle_max resulting maximum movement angle in radians
     94  * \param include_dcoords whether or not to calculate the intersection between the extreme movement vectors and the game world edges
     95  * \param *x_min resulting intersection point x coordinate of game world for the minimum movement angle radian
     96  * \param *y_min resulting intersection point y coordinate of game world for the minimum movement angle radian
     97  * \param *x_max resulting intersection point x coordinate of game world for the maximum movement angle radian
     98  * \param *y_max resulting intersection point y coordinate of game world for the maximum movement angle radian
     99  *   
    100  * From a position point and a movement magnitude, this function yields an angle span within which movement of the given magnitude will be kept within the world bounds.
    101  * 
    102  * Optionally, the coordinates of the intersection points to the game world can also be calculated. In this case they will be stored in the variables passed in the last four parameters.
    103  * These variables will be left unchanged if 0 is passed for include_dcoords
    104  * 
    105  * \todo Return zero for both radians when movement in any case is out of world bounds (no vector is possible), or if position is out of bounds
    106  * 
    107  */
    108  
    109 /**
    110  * \fn enum lash_anglespan_compare lash_compareAngleSpan(float old_rad_min, float old_rad_max, float new_rad_min, float new_rad_max)
    111  * \brief Contiguous angle spans from two angles
    112  * \param old_rad_min the old span minimum radian
    113  * \param old_rad_min the old span maxumum radian
    114  * \param old_rad_min the new span minimum radian
    115  * \param old_rad_min the new span maximum radian
    116  * 
    117  * Compares the span of two angles, and if they overlap returns which transformation should be made to reduce them to one contiguous span:
    118  * - If the new span encloses the MINIMUM radian of the old span, then the old minimum should be set to the new minimum
    119  * - If the new span encloses the MAXIMUM radian of the old span, then the old maximum should be set to the new maximum
    120  * - If the new span encloses the WHOLE of the old span, then the old span should be replaced by the new span
    121  * - If the new span is enclosed by the WHOLE of the old span, no change should occur
    122  * - If the new span is outside of the old span, no change should occur
    123  * 
    124  * \todo can never be LASH_ANGLESPAN_BOTH. BOTH should be enclosing the whole span, and should lead to deletion of the old span
    125  * 
    126  */
    127 
    128 /**
    129  * \fn int lash_cartesianToIndex(unsigned long int *index, unsigned int *w, unsigned int *h, lash_game_coords_t *coords)
    130  * \brief Get the linear index of a cartesian coordinate pair
    131  * 
    132  * \param *index pointer to variable holding the resulting index
    133  * \param *w the width of the coordinate system
    134  * \param *h the height of the coordinate system
    135  * \param *coords the coordinate pair to calculate
    136  * 
    137  * If the coordinate pair is out of bounds, the variable the index parameter points to will be left unchanged, and the function will return 1
    138  * 
    139  * \see lashCartesianToIndex
    140  * 
    141  */
    142 
    143 /**
    144  * \fn int lash_indexToCartesian(lash_game_coords_t *coords, unsigned int *w, unsigned int *h, unsigned long int *index)
    145  * \brief Get the coordinate pair from a linear index
    146  * 
    147  * \param *coords pointer to the struct the coordinate pair will be stored
    148  * \param *w the width of the coordinate system
    149  * \param *h the height of the coordinate system
    150  * \param *index to calculate
    151  * 
    152  * If the index is out of bounds, the variable the index parameter points to will be left unchanged, and the function will return 1
    153  * 
    154  * \see lashCartesianToIndex
    155  * 
    156  */
    157