]> 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 a55ab9d6df90b2ef526322591e06be8e630dccb8..e55de85377b9e91473539410c5e3f228cdd161de 100644 (file)
--- a/mathlib.c
+++ b/mathlib.c
@@ -518,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]);
 }
+
+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;
+}
+