Subversion Repositories Games.Carmageddon

Rev

Rev 18 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef MACROS_H
  2. #define MACROS_H
  3.  
  4. #define VEHICLE_TYPE_FROM_ID(id) ((tVehicle_type)(id >> 8))
  5. #define VEHICLE_INDEX_FROM_ID(id) ((id)&0x00ff)
  6.  
  7. //#define VEC3_TRANSLATE(mat) (*(br_vector3*)(&mat->m[3][0]))
  8.  
  9. #define SLOBYTE(x) (*((signed char*)&(x)))
  10.  
  11. #define STR_STARTS_WITH(haystack, needle) strncmp(haystack, needle, strlen(needle))
  12. #define STR_ENDS_WITH(haystack, needle) strcmp(haystack + strlen(haystack) - strlen(needle), needle)
  13.  
  14. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  15. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  16. #define CONSTRAIN_BETWEEN(lowerbound, upperbound, val) (MIN((upperbound), MAX((lowerbound), (val))))
  17.  
  18. #define COUNT_OF(array) (sizeof((array)) / sizeof((array)[0]))
  19. #define LEN(array) (sizeof((array)) / sizeof((array)[0]))
  20.  
  21. #define DEG_TO_RAD(degrees) ((degrees)*3.141592653589793 / 180.0)
  22.  
  23. #define V11MODEL(model) (((v11model*)model->prepared))
  24. #define CAR(c) ((tCar_spec*)c)
  25.  
  26. #define Vector3Div(v1, v2, v3)                \
  27.     do {                                      \
  28.         (v1)->v[0] = (v2)->v[0] / (v3)->v[0]; \
  29.         (v1)->v[1] = (v2)->v[1] / (v3)->v[1]; \
  30.         (v1)->v[2] = (v2)->v[2] / (v3)->v[2]; \
  31.     } while (0)
  32.  
  33. #define Vector3DistanceSquared(V1, V2) \
  34.     ((((V1)->v[0] - (V2)->v[0])) * (((V1)->v[0] - (V2)->v[0])) + (((V1)->v[1] - (V2)->v[1])) * (((V1)->v[1] - (V2)->v[1])) + (((V1)->v[2] - (V2)->v[2])) * (((V1)->v[2] - (V2)->v[2])))
  35.  
  36. #define Vector3Distance(V1, V2) sqrtf(Vector3DistanceSquared((V1), (V2)))
  37. #define Vector3AreEqual(V1, V2) \
  38.     ((V1)->v[0] == (V2)->v[0] && (V1)->v[1] == (V2)->v[1] && (V1)->v[2] == (V2)->v[2])
  39. #define Vector3EqualElements(V, A, B, C) \
  40.     ((V)->v[0] == (A) && (V)->v[1] == (B) && (V)->v[2] == (C))
  41. #define Vector3IsZero(V) Vector3EqualElements((V), 0.f, 0.f, 0.f)
  42. #define Vector3AddFloats(V1, V2, X, Y, Z) \
  43.     do { (V1)->v[0] = (V2)->v[0] + (X); (V1)->v[1] = (V2)->v[1] + (Y);  (V1)->v[2] = (V2)->v[2] + (Z); } while (0)
  44. #define SwapValuesUsingTemporary(V1, V2, T) \
  45.     do {                                    \
  46.         (T) = (V1);                         \
  47.         (V1) = (V2);                        \
  48.         (V2) = (T);                         \
  49.     } while (0)
  50.  
  51. #endif
  52.