mirror of
https://github.com/UberGames/GtkRadiant.git
synced 2025-02-23 12:22:28 +00:00
Making more progress on EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES code.
- Setting EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES to 1 (enabled). I'll turn this off before merging into trunk. - In function MapPlaneFromPoints() in map.c, doing a bit tighter math when EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES is on. This comes at the expense of a few extra CPU cycles. The signature of the function remains the same. - In VectorNormalize() in mathlib.c, fixing a cast of the return value. I did not see compile warnings or runtime errors, but it seems wrong the way it was. - Adding VectorNormalizeAccu() in mathlib.c, for normalizing vectors built on the high resolution data type. git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/Rambetter-math-fix-experiments@395 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
parent
0749e45aa3
commit
9c24f3e995
4 changed files with 51 additions and 2 deletions
|
@ -347,6 +347,7 @@ vec_accu_t Q_rintAccu(vec_accu_t val);
|
|||
|
||||
void VectorCopyAccuToRegular(const vec3_accu_t in, vec3_t out);
|
||||
void VectorCopyRegularToAccu(const vec3_t in, vec3_accu_t out);
|
||||
vec_accu_t VectorNormalizeAccu(const vec3_accu_t in, vec3_accu_t out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ vec_t VectorNormalize( const vec3_t in, vec3_t out ) {
|
|||
out[1] = (vec_t) (y / length);
|
||||
out[2] = (vec_t) (z / length);
|
||||
|
||||
return length;
|
||||
return (vec_t) length;
|
||||
}
|
||||
|
||||
vec_t ColorNormalize( const vec3_t in, vec3_t out ) {
|
||||
|
@ -722,3 +722,31 @@ void VectorCopyRegularToAccu(const vec3_t in, vec3_accu_t out)
|
|||
out[1] = (vec_accu_t) in[1];
|
||||
out[2] = (vec_accu_t) in[2];
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
VectorNormalizeAccu
|
||||
=================
|
||||
*/
|
||||
vec_accu_t VectorNormalizeAccu(const vec3_accu_t in, vec3_accu_t out)
|
||||
{
|
||||
// The sqrt() function takes double as an input and returns double as an
|
||||
// output according the the man pages on Debian and on FreeBSD. Therefore,
|
||||
// I don't see a reason why using a double outright (instead of using the
|
||||
// vec_accu_t alias for example) could possibly be frowned upon.
|
||||
|
||||
vec_accu_t length;
|
||||
|
||||
length = (vec_accu_t) sqrt((in[0] * in[0]) + (in[1] * in[1]) + (in[2] * in[2]));
|
||||
if (length == 0)
|
||||
{
|
||||
VectorClear(out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
out[0] = in[0] / length;
|
||||
out[1] = in[1] / length;
|
||||
out[2] = in[2] / length;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
|
|
@ -280,6 +280,25 @@ takes 3 points and finds the plane they lie in
|
|||
|
||||
int MapPlaneFromPoints( vec3_t *p )
|
||||
{
|
||||
#if EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES
|
||||
vec3_accu_t paccu[3];
|
||||
vec3_accu_t t1, t2, normalAccu;
|
||||
vec3_t normal;
|
||||
vec_t dist;
|
||||
|
||||
VectorCopyRegularToAccu(p[0], paccu[0]);
|
||||
VectorCopyRegularToAccu(p[1], paccu[1]);
|
||||
VectorCopyRegularToAccu(p[2], paccu[2]);
|
||||
|
||||
VectorSubtractAccu(paccu[0], paccu[1], t1);
|
||||
VectorSubtractAccu(paccu[2], paccu[1], t2);
|
||||
CrossProductAccu(t1, t2, normalAccu);
|
||||
VectorNormalizeAccu(normalAccu, normalAccu);
|
||||
dist = (vec_t) DotProductAccu(paccu[0], normalAccu);
|
||||
VectorCopyAccuToRegular(normalAccu, normal);
|
||||
|
||||
return FindFloatPlane(normal, dist, 3, p);
|
||||
#else
|
||||
vec3_t t1, t2, normal;
|
||||
vec_t dist;
|
||||
|
||||
|
@ -295,6 +314,7 @@ int MapPlaneFromPoints( vec3_t *p )
|
|||
|
||||
/* store the plane */
|
||||
return FindFloatPlane( normal, dist, 3, p );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ constants
|
|||
------------------------------------------------------------------------------- */
|
||||
|
||||
/* temporary hacks and tests (please keep off in SVN to prevent anyone's legacy map from screwing up) */
|
||||
#define EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES 0
|
||||
#define EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES 1
|
||||
|
||||
/* general */
|
||||
#define MAX_QPATH 64
|
||||
|
|
Loading…
Reference in a new issue