]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - mathlib.c
added Math_atov function (ascii to vector), tries to parse any imaginable vector...
[xonotic/darkplaces.git] / mathlib.c
index a0e328d0e86fb21836f4a05f02cd101c10e86e03..e55de85377b9e91473539410c5e3f228cdd161de 100644 (file)
--- a/mathlib.c
+++ b/mathlib.c
@@ -29,66 +29,66 @@ float ixtable[4096];
 
 float m_bytenormals[NUMVERTEXNORMALS][3] =
 {
 
 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.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.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.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.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.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.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.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},
 {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.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.681718, -0.147621, -0.716567}, {0.850651, 0.000000, -0.525731},
-{0.809017, -0.309017, -0.500000}, {0.864188, -0.442863, -0.238856}, 
+{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.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.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.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.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.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},
 {-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);
        vec3_t vr, vu, vf;
 
        angle = DEG2RAD(degrees);
-
        c = cos(angle);
        s = sin(angle);
        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;
        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;
        }
                v[1] *= ilength;
                v[2] *= ilength;
        }
-               
+
        return length;
 
 }
        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];
 }
 
        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)
 {
 
 void Mathlib_Init(void)
 {
@@ -508,3 +518,25 @@ void Matrix4x4_Print (const matrix4x4_t *in)
        , 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]);
 }
        , 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;
+}
+