X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=mathlib.c;h=e55de85377b9e91473539410c5e3f228cdd161de;hb=ac98bf077bc6ec661e54210d8b3bc8ce687cede2;hp=96090b50b49ff49fc2a49481862fb26d3c157c46;hpb=14b5a1213af9d37bf205793411ecdfb31135539f;p=xonotic%2Fdarkplaces.git diff --git a/mathlib.c b/mathlib.c index 96090b50..e55de853 100644 --- a/mathlib.c +++ b/mathlib.c @@ -29,66 +29,66 @@ float ixtable[4096]; float m_bytenormals[NUMVERTEXNORMALS][3] = { -{-0.525731, 0.000000, 0.850651}, {-0.442863, 0.238856, 0.864188}, -{-0.295242, 0.000000, 0.955423}, {-0.309017, 0.500000, 0.809017}, -{-0.162460, 0.262866, 0.951056}, {0.000000, 0.000000, 1.000000}, -{0.000000, 0.850651, 0.525731}, {-0.147621, 0.716567, 0.681718}, -{0.147621, 0.716567, 0.681718}, {0.000000, 0.525731, 0.850651}, -{0.309017, 0.500000, 0.809017}, {0.525731, 0.000000, 0.850651}, -{0.295242, 0.000000, 0.955423}, {0.442863, 0.238856, 0.864188}, -{0.162460, 0.262866, 0.951056}, {-0.681718, 0.147621, 0.716567}, -{-0.809017, 0.309017, 0.500000}, {-0.587785, 0.425325, 0.688191}, +{-0.525731, 0.000000, 0.850651}, {-0.442863, 0.238856, 0.864188}, +{-0.295242, 0.000000, 0.955423}, {-0.309017, 0.500000, 0.809017}, +{-0.162460, 0.262866, 0.951056}, {0.000000, 0.000000, 1.000000}, +{0.000000, 0.850651, 0.525731}, {-0.147621, 0.716567, 0.681718}, +{0.147621, 0.716567, 0.681718}, {0.000000, 0.525731, 0.850651}, +{0.309017, 0.500000, 0.809017}, {0.525731, 0.000000, 0.850651}, +{0.295242, 0.000000, 0.955423}, {0.442863, 0.238856, 0.864188}, +{0.162460, 0.262866, 0.951056}, {-0.681718, 0.147621, 0.716567}, +{-0.809017, 0.309017, 0.500000}, {-0.587785, 0.425325, 0.688191}, {-0.850651, 0.525731, 0.000000}, {-0.864188, 0.442863, 0.238856}, -{-0.716567, 0.681718, 0.147621}, {-0.688191, 0.587785, 0.425325}, -{-0.500000, 0.809017, 0.309017}, {-0.238856, 0.864188, 0.442863}, -{-0.425325, 0.688191, 0.587785}, {-0.716567, 0.681718, -0.147621}, -{-0.500000, 0.809017, -0.309017}, {-0.525731, 0.850651, 0.000000}, +{-0.716567, 0.681718, 0.147621}, {-0.688191, 0.587785, 0.425325}, +{-0.500000, 0.809017, 0.309017}, {-0.238856, 0.864188, 0.442863}, +{-0.425325, 0.688191, 0.587785}, {-0.716567, 0.681718, -0.147621}, +{-0.500000, 0.809017, -0.309017}, {-0.525731, 0.850651, 0.000000}, {0.000000, 0.850651, -0.525731}, {-0.238856, 0.864188, -0.442863}, -{0.000000, 0.955423, -0.295242}, {-0.262866, 0.951056, -0.162460}, +{0.000000, 0.955423, -0.295242}, {-0.262866, 0.951056, -0.162460}, {0.000000, 1.000000, 0.000000}, {0.000000, 0.955423, 0.295242}, -{-0.262866, 0.951056, 0.162460}, {0.238856, 0.864188, 0.442863}, -{0.262866, 0.951056, 0.162460}, {0.500000, 0.809017, 0.309017}, -{0.238856, 0.864188, -0.442863}, {0.262866, 0.951056, -0.162460}, -{0.500000, 0.809017, -0.309017}, {0.850651, 0.525731, 0.000000}, -{0.716567, 0.681718, 0.147621}, {0.716567, 0.681718, -0.147621}, -{0.525731, 0.850651, 0.000000}, {0.425325, 0.688191, 0.587785}, -{0.864188, 0.442863, 0.238856}, {0.688191, 0.587785, 0.425325}, +{-0.262866, 0.951056, 0.162460}, {0.238856, 0.864188, 0.442863}, +{0.262866, 0.951056, 0.162460}, {0.500000, 0.809017, 0.309017}, +{0.238856, 0.864188, -0.442863}, {0.262866, 0.951056, -0.162460}, +{0.500000, 0.809017, -0.309017}, {0.850651, 0.525731, 0.000000}, +{0.716567, 0.681718, 0.147621}, {0.716567, 0.681718, -0.147621}, +{0.525731, 0.850651, 0.000000}, {0.425325, 0.688191, 0.587785}, +{0.864188, 0.442863, 0.238856}, {0.688191, 0.587785, 0.425325}, {0.809017, 0.309017, 0.500000}, {0.681718, 0.147621, 0.716567}, -{0.587785, 0.425325, 0.688191}, {0.955423, 0.295242, 0.000000}, +{0.587785, 0.425325, 0.688191}, {0.955423, 0.295242, 0.000000}, {1.000000, 0.000000, 0.000000}, {0.951056, 0.162460, 0.262866}, -{0.850651, -0.525731, 0.000000}, {0.955423, -0.295242, 0.000000}, -{0.864188, -0.442863, 0.238856}, {0.951056, -0.162460, 0.262866}, +{0.850651, -0.525731, 0.000000}, {0.955423, -0.295242, 0.000000}, +{0.864188, -0.442863, 0.238856}, {0.951056, -0.162460, 0.262866}, {0.809017, -0.309017, 0.500000}, {0.681718, -0.147621, 0.716567}, {0.850651, 0.000000, 0.525731}, {0.864188, 0.442863, -0.238856}, -{0.809017, 0.309017, -0.500000}, {0.951056, 0.162460, -0.262866}, -{0.525731, 0.000000, -0.850651}, {0.681718, 0.147621, -0.716567}, +{0.809017, 0.309017, -0.500000}, {0.951056, 0.162460, -0.262866}, +{0.525731, 0.000000, -0.850651}, {0.681718, 0.147621, -0.716567}, {0.681718, -0.147621, -0.716567}, {0.850651, 0.000000, -0.525731}, -{0.809017, -0.309017, -0.500000}, {0.864188, -0.442863, -0.238856}, -{0.951056, -0.162460, -0.262866}, {0.147621, 0.716567, -0.681718}, -{0.309017, 0.500000, -0.809017}, {0.425325, 0.688191, -0.587785}, -{0.442863, 0.238856, -0.864188}, {0.587785, 0.425325, -0.688191}, -{0.688191, 0.587785, -0.425325}, {-0.147621, 0.716567, -0.681718}, +{0.809017, -0.309017, -0.500000}, {0.864188, -0.442863, -0.238856}, +{0.951056, -0.162460, -0.262866}, {0.147621, 0.716567, -0.681718}, +{0.309017, 0.500000, -0.809017}, {0.425325, 0.688191, -0.587785}, +{0.442863, 0.238856, -0.864188}, {0.587785, 0.425325, -0.688191}, +{0.688191, 0.587785, -0.425325}, {-0.147621, 0.716567, -0.681718}, {-0.309017, 0.500000, -0.809017}, {0.000000, 0.525731, -0.850651}, {-0.525731, 0.000000, -0.850651}, {-0.442863, 0.238856, -0.864188}, -{-0.295242, 0.000000, -0.955423}, {-0.162460, 0.262866, -0.951056}, -{0.000000, 0.000000, -1.000000}, {0.295242, 0.000000, -0.955423}, -{0.162460, 0.262866, -0.951056}, {-0.442863, -0.238856, -0.864188}, -{-0.309017, -0.500000, -0.809017}, {-0.162460, -0.262866, -0.951056}, -{0.000000, -0.850651, -0.525731}, {-0.147621, -0.716567, -0.681718}, -{0.147621, -0.716567, -0.681718}, {0.000000, -0.525731, -0.850651}, -{0.309017, -0.500000, -0.809017}, {0.442863, -0.238856, -0.864188}, -{0.162460, -0.262866, -0.951056}, {0.238856, -0.864188, -0.442863}, -{0.500000, -0.809017, -0.309017}, {0.425325, -0.688191, -0.587785}, -{0.716567, -0.681718, -0.147621}, {0.688191, -0.587785, -0.425325}, +{-0.295242, 0.000000, -0.955423}, {-0.162460, 0.262866, -0.951056}, +{0.000000, 0.000000, -1.000000}, {0.295242, 0.000000, -0.955423}, +{0.162460, 0.262866, -0.951056}, {-0.442863, -0.238856, -0.864188}, +{-0.309017, -0.500000, -0.809017}, {-0.162460, -0.262866, -0.951056}, +{0.000000, -0.850651, -0.525731}, {-0.147621, -0.716567, -0.681718}, +{0.147621, -0.716567, -0.681718}, {0.000000, -0.525731, -0.850651}, +{0.309017, -0.500000, -0.809017}, {0.442863, -0.238856, -0.864188}, +{0.162460, -0.262866, -0.951056}, {0.238856, -0.864188, -0.442863}, +{0.500000, -0.809017, -0.309017}, {0.425325, -0.688191, -0.587785}, +{0.716567, -0.681718, -0.147621}, {0.688191, -0.587785, -0.425325}, {0.587785, -0.425325, -0.688191}, {0.000000, -0.955423, -0.295242}, -{0.000000, -1.000000, 0.000000}, {0.262866, -0.951056, -0.162460}, -{0.000000, -0.850651, 0.525731}, {0.000000, -0.955423, 0.295242}, -{0.238856, -0.864188, 0.442863}, {0.262866, -0.951056, 0.162460}, -{0.500000, -0.809017, 0.309017}, {0.716567, -0.681718, 0.147621}, -{0.525731, -0.850651, 0.000000}, {-0.238856, -0.864188, -0.442863}, -{-0.500000, -0.809017, -0.309017}, {-0.262866, -0.951056, -0.162460}, +{0.000000, -1.000000, 0.000000}, {0.262866, -0.951056, -0.162460}, +{0.000000, -0.850651, 0.525731}, {0.000000, -0.955423, 0.295242}, +{0.238856, -0.864188, 0.442863}, {0.262866, -0.951056, 0.162460}, +{0.500000, -0.809017, 0.309017}, {0.716567, -0.681718, 0.147621}, +{0.525731, -0.850651, 0.000000}, {-0.238856, -0.864188, -0.442863}, +{-0.500000, -0.809017, -0.309017}, {-0.262866, -0.951056, -0.162460}, {-0.850651, -0.525731, 0.000000}, {-0.716567, -0.681718, -0.147621}, -{-0.716567, -0.681718, 0.147621}, {-0.525731, -0.850651, 0.000000}, +{-0.716567, -0.681718, 0.147621}, {-0.525731, -0.850651, 0.000000}, {-0.500000, -0.809017, 0.309017}, {-0.238856, -0.864188, 0.442863}, {-0.262866, -0.951056, 0.162460}, {-0.864188, -0.442863, 0.238856}, {-0.809017, -0.309017, 0.500000}, {-0.688191, -0.587785, 0.425325}, @@ -244,14 +244,9 @@ void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, vec3_t vr, vu, vf; angle = DEG2RAD(degrees); - c = cos(angle); s = sin(angle); - - vf[0] = dir[0]; - vf[1] = dir[1]; - vf[2] = dir[2]; - + VectorCopy(dir, vf); VectorVectors(vf, vr, vu); t0 = vr[0] * c + vu[0] * -s; @@ -441,7 +436,7 @@ float VectorNormalizeLength (vec3_t v) v[1] *= ilength; v[2] *= ilength; } - + return length; } @@ -487,6 +482,21 @@ void R_ConcatTransforms (const float in1[3*4], const float in2[3*4], float out[3 out[2*4+3] = in1[2*4+0] * in2[0*4+3] + in1[2*4+1] * in2[1*4+3] + in1[2*4+2] * in2[2*4+3] + in1[2*4+3]; } +float RadiusFromBounds (const vec3_t mins, const vec3_t maxs) +{ + vec3_t m1, m2; + VectorMultiply(mins, mins, m1); + VectorMultiply(maxs, maxs, m2); + return sqrt(max(m1[0], m2[0]) + max(m1[1], m2[1]) + max(m1[2], m2[2])); +} + +float RadiusFromBoundsAndOrigin (const vec3_t mins, const vec3_t maxs, const vec3_t origin) +{ + vec3_t m1, m2; + VectorSubtract(mins, origin, m1);VectorMultiply(m1, m1, m1); + VectorSubtract(maxs, origin, m2);VectorMultiply(m2, m2, m2); + return sqrt(max(m1[0], m2[0]) + max(m1[1], m2[1]) + max(m1[2], m2[2])); +} void Mathlib_Init(void) { @@ -498,3 +508,35 @@ void Mathlib_Init(void) ixtable[a] = 1.0f / a; } +#include "matrixlib.h" + +void Matrix4x4_Print (const matrix4x4_t *in) +{ + Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n" + , in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3] + , in->m[1][0], in->m[1][1], in->m[1][2], in->m[1][3] + , in->m[2][0], in->m[2][1], in->m[2][2], in->m[2][3] + , in->m[3][0], in->m[3][1], in->m[3][2], in->m[3][3]); +} + +int Math_atov(const char *s, vec3_t out) +{ + int i; + VectorClear(out); + if (*s == '\'') + s++; + for (i = 0;i < 3;i++) + { + while (*s == ' ' || *s == '\t') + s++; + out[i] = atof (s); + if (out[i] == 0 && *s != '-' && *s != '+' && (*s < '0' || *s > '9')) + break; // not a number + while (*s && *s != ' ' && *s !='\t' && *s != '\'') + s++; + if (*s == '\'') + break; + } + return i; +} +