mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2025-04-19 00:41:23 +00:00
Making progress on the SnapPlane() and SnapNormal() issues.
- Removing DIST_EPSILON #define from map.c. It's unused and only confuses programmers. - Adding new function SnapPlaneImproved() to map.c which is like SnapPlane(), only it takes an additional argument which is the "center". This new function is not being used anywhere yet. - In mathlib, adding VectorIsOnAxis() and VectorIsOnAxialPlane(), two convenience methods that will help make other code look more intuitive. git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/Rambetter-math-fix-experiments@400 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
parent
2bdcb2d3c2
commit
698b1d6285
3 changed files with 75 additions and 2 deletions
|
@ -82,6 +82,9 @@ qboolean VectorCompare (vec3_t v1, vec3_t v2);
|
|||
|
||||
#define Q_rint(in) ((vec_t)floor(in+0.5))
|
||||
|
||||
qboolean VectorIsOnAxis(vec3_t v);
|
||||
qboolean VectorIsOnAxialPlane(vec3_t v);
|
||||
|
||||
vec_t VectorLength(vec3_t v);
|
||||
|
||||
void VectorMA( const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc );
|
||||
|
|
|
@ -26,6 +26,54 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
vec3_t vec3_origin = {0.0f,0.0f,0.0f};
|
||||
|
||||
/*
|
||||
================
|
||||
VectorIsOnAxis
|
||||
================
|
||||
*/
|
||||
qboolean VectorIsOnAxis(vec3_t v)
|
||||
{
|
||||
int i, zeroComponentCount;
|
||||
|
||||
zeroComponentCount = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (v[i] == 0.0)
|
||||
{
|
||||
zeroComponentCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (zeroComponentCount > 1)
|
||||
{
|
||||
// The zero vector will be on axis.
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VectorIsOnAxis
|
||||
================
|
||||
*/
|
||||
qboolean VectorIsOnAxialPlane(vec3_t v)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (v[i] == 0.0)
|
||||
{
|
||||
// The zero vector will be on axial plane.
|
||||
return qtrue;
|
||||
}
|
||||
}
|
||||
|
||||
return qfalse;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
MakeNormalVectors
|
||||
|
|
|
@ -59,8 +59,6 @@ PlaneEqual()
|
|||
ydnar: replaced with variable epsilon for djbob
|
||||
*/
|
||||
|
||||
#define DIST_EPSILON 0.01
|
||||
|
||||
qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist )
|
||||
{
|
||||
float ne, de;
|
||||
|
@ -291,6 +289,30 @@ void SnapPlane( vec3_t normal, vec_t *dist )
|
|||
*dist = Q_rint( *dist );
|
||||
}
|
||||
|
||||
/*
|
||||
SnapPlaneImproved()
|
||||
snaps a plane to normal/distance epsilons, improved code
|
||||
*/
|
||||
void SnapPlaneImproved(vec3_t normal, vec_t *dist, vec3_t center)
|
||||
{
|
||||
vec_t distNearestInt;
|
||||
|
||||
if (SnapNormal(normal))
|
||||
{
|
||||
*dist = DotProduct(normal, center);
|
||||
}
|
||||
|
||||
if (VectorIsOnAxis(normal))
|
||||
{
|
||||
// Only snap distance if the normal is an axis. Otherwise there
|
||||
// is nothing "natural" about snapping the distance to an integer.
|
||||
distNearestInt = Q_rint(*dist);
|
||||
if (-distanceEpsilon < *dist - distNearestInt && *dist - distNearestInt < distanceEpsilon)
|
||||
{
|
||||
*dist = distNearestInt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue