From: havoc Date: Thu, 27 Mar 2003 08:02:43 +0000 (+0000) Subject: added Math_atov function (ascii to vector), tries to parse any imaginable vector... X-Git-Tag: xonotic-v0.1.0preview~6716 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2861288617172d7be2fc45c92b3bc1adb04f8a2a;p=xonotic%2Fdarkplaces.git added Math_atov function (ascii to vector), tries to parse any imaginable vector (even badly formatted ones with varying numbers of spaces) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2854 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/mathlib.c b/mathlib.c index a55ab9d6..e55de853 100644 --- 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; +} + diff --git a/mathlib.h b/mathlib.h index 3d567852..ba362ce3 100644 --- a/mathlib.h +++ b/mathlib.h @@ -223,6 +223,7 @@ float RadiusFromBoundsAndOrigin (const vec3_t mins, const vec3_t maxs, const vec // print a matrix to the console struct matrix4x4_s; void Matrix4x4_Print(const struct matrix4x4_s *in); +int Math_atov(const char *s, vec3_t out); #endif