34 #define M_PI 3.14159265358979323846
37 #define M_PI_2 1.57079632679489661923
40 #define EQUAL_EPSILON 0.001
45 #define EQUAL2(a,b,epsilon) (fabs((a)-(b))<epsilon)
48 #define Q_ftol(f) (long) (f)
50 #define torad (M_PI/180.0f)
51 #define todeg (180.0f/M_PI)
59 #define AXIS_FORWARD 0
65 #define SIN_ALPHA 0.39875
66 #define COS_ALPHA 0.91706
69 #define CENTER_LAT 0.0
84 #define BASE_DIRECTIONS 4
87 #define PATHFINDING_DIRECTIONS 40
88 #define CORE_DIRECTIONS 8
89 #define FLYING_DIRECTIONS 16
100 #define VecToPos(v, p) ( \
101 (p)[0] = ((int)(v)[0] + MAX_WORLD_WIDTH) / UNIT_SIZE, \
102 (p)[1] = ((int)(v)[1] + MAX_WORLD_WIDTH) / UNIT_SIZE, \
103 (p)[2] = std::min((PATHFINDING_HEIGHT - 1), ((int)(v)[2] / UNIT_HEIGHT)) \
110 #define PosToVec(p, v) ( \
111 (v)[0] = ((int)(p)[0] - GRID_WIDTH) * UNIT_SIZE + UNIT_SIZE / 2, \
112 (v)[1] = ((int)(p)[1] - GRID_WIDTH) * UNIT_SIZE + UNIT_SIZE / 2, \
113 (v)[2] = (int)(p)[2] * UNIT_HEIGHT + UNIT_HEIGHT / 2 \
207 mins[0] = std::max(
mins[0] - byVal, 0);
208 mins[1] = std::max(
mins[1] - byVal, 0);
237 #define DV_FLAGS_BIT_SHIFT 4
238 #define DV_DIR_BIT_SHIFT 8
239 #define DV_Z_BIT_MASK 0x0007
240 #define DV_FLAGS_BIT_MASK 0x00F0
241 #define DV_DIR_BIT_MASK 0xFF00
243 #define DV_FLAG_AUTOCROUCH 0x01
244 #define DV_FLAG_AUTOCROUCHED 0x02
245 #define DV_FLAG_AUTODIVE 0x04
247 #define makeDV(dir, z) (((dir) << DV_DIR_BIT_SHIFT) | ((z) & DV_Z_BIT_MASK))
248 #define setDVz(dv, z) (((dv) & (~DV_Z_BIT_MASK)) | ((z) & DV_Z_BIT_MASK))
249 #define getDVdir(dv) ((dv) >> DV_DIR_BIT_SHIFT)
250 #define getDVflags(dv) (((dv) & DV_FLAGS_BIT_MASK) >> DV_FLAGS_BIT_SHIFT)
251 #define getDVz(dv) ((dv) & DV_Z_BIT_MASK)
253 #define PosAddDV(p, crouch, dv) ((p)[0]+=dvecs[getDVdir(dv)][0], (p)[1]+=dvecs[getDVdir(dv)][1], (p)[2]=getDVz(dv), (crouch)+=dvecs[getDVdir(dv)][3])
254 #define PosSubDV(p, crouch, dv) ((p)[0]-=dvecs[getDVdir(dv)][0], (p)[1]-=dvecs[getDVdir(dv)][1], (p)[2]=getDVz(dv), (crouch)-=dvecs[getDVdir(dv)][3])
257 #define AngleToDV(x) (AngleToDir(x) << DV_DIR_BIT_SHIFT)
302 float LerpAngle(
float a1,
float a2,
float frac);
311 void gaussrand(
float* gauss1,
float* gauss2);
void set(const AABB &aabb)
void set(const pos3_t mini, const pos3_t maxi)
#define VectorCopy(src, dest)
double GetDistanceOnGlobe(const vec2_t pos1, const vec2_t pos2)
Calculate distance on the geoscape.
void VectorMidpoint(const vec3_t point1, const vec3_t point2, vec3_t midpoint)
Calculates the midpoint between two vectors.
void VectorRotate(vec3_t m[3], const vec3_t va, vec3_t vb)
Rotate a vector with a rotation matrix.
const byte dvleft[CORE_DIRECTIONS]
void VectorNormalizeFast(vec3_t v)
fast vector normalize routine that does not check to make sure that length != 0, nor does it return l...
void GLMatrixAssemble(const vec3_t origin, const vec3_t angles, float *matrix)
Builds an opengl translation and rotation matrix.
GridBox(const ipos3_t mini, const ipos3_t maxi)
void expandXY(const int byVal)
expand the box in four directions, but clip them to the maximum boundaries
void GLPositionTransform(const float m[16], const vec3_t in, vec3_t out)
Transform position (xyz) vector by OpenGL rules.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
void TangentVectors(const vec3_t normal, const vec3_t sdir, const vec3_t tdir, vec4_t tangent, vec3_t binormal)
Projects the normalized directional vectors on to the normal's plane. The fourth component of the res...
bool FrustumVis(const vec3_t origin, int dir, const vec3_t point)
Checks whether a point is visible from a given position.
void CalculateMinsMaxs(const vec3_t angles, const AABB &relBox, const vec3_t origin, AABB &absBox)
Calculates the bounding box in absolute coordinates, also for rotating objects. WARNING: do not use t...
static const vec3_t scale
int VectorCompareEps(const vec3_t v1, const vec3_t v2, float epsilon)
Compare two vectors that may have an epsilon difference but still be the same vectors.
const vec4_t dvecs[PATHFINDING_DIRECTIONS]
void VectorMix(const vec3_t v1, const vec3_t v2, const float mix, vec3_t out)
Calculate a position on v1 v2 line.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
void Orthogonalize(vec3_t v1, const vec3_t v2)
Grahm-Schmidt orthogonalization.
void VecToPolar(const vec3_t v, vec2_t a)
Converts vector coordinates into polar coordinates.
bool Q_IsPowerOfTwo(int i)
Checks whether i is power of two value.
float VectorAngleBetween(const vec3_t vec1, const vec3_t vec2)
Calculates the angle (in radians) between the two given vectors.
void VectorClampMA(vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc)
void VectorCalcMinsMaxs(const vec3_t center, const vec3_t size, vec3_t mins, vec3_t maxs)
Calculates a bounding box from a center and a size.
float AngleNormalize180(float angle)
returns angle normalized to the range [-180 < angle <= 180]
vec_t VectorNormalize(vec3_t v)
Calculate unit vector for a given vec3_t.
const byte dvright[CORE_DIRECTIONS]
GridBox(const pos3_t mini, const pos3_t maxi)
const float dvecsn[CORE_DIRECTIONS][2]
vec_t ColorNormalize(const vec3_t in, vec3_t out)
void VectorCreateRotationMatrix(const vec3_t angles, vec3_t matrix[3])
float frand(void)
Return random values between 0 and 1.
vec_t Q_rint(const vec_t in)
Round to nearest integer.
void MatrixMultiply(const vec3_t a[3], const vec3_t b[3], vec3_t c[3])
Multiply 3*3 matrix by 3*3 matrix.
#define PATHFINDING_WIDTH
absolute max
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle...
bool VectorNearer(const vec3_t v1, const vec3_t v2, const vec3_t comp)
Checks whether the given vector v1 is closer to comp as the vector v2.
float LerpAngle(float a1, float a2, float frac)
Returns the angle resulting from turning fraction * angle from angle1 to angle2.
void PerpendicularVector(vec3_t dst, const vec3_t src)
Finds a vector perpendicular to the source vector.
#define PATHFINDING_DIRECTIONS
void VectorMA(const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector)
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb)
void GLVectorTransform(const float m[16], const vec4_t in, vec4_t out)
Multiply 4*4 matrix by 4d vector.
void MatrixTranspose(const vec3_t m[3], vec3_t t[3])
Transposes m and stores the result in t.
void gaussrand(float *gauss1, float *gauss2)
generate two gaussian distributed random numbers with median at 0 and stdev of 1
Defined CONSTANTS (Macros are elsewhere)
#define VecToPos(v, p)
Map boundary is +/- MAX_WORLD_WIDTH - to get into the positive area we add the possible max negative ...
float AngleNormalize360(float angle)
returns angle normalized to the range [0 <= angle < 360]
GridBox(const AABB &aabb)
bool RayIntersectAABB(const vec3_t start, const vec3_t end, const AABB &aabb)
void VecToAngles(const vec3_t vec, vec3_t angles)
Converts a vector to an angle vector.
void clipToMaxBoundaries()
void AddPointToBounds(const vec3_t v, vec3_t mins, vec3_t maxs)
If the point is outside the box defined by mins and maxs, expand the box to accommodate it...
float crand(void)
Return random values between -1 and 1.
void setFromMapBounds(const vec3_t mini, const vec3_t maxi)
Set the box correctly if the maxs value is the upper corner of a cell. VecToPos considers the upper b...
#define PATHFINDING_HEIGHT
15 max, adjusting above 8 will require a rewrite to the DV code
void ClearBounds(vec3_t mins, vec3_t maxs)
Sets mins and maxs to their starting points before using AddPointToBounds.
void PolarToVec(const vec2_t a, vec3_t v)
Converts longitude and latitude to a 3D vector in Euclidean coordinates.
const vec3_t & getMins() const
void RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
Rotate a point around a given vector.
vec_t VectorNormalize2(const vec3_t v, vec3_t out)
Calculated the normal vector for a given vec3_t.
void GLMatrixMultiply(const float a[16], const float b[16], float c[16])
Multiply 4*4 matrix by 4*4 matrix.
const float directionAngles[CORE_DIRECTIONS]
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
void VectorRotatePoint(vec3_t point, vec3_t matrix[3])
static const GridBox EMPTY
short dvec_t
The direction vector tells us where the actor came from (in his previous step). The pathing table hol...
Cross-platform type definitions.
void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross)
binary operation on vectors in a three-dimensional space
QGL_EXTERN int GLboolean GLfloat * v
const vec3_t & getMaxs() const
void VectorInverse(vec3_t v)
Inverse a vector.
A simple line between two points.