31#define logf(x) ((float)log((double)(x)))
40#define RT2 0.70710678118654752440084436210485
102const float dvecsn[
CORE_DIRECTIONS][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {
RT2,
RT2}, {-
RT2, -
RT2}, {-
RT2,
RT2}, {
RT2, -
RT2} };
107#define DIRECTION_EAST 0
108#define DIRECTION_WEST 1
109#define DIRECTION_NORTH 2
110#define DIRECTION_SOUTH 3
111#define DIRECTION_NORTHEAST 4
112#define DIRECTION_SOUTHWEST 5
113#define DIRECTION_NORTHWEST 6
114#define DIRECTION_SOUTHEAST 7
144 static const int anglesToDV[8] = {0, 4, 2, 6, 1, 5, 3, 7};
145 return anglesToDV[angle];
149 Com_Printf(
"Error in AngleToDV: shouldn't have reached this line\n");
159 return floor(in + 0.5);
174 const double latitude1 = pos1[1] *
torad;
175 const double latitude2 = pos2[1] *
torad;
176 const double deltaLongitude = (pos1[0] - pos2[0]) *
torad;
179 distance = cos(latitude1) * cos(latitude2) * cos(deltaLongitude) + sin(latitude1) * sin(latitude2);
180 distance = std::min(std::max(-1.0, distance), 1.0);
181 distance = acos(distance) *
todeg;
183 assert(distance >= 0.0);
202 if (
EQUAL(max, 0.0f)) {
245 const float ilength = 1.0f /
length;
246 out[0] =
v[0] * ilength;
247 out[1] =
v[1] * ilength;
248 out[2] =
v[2] * ilength;
263 outVector[0] = veca[0] +
scale * vecb[0];
264 outVector[1] = veca[1] +
scale * vecb[1];
265 outVector[2] = veca[2] +
scale * vecb[2];
273 for (
i = 0;
i < 3;
i++)
274 if (veca[
i] > 4094.0)
276 else if (veca[
i] < -4094.0)
280 for (
i = 0;
i < 3;
i++) {
281 const float test = veca[
i] +
scale * vecb[
i];
282 if (test < -4095.0f) {
283 const float newScale = (-4094.0 - veca[
i]) / vecb[
i];
284 if (fabs(newScale) < fabs(
scale))
286 }
else if (test > 4095.0f) {
287 const float newScale = (4094.0 - veca[
i]) / vecb[
i];
288 if (fabs(newScale) < fabs(
scale))
306 c[0][0] = a[0][0] * b[0][0] + a[1][0] * b[0][1] + a[2][0] * b[0][2];
307 c[0][1] = a[0][1] * b[0][0] + a[1][1] * b[0][1] + a[2][1] * b[0][2];
308 c[0][2] = a[0][2] * b[0][0] + a[1][2] * b[0][1] + a[2][2] * b[0][2];
310 c[1][0] = a[0][0] * b[1][0] + a[1][0] * b[1][1] + a[2][0] * b[1][2];
311 c[1][1] = a[0][1] * b[1][0] + a[1][1] * b[1][1] + a[2][1] * b[1][2];
312 c[1][2] = a[0][2] * b[1][0] + a[1][2] * b[1][1] + a[2][2] * b[1][2];
314 c[2][0] = a[0][0] * b[2][0] + a[1][0] * b[2][1] + a[2][0] * b[2][2];
315 c[2][1] = a[0][1] * b[2][0] + a[1][1] * b[2][1] + a[2][1] * b[2][2];
316 c[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2];
328 matrix[3] = matrix[7] = matrix[11] = 0.0;
332 AngleVectors(angles, &matrix[0], &matrix[4], &matrix[8]);
352 for (
int j = 0; j < 4; j++) {
354 for (
int i = 0;
i < 4;
i++)
355 c[
i + k] = a[
i] * b[k] + a[
i + 4] * b[k + 1] + a[
i + 8] * b[k + 2] + a[
i + 12] * b[k + 3];
368 for (
int i = 0;
i < 4;
i++)
369 out[
i] =
m[
i] * in[0] +
m[
i + 4] * in[1] +
m[
i + 8] * in[2] +
m[
i + 12] * in[3];
382 for (
int i = 0;
i < 3;
i++)
383 out[
i] =
m[
i] * in[0] +
m[
i + 4] * in[1] +
m[
i + 8] * in[2] +
m[
i + 12];
397 vb[0] =
m[0][0] *
va[0] +
m[1][0] *
va[1] +
m[2][0] *
va[2];
398 vb[1] =
m[0][1] *
va[0] +
m[1][1] *
va[1] +
m[2][1] *
va[2];
399 vb[2] =
m[0][2] *
va[0] +
m[1][2] *
va[1] +
m[2][2] *
va[2];
422 if (d[0] > epsilon || d[1] > epsilon || d[2] > epsilon)
449 const float number = 1.0 - mix;
451 out[0] = v1[0] * number + v2[0] * mix;
452 out[1] = v1[1] * number + v2[1] * mix;
453 out[2] = v1[2] * number + v2[2] * mix;
487 const float angle = acos(dot);
508 return (rand() & 32767) * (1.0 / 32767);
519 return (rand() & 32767) * (2.0 / 32767) - 1;
531 float x1, x2, w, tmp;
536 w = x1 * x1 + x2 * x2;
550 vec3_t minVec, maxVec, tmpMinVec, tmpMaxVec;
551 vec3_t centerVec, halfVec, newCenterVec, newHalfVec;
567 VectorAdd(newCenterVec, newHalfVec, tmpMaxVec);
570 minVec[0] = std::min(tmpMinVec[0], tmpMaxVec[0]);
571 minVec[1] = std::min(tmpMinVec[1], tmpMaxVec[1]);
572 minVec[2] = std::min(tmpMinVec[2], tmpMaxVec[2]);
573 maxVec[0] = std::max(tmpMinVec[0], tmpMaxVec[0]);
574 maxVec[1] = std::max(tmpMinVec[1], tmpMaxVec[1]);
575 maxVec[2] = std::max(tmpMinVec[2], tmpMaxVec[2]);
578 absBox.
set(minVec, maxVec);
633 const float anglePitch = angles[
PITCH] *
torad;
634 const float sp = sin(anglePitch);
635 const float cp = cos(anglePitch);
636 const float angleYaw = angles[
YAW] *
torad;
637 const float sy = sin(angleYaw);
638 const float cy = cos(angleYaw);
639 const float angleRoll = angles[
ROLL] *
torad;
640 const float sr = sin(angleRoll);
641 const float cr = cos(angleRoll);
644 forward[0] = cp * cy;
645 forward[1] = cp * sy;
649 right[0] = (-1 * sr * sp * cy + -1 * cr * -sy);
650 right[1] = (-1 * sr * sp * sy + -1 * cr * cy);
651 right[2] = -1 * sr * cp;
654 up[0] = (cr * sp * cy + -sr * -sy);
655 up[1] = (cr * sp * sy + -sr * cy);
672 delta[0] = point[0] -
origin[0];
673 delta[1] = point[1] -
origin[1];
679 if ((delta[0] *
dvecsn[dv][0] + delta[1] *
dvecsn[dv][1]) < 0.5)
701 inv_denom = 1.0F / sqrt(
DotProduct(normal, normal));
706 n[0] = normal[0] * inv_denom;
707 n[1] = normal[1] * inv_denom;
708 n[2] = normal[2] * inv_denom;
711 dst[0] = point[0] - distance * normal[0];
712 dst[1] = point[1] - distance * normal[1];
713 dst[2] = point[2] - distance * normal[2];
725 const float threehalfs = 1.5F;
730 t.i = 0x5f3759df - (t.i >> 1);
733 y = y * (threehalfs - (x2 * y * y));
735 y = y * (threehalfs - (x2 * y * y));
749 const float ilength = 1.0 /
length;
784 float minelem = 1.0F;
788 for (pos = 0,
i = 0;
i < 3;
i++) {
789 const float a = fabs(src[
i]);
795 tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
822 cross[0] = v1[1] * v2[2] - v1[2] * v2[1];
823 cross[1] = v1[2] * v2[0] - v1[0] * v2[2];
824 cross[2] = v1[0] * v2[1] - v1[1] * v2[0];
829 out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
830 out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
831 out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2];
832 out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + in1[1][2] * in2[2][0];
833 out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + in1[1][2] * in2[2][1];
834 out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + in1[1][2] * in2[2][2];
835 out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + in1[2][2] * in2[2][0];
836 out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1];
837 out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2];
877 memcpy(im,
m,
sizeof(im));
889 zrot[0][0] = cos(degrees *
torad);
890 zrot[0][1] = sin(degrees *
torad);
891 zrot[1][0] = -sin(degrees *
torad);
892 zrot[1][1] = cos(degrees *
torad);
898 for (
int i = 0;
i < 3;
i++) {
912 const float p = a[0] *
torad;
913 const float t = a[1] *
torad;
915 VectorSet(
v, cos(p) * cos(t), sin(p) * cos(t), sin(t));
924 a[0] =
todeg * atan2(
v[1],
v[0]);
925 a[1] = 90 -
todeg * acos(
v[2]);
941 if (value1[2] > 0.0f)
946 const float forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
947 if (!
EQUAL(value1[0], 0.0f))
948 yaw = atan2(value1[1], value1[0]) *
todeg;
949 else if (value1[1] > 0.0f)
956 pitch = atan2(value1[2], forward) *
todeg;
962 angles[
PITCH] = -pitch;
974 return (
i > 0 && !(
i & (
i - 1)));
987 return a2 + frac * (a1 - a2);
997 return (360.0 / 65536) * ((
int)(angle * (65536 / 360.0)) & 65535);
1021 for (
int i = 0;
i < 3;
i++) {
1034 mins[0] = mins[1] = mins[2] = 99999;
1035 maxs[0] = maxs[1] = maxs[2] = -99999;
1044 for (
int i = 0;
i < 3;
i++) {
1103 for (
int i = 0;
i < 3;
i++) {
1104 for(
int j = 0; j < 3; j++) {
1118 for (
int i = 0;
i < 3;
i++) {
1119 const float threshold = 1.0e-6f;
1122 if (fabs(delta[
i]) < threshold) {
1123 if (delta[
i] > 0.0f) {
1124 return !(end[
i] < aabb.
mins[
i] || start[
i] > aabb.
maxs[
i]);
1126 return !(start[
i] < aabb.
mins[
i] || end[
i] > aabb.
maxs[
i]);
1130 u0 = (aabb.
mins[
i] - start[
i]) / delta[
i];
1131 u1 = (aabb.
maxs[
i] - start[
i]) / delta[
i];
1134 const float temp = u0;
1139 if (u1 < t0 || u0 > t1) {
1143 t0 = std::max(u0, t0);
1144 t1 = std::min(u1, t1);
void getCenter(vec3_t center) const
Calculates the center of the bounding box.
void set(const AABB &other)
Copies the values from the given aabb.
void shift(const vec3_t shiftVec)
shove the whole box by the given vector
static const GridBox EMPTY
void Com_Printf(const char *const fmt,...)
definitions common between client and server, but not game lib
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
const vec4_t dvecs[PATHFINDING_DIRECTIONS]
void VectorMidpoint(const vec3_t point1, const vec3_t point2, vec3_t midpoint)
Calculates the midpoint between two vectors.
void MatrixMultiply(const vec3_t a[3], const vec3_t b[3], vec3_t c[3])
Multiply 3*3 matrix by 3*3 matrix.
void ClearBounds(vec3_t mins, vec3_t maxs)
Sets mins and maxs to their starting points before using AddPointToBounds.
float VectorAngleBetween(const vec3_t vec1, const vec3_t vec2)
Calculates the angle (in radians) between the two given vectors.
void gaussrand(float *gauss1, float *gauss2)
generate two gaussian distributed random numbers with median at 0 and stdev of 1
float AngleNormalize360(float angle)
returns angle normalized to the range [0 <= angle < 360]
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.
vec_t VectorNormalize(vec3_t v)
Calculate unit vector for a given vec3_t.
void GLMatrixAssemble(const vec3_t origin, const vec3_t angles, float *matrix)
Builds an opengl translation and rotation matrix.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
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).
#define DIRECTION_NORTHEAST
const byte dvleft[CORE_DIRECTIONS]
vec_t Q_rint(const vec_t in)
Round to nearest integer.
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...
#define DIRECTION_NORTHWEST
void Orthogonalize(vec3_t out, const vec3_t in)
Grahm-Schmidt orthogonalization.
static void ProjectPointOnPlane(vec3_t dst, const vec3_t point, const vec3_t normal)
Projects a point on a plane passing through the origin.
void MatrixTranspose(const vec3_t m[3], vec3_t t[3])
Transposes m and stores the result in t.
bool FrustumVis(const vec3_t origin, int dir, const vec3_t point)
Checks whether a point is visible from a given position.
const float directionAngles[CORE_DIRECTIONS]
vec_t VectorNormalize2(const vec3_t v, vec3_t out)
Calculated the normal vector for a given vec3_t.
void GLPositionTransform(const float m[16], const vec3_t in, vec3_t out)
Transform position (xyz) vector by OpenGL rules.
void VectorCreateRotationMatrix(const vec3_t angles, vec3_t matrix[3])
void VectorInverse(vec3_t v)
Inverse a vector.
float crand(void)
Return random values between -1 and 1.
void RotatePointAroundVector(vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
Rotate a point around a given vector.
void PolarToVec(const vec2_t a, vec3_t v)
Converts longitude and latitude to a 3D vector in Euclidean coordinates.
void VectorMix(const vec3_t v1, const vec3_t v2, float mix, vec3_t out)
Calculate a position on v1 v2 line.
const byte dvright[CORE_DIRECTIONS]
bool RayIntersectAABB(const vec3_t start, const vec3_t end, const AABB &aabb)
vec_t ColorNormalize(const vec3_t in, vec3_t out)
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.
void VectorRotate(vec3_t m[3], const vec3_t va, vec3_t vb)
Rotate a vector with a rotation matrix.
#define DIRECTION_SOUTHEAST
static void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3])
bool Q_IsPowerOfTwo(int i)
Checks whether i is power of two value.
void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Create the rotation matrix in order to rotate something.
float AngleNormalize180(float angle)
returns angle normalized to the range [-180 < angle <= 180]
void PerpendicularVector(vec3_t dst, const vec3_t src)
Finds a vector perpendicular to the source vector.
int AngleToDir(int angle)
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle.
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....
static float Q_rsqrtApprox(const float number)
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.
#define DIRECTION_SOUTHWEST
double GetDistanceOnGlobe(const vec2_t pos1, const vec2_t pos2)
Calculate distance on the geoscape.
void VectorClampMA(vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc)
void VecToPolar(const vec3_t v, vec2_t a)
Converts vector coordinates into polar coordinates.
float LerpAngle(float a2, float a1, float frac)
Returns the angle resulting from turning fraction * angle from angle1 to angle2.
void VecToAngles(const vec3_t value1, vec3_t angles)
Converts a vector to an angle vector.
const float dvecsn[CORE_DIRECTIONS][2]
void VectorRotatePoint(vec3_t point, vec3_t matrix[3])
void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross)
binary operation on vectors in a three-dimensional space
float frand(void)
Return random values between 0 and 1.
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 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...
void GLMatrixMultiply(const float a[16], const float b[16], float c[16])
Multiply 4*4 matrix by 4*4 matrix.
void GLVectorTransform(const float m[16], const vec4_t in, vec4_t out)
Multiply 4*4 matrix by 4d vector.
#define DIRECTIONS
Number of angles from a position (2-dimensional).
#define PATHFINDING_DIRECTIONS
QGL_EXTERN int GLboolean GLfloat * v
QGL_EXTERN GLuint GLsizei GLsizei * length
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...
static const vec3_t scale
#define VectorMul(scalar, b, dest)
#define VectorNotEmpty(a)
#define VectorSubtract(a, b, dest)
#define VectorCopy(src, dest)
#define VectorAdd(a, b, dest)
#define DotProduct(x, y)
Returns the distance between two 3-dimensional vectors.
#define VectorSet(v, x, y, z)
#define VectorScale(in, scale, out)