2007-11-04 03:34:51 +00:00
/*
2012-03-17 20:01:54 +00:00
Copyright ( C ) 1999 - 2007 id Software , Inc . and contributors .
For a list of contributors , see the accompanying CONTRIBUTORS file .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
This file is part of GtkRadiant .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
GtkRadiant is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
GtkRadiant is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
You should have received a copy of the GNU General Public License
along with GtkRadiant ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
2007-11-04 03:34:51 +00:00
# ifndef __MATHLIB__
# define __MATHLIB__
// mathlib.h
# include <math.h>
2011-01-10 06:15:47 +00:00
# include <float.h>
2007-11-04 03:34:51 +00:00
# include "bytebool.h"
# ifdef __cplusplus
extern " C "
{
# endif
typedef float vec_t ;
typedef vec_t vec3_t [ 3 ] ;
typedef vec_t vec5_t [ 5 ] ;
typedef vec_t vec4_t [ 4 ] ;
2011-01-10 06:15:47 +00:00
// Smallest positive value for vec_t such that 1.0 + VEC_SMALLEST_EPSILON_AROUND_ONE != 1.0.
// In the case of 32 bit floats (which is almost certainly the case), it's 0.00000011921.
// Don't forget that your epsilons should depend on the possible range of values,
// because for example adding VEC_SMALLEST_EPSILON_AROUND_ONE to 1024.0 will have no effect.
# define VEC_SMALLEST_EPSILON_AROUND_ONE FLT_EPSILON
2012-03-17 20:01:54 +00:00
# define SIDE_FRONT 0
# define SIDE_ON 2
# define SIDE_BACK 1
# define SIDE_CROSS -2
2007-11-04 03:34:51 +00:00
// plane types are used to speed some tests
// 0-2 are axial planes
2012-03-17 20:01:54 +00:00
# define PLANE_X 0
# define PLANE_Y 1
# define PLANE_Z 2
# define PLANE_NON_AXIAL 3
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define Q_PI 3.14159265358979323846f
2007-11-04 03:34:51 +00:00
extern vec3_t vec3_origin ;
2012-03-17 20:01:54 +00:00
# define EQUAL_EPSILON 0.001
2007-11-04 03:34:51 +00:00
# ifndef VEC_MAX
# define VEC_MAX 3.402823466e+38F
# endif
2012-03-17 20:01:54 +00:00
qboolean VectorCompare ( vec3_t v1 , vec3_t v2 ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define DotProduct( x,y ) ( ( x )[0] * ( y )[0] + ( x )[1] * ( y )[1] + ( x )[2] * ( y )[2] )
# define VectorSubtract( a,b,c ) ( ( c )[0] = ( a )[0] - ( b )[0],( c )[1] = ( a )[1] - ( b )[1],( c )[2] = ( a )[2] - ( b )[2] )
# define VectorAdd( a,b,c ) ( ( c )[0] = ( a )[0] + ( b )[0],( c )[1] = ( a )[1] + ( b )[1],( c )[2] = ( a )[2] + ( b )[2] )
# define VectorIncrement( a,b ) ( ( b )[0] += ( a )[0],( b )[1] += ( a )[1],( b )[2] += ( a )[2] )
# define VectorCopy( a,b ) ( ( b )[0] = ( a )[0],( b )[1] = ( a )[1],( b )[2] = ( a )[2] )
# define VectorSet( v, a, b, c ) ( ( v )[0] = ( a ),( v )[1] = ( b ),( v )[2] = ( c ) )
# define VectorScale( a,b,c ) ( ( c )[0] = ( b ) * ( a )[0],( c )[1] = ( b ) * ( a )[1],( c )[2] = ( b ) * ( a )[2] )
# define VectorMid( a,b,c ) ( ( c )[0] = ( ( a )[0] + ( b )[0] ) * 0.5f,( c )[1] = ( ( a )[1] + ( b )[1] ) * 0.5f,( c )[2] = ( ( a )[2] + ( b )[2] ) * 0.5f )
# define VectorNegative( a,b ) ( ( b )[0] = -( a )[0],( b )[1] = -( a )[1],( b )[2] = -( a )[2] )
# define CrossProduct( a,b,c ) ( ( c )[0] = ( a )[1] * ( b )[2] - ( a )[2] * ( b )[1],( c )[1] = ( a )[2] * ( b )[0] - ( a )[0] * ( b )[2],( c )[2] = ( a )[0] * ( b )[1] - ( a )[1] * ( b )[0] )
# define VectorClear( x ) ( ( x )[0] = ( x )[1] = ( x )[2] = 0 )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
# define Q_rint( in ) ( (vec_t)floor( in + 0.5 ) )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
qboolean VectorIsOnAxis ( vec3_t v ) ;
qboolean VectorIsOnAxialPlane ( vec3_t v ) ;
2011-01-10 06:15:47 +00:00
2012-03-17 20:01:54 +00:00
vec_t VectorLength ( vec3_t v ) ;
2007-11-04 03:34:51 +00:00
void VectorMA ( const vec3_t va , vec_t scale , const vec3_t vb , vec3_t vc ) ;
2012-03-17 20:01:54 +00:00
void _CrossProduct ( vec3_t v1 , vec3_t v2 , vec3_t cross ) ;
2011-01-12 03:35:57 +00:00
// I need this define in order to test some of the regression tests from time to time.
// This define affect the precision of VectorNormalize() function only.
# define MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX 1
2012-03-17 20:01:54 +00:00
vec_t VectorNormalize ( const vec3_t in , vec3_t out ) ;
2007-11-04 03:34:51 +00:00
vec_t ColorNormalize ( const vec3_t in , vec3_t out ) ;
2012-03-17 20:01:54 +00:00
void VectorInverse ( vec3_t v ) ;
void VectorPolar ( vec3_t v , float radius , float theta , float phi ) ;
2007-11-04 03:34:51 +00:00
// default snapping, to 1
2012-03-17 20:01:54 +00:00
void VectorSnap ( vec3_t v ) ;
2007-11-04 03:34:51 +00:00
// integer snapping
2012-03-17 20:01:54 +00:00
void VectorISnap ( vec3_t point , int snap ) ;
2007-11-04 03:34:51 +00:00
// Gef: added snap to float for sub-integer grid sizes
// TTimo: we still use the int version of VectorSnap when possible
// to avoid potential rounding issues
// TTimo: renaming to VectorFSnap for C implementation
2012-03-17 20:01:54 +00:00
void VectorFSnap ( vec3_t point , float snap ) ;
2007-11-04 03:34:51 +00:00
// NOTE: added these from Ritual's Q3Radiant
2012-03-17 20:01:54 +00:00
void ClearBounds ( vec3_t mins , vec3_t maxs ) ;
void AddPointToBounds ( vec3_t v , vec3_t mins , vec3_t maxs ) ;
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
void AngleVectors ( vec3_t angles , vec3_t forward , vec3_t right , vec3_t up ) ;
2007-11-04 03:34:51 +00:00
void VectorToAngles ( vec3_t vec , vec3_t angles ) ;
# define ZERO_EPSILON 1.0E-6
# define RAD2DEGMULT 57.29577951308232f
# define DEG2RADMULT 0.01745329251994329f
2012-03-17 20:01:54 +00:00
# define RAD2DEG( a ) ( ( a ) * RAD2DEGMULT )
# define DEG2RAD( a ) ( ( a ) * DEG2RADMULT )
2007-11-04 03:34:51 +00:00
2012-03-17 20:01:54 +00:00
void VectorRotate ( vec3_t vIn , vec3_t vRotation , vec3_t out ) ;
void VectorRotateOrigin ( vec3_t vIn , vec3_t vRotation , vec3_t vOrigin , vec3_t out ) ;
2007-11-04 03:34:51 +00:00
// some function merged from tools mathlib code
qboolean PlaneFromPoints ( vec4_t plane , const vec3_t a , const vec3_t b , const vec3_t c ) ;
void NormalToLatLong ( const vec3_t normal , byte bytes [ 2 ] ) ;
2012-03-17 20:01:54 +00:00
int PlaneTypeForNormal ( vec3_t normal ) ;
2007-11-04 03:34:51 +00:00
void RotatePointAroundVector ( vec3_t dst , const vec3_t dir , const vec3_t point , float degrees ) ;
// Spog
// code imported from geomlib
/*!
2012-03-17 20:01:54 +00:00
\ todo
FIXME test calls such as intersect tests should be named test_
*/
2007-11-04 03:34:51 +00:00
typedef vec_t m3x3_t [ 9 ] ;
2012-03-17 20:01:54 +00:00
/*!NOTE
m4x4 looks like this . .
2007-11-04 03:34:51 +00:00
x y z
2012-03-17 20:01:54 +00:00
x axis ( 0 1 2 )
y axis ( 4 5 6 )
z axis ( 8 9 10 )
translation ( 12 13 14 )
scale ( 0 5 10 )
*/
2007-11-04 03:34:51 +00:00
typedef vec_t m4x4_t [ 16 ] ;
2012-03-17 20:01:54 +00:00
# define M4X4_INDEX( m,row,col ) ( m[( col << 2 ) + row] )
2007-11-04 03:34:51 +00:00
typedef enum { TRANSLATE , SCALE , ROTATE } transformtype ; // legacy, used only in pmesh.cpp
typedef enum { eXYZ , eYZX , eZXY , eXZY , eYXZ , eZYX } eulerOrder_t ;
// constructors
/*! create m4x4 as identity matrix */
2012-03-17 20:01:54 +00:00
void m4x4_identity ( m4x4_t matrix ) ;
2007-11-04 03:34:51 +00:00
/*! create m4x4 as a translation matrix, for a translation vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_translation_for_vec3 ( m4x4_t matrix , const vec3_t translation ) ;
2007-11-04 03:34:51 +00:00
/*! create m4x4 as a rotation matrix, for an euler angles (degrees) vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_rotation_for_vec3 ( m4x4_t matrix , const vec3_t euler , eulerOrder_t order ) ;
2007-11-04 03:34:51 +00:00
/*! create m4x4 as a scaling matrix, for a scale vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_scale_for_vec3 ( m4x4_t matrix , const vec3_t scale ) ;
2007-11-04 03:34:51 +00:00
/*! create m4x4 as a rotation matrix, for a quaternion vec4 */
2012-03-17 20:01:54 +00:00
void m4x4_rotation_for_quat ( m4x4_t matrix , const vec4_t rotation ) ;
2007-11-04 03:34:51 +00:00
/*! create m4x4 as a rotation matrix, for an axis vec3 and an angle (radians) */
2012-03-17 20:01:54 +00:00
void m4x4_rotation_for_axisangle ( m4x4_t matrix , const vec3_t axis , vec_t angle ) ;
2007-11-04 03:34:51 +00:00
// a valid m4x4 to be modified is always first argument
/*! translate m4x4 by a translation vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_translate_by_vec3 ( m4x4_t matrix , const vec3_t translation ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 by a euler (degrees) vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_rotate_by_vec3 ( m4x4_t matrix , const vec3_t euler , eulerOrder_t order ) ;
2007-11-04 03:34:51 +00:00
/*! scale m4x4 by a scaling vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_scale_by_vec3 ( m4x4_t matrix , const vec3_t scale ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 by a quaternion vec4 */
2012-03-17 20:01:54 +00:00
void m4x4_rotate_by_quat ( m4x4_t matrix , const vec4_t rotation ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 by an axis vec3 and an angle (radians) */
2012-03-17 20:01:54 +00:00
void m4x4_rotate_by_axisangle ( m4x4_t matrix , const vec3_t axis , vec_t angle ) ;
2007-11-04 03:34:51 +00:00
/*! transform m4x4 by translation/euler/scaling vec3 (transform = translation.euler.scale) */
2012-03-17 20:01:54 +00:00
void m4x4_transform_by_vec3 ( m4x4_t matrix , const vec3_t translation , const vec3_t euler , eulerOrder_t order , const vec3_t scale ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 around a pivot point by euler(degrees) vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_pivoted_rotate_by_vec3 ( m4x4_t matrix , const vec3_t euler , eulerOrder_t order , const vec3_t pivotpoint ) ;
2007-11-04 03:34:51 +00:00
/*! scale m4x4 around a pivot point by scaling vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_pivoted_scale_by_vec3 ( m4x4_t matrix , const vec3_t scale , const vec3_t pivotpoint ) ;
2007-11-04 03:34:51 +00:00
/*! transform m4x4 around a pivot point by translation/euler/scaling vec3 */
2012-03-17 20:01:54 +00:00
void m4x4_pivoted_transform_by_vec3 ( m4x4_t matrix , const vec3_t translation , const vec3_t euler , eulerOrder_t order , const vec3_t scale , const vec3_t pivotpoint ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 around a pivot point by quaternion vec4 */
2012-03-17 20:01:54 +00:00
void m4x4_pivoted_rotate_by_quat ( m4x4_t matrix , const vec4_t rotation , const vec3_t pivotpoint ) ;
2007-11-04 03:34:51 +00:00
/*! rotate m4x4 around a pivot point by axis vec3 and angle (radians) */
2012-03-17 20:01:54 +00:00
void m4x4_pivoted_rotate_by_axisangle ( m4x4_t matrix , const vec3_t axis , vec_t angle , const vec3_t pivotpoint ) ;
2007-11-04 03:34:51 +00:00
/*! post-multiply m4x4 by another m4x4 */
2012-03-17 20:01:54 +00:00
void m4x4_multiply_by_m4x4 ( m4x4_t matrix , const m4x4_t other ) ;
2007-11-04 03:34:51 +00:00
/*! pre-multiply m4x4 by another m4x4 */
2012-03-17 20:01:54 +00:00
void m4x4_premultiply_by_m4x4 ( m4x4_t matrix , const m4x4_t other ) ;
2007-11-04 03:34:51 +00:00
/*! multiply a point (x,y,z,1) by matrix */
2012-03-17 20:01:54 +00:00
void m4x4_transform_point ( const m4x4_t matrix , vec3_t point ) ;
2007-11-04 03:34:51 +00:00
/*! multiply a normal (x,y,z,0) by matrix */
2012-03-17 20:01:54 +00:00
void m4x4_transform_normal ( const m4x4_t matrix , vec3_t normal ) ;
2007-11-04 03:34:51 +00:00
/*! multiply a vec4 (x,y,z,w) by matrix */
2012-03-17 20:01:54 +00:00
void m4x4_transform_vec4 ( const m4x4_t matrix , vec4_t vector ) ;
2007-11-04 03:34:51 +00:00
/*! multiply a point (x,y,z,1) by matrix */
2012-03-17 20:01:54 +00:00
void m4x4_transform_point ( const m4x4_t matrix , vec3_t point ) ;
2007-11-04 03:34:51 +00:00
/*! multiply a normal (x,y,z,0) by matrix */
2012-03-17 20:01:54 +00:00
void m4x4_transform_normal ( const m4x4_t matrix , vec3_t normal ) ;
2007-11-04 03:34:51 +00:00
/*! transpose a m4x4 */
2012-03-17 20:01:54 +00:00
void m4x4_transpose ( m4x4_t matrix ) ;
2007-11-04 03:34:51 +00:00
/*! invert an orthogonal 4x3 subset of a 4x4 matrix */
2012-03-17 20:01:54 +00:00
void m4x4_orthogonal_invert ( m4x4_t matrix ) ;
2007-11-04 03:34:51 +00:00
/*! invert any m4x4 using Kramer's rule.. return 1 if matrix is singular, else return 0 */
2012-03-17 20:01:54 +00:00
int m4x4_invert ( m4x4_t matrix ) ;
2007-11-04 03:34:51 +00:00
/*!
2012-03-17 20:01:54 +00:00
\ todo object / ray intersection functions should maybe return a point rather than a distance ?
*/
2007-11-04 03:34:51 +00:00
/*!
2012-03-17 20:01:54 +00:00
aabb_t - " axis-aligned " bounding box . . .
origin : centre of bounding box . . .
extents : + / - extents of box from origin . . .
radius : cached length of extents vector . . .
*/
2007-11-04 03:34:51 +00:00
typedef struct aabb_s
{
2012-03-17 20:01:54 +00:00
vec3_t origin ;
vec3_t extents ;
vec_t radius ;
2007-11-04 03:34:51 +00:00
} aabb_t ;
/*!
2012-03-17 20:01:54 +00:00
bbox_t - oriented bounding box . . .
aabb : axis - aligned bounding box . . .
axes : orientation axes . . .
*/
2007-11-04 03:34:51 +00:00
typedef struct bbox_s
{
2012-03-17 20:01:54 +00:00
aabb_t aabb ;
vec3_t axes [ 3 ] ;
2007-11-04 03:34:51 +00:00
} bbox_t ;
/*!
2012-03-17 20:01:54 +00:00
ray_t - origin point and direction unit - vector
*/
2007-11-04 03:34:51 +00:00
typedef struct ray_s
{
2012-03-17 20:01:54 +00:00
vec3_t origin ;
vec3_t direction ;
2007-11-04 03:34:51 +00:00
} ray_t ;
/*! Generate AABB from min/max. */
2012-03-17 20:01:54 +00:00
void aabb_construct_for_vec3 ( aabb_t * aabb , const vec3_t min , const vec3_t max ) ;
2007-11-04 03:34:51 +00:00
/*! Update bounding-sphere radius. */
2012-03-17 20:01:54 +00:00
void aabb_update_radius ( aabb_t * aabb ) ;
2007-11-04 03:34:51 +00:00
/*! Initialise AABB to negative size. */
2012-03-17 20:01:54 +00:00
void aabb_clear ( aabb_t * aabb ) ;
2007-11-04 03:34:51 +00:00
/*! Extend AABB to include point. */
2012-03-17 20:01:54 +00:00
void aabb_extend_by_point ( aabb_t * aabb , const vec3_t point ) ;
2007-11-04 03:34:51 +00:00
/*! Extend AABB to include aabb_src. */
2012-03-17 20:01:54 +00:00
void aabb_extend_by_aabb ( aabb_t * aabb , const aabb_t * aabb_src ) ;
2007-11-04 03:34:51 +00:00
/*! Extend AABB by +/- extension vector. */
2012-03-17 20:01:54 +00:00
void aabb_extend_by_vec3 ( aabb_t * aabb , vec3_t extension ) ;
2007-11-04 03:34:51 +00:00
/*! Return 2 if point is inside, else 1 if point is on surface, else 0. */
2012-03-17 20:01:54 +00:00
int aabb_intersect_point ( const aabb_t * aabb , const vec3_t point ) ;
2007-11-04 03:34:51 +00:00
/*! Return 2 if aabb_src intersects, else 1 if aabb_src touches exactly, else 0. */
2012-03-17 20:01:54 +00:00
int aabb_intersect_aabb ( const aabb_t * aabb , const aabb_t * aabb_src ) ;
2007-11-04 03:34:51 +00:00
/*! Return 2 if aabb is behind plane, else 1 if aabb intersects plane, else 0. */
2012-03-17 20:01:54 +00:00
int aabb_intersect_plane ( const aabb_t * aabb , const float * plane ) ;
2007-11-04 03:34:51 +00:00
/*! Return 1 if aabb intersects ray, else 0... dist = closest intersection. */
2012-03-17 20:01:54 +00:00
int aabb_intersect_ray ( const aabb_t * aabb , const ray_t * ray , vec_t * dist ) ;
2007-11-04 03:34:51 +00:00
/*! Return 1 if aabb intersects ray, else 0. Faster, but does not provide point of intersection */
2012-03-17 20:01:54 +00:00
int aabb_test_ray ( const aabb_t * aabb , const ray_t * ray ) ;
2007-11-04 03:34:51 +00:00
/*! Generate AABB from oriented bounding box. */
2012-03-17 20:01:54 +00:00
void aabb_for_bbox ( aabb_t * aabb , const bbox_t * bbox ) ;
2007-11-04 03:34:51 +00:00
/*! Generate AABB from 2-dimensions of min/max, specified by axis. */
2012-03-17 20:01:54 +00:00
void aabb_for_area ( aabb_t * aabb , vec3_t area_tl , vec3_t area_br , int axis ) ;
2007-11-04 03:34:51 +00:00
/*! Generate AABB to contain src * transform. NOTE: transform must be orthogonal */
2012-03-17 20:01:54 +00:00
void aabb_for_transformed_aabb ( aabb_t * dst , const aabb_t * src , const m4x4_t transform ) ;
2007-11-04 03:34:51 +00:00
/*! Generate oriented bounding box from AABB and transformation matrix. */
/*!\todo Remove need to specify euler/scale. */
2012-03-17 20:01:54 +00:00
void bbox_for_oriented_aabb ( bbox_t * bbox , const aabb_t * aabb ,
const m4x4_t matrix , const vec3_t euler , const vec3_t scale ) ;
2007-11-04 03:34:51 +00:00
/*! Return 2 is bbox is behind plane, else return 1 if bbox intersects plane, else return 0. */
2012-03-17 20:01:54 +00:00
int bbox_intersect_plane ( const bbox_t * bbox , const vec_t * plane ) ;
2007-11-04 03:34:51 +00:00
/*! Generate a ray from an origin point and a direction unit-vector */
2012-03-17 20:01:54 +00:00
void ray_construct_for_vec3 ( ray_t * ray , const vec3_t origin , const vec3_t direction ) ;
2007-11-04 03:34:51 +00:00
/*! Transform a ray */
2012-03-17 20:01:54 +00:00
void ray_transform ( ray_t * ray , const m4x4_t matrix ) ;
2007-11-04 03:34:51 +00:00
/*! return true if point intersects cone formed by ray, divergence and epsilon */
2012-03-17 20:01:54 +00:00
vec_t ray_intersect_point ( const ray_t * ray , const vec3_t point , vec_t epsilon , vec_t divergence ) ;
2007-11-04 03:34:51 +00:00
/*! return true if triangle intersects ray... dist = dist from intersection point to ray-origin */
2012-03-17 20:01:54 +00:00
vec_t ray_intersect_triangle ( const ray_t * ray , qboolean bCullBack , const vec3_t vert0 , const vec3_t vert1 , const vec3_t vert2 ) ;
2007-11-04 03:34:51 +00:00
2011-01-10 06:15:47 +00:00
////////////////////////////////////////////////////////////////////////////////
// Below is double-precision math stuff. This was initially needed by the new
// "base winding" code in q3map2 brush processing in order to fix the famous
// "disappearing triangles" issue. These definitions can be used wherever extra
// precision is needed.
////////////////////////////////////////////////////////////////////////////////
typedef double vec_accu_t ;
typedef vec_accu_t vec3_accu_t [ 3 ] ;
// Smallest positive value for vec_accu_t such that 1.0 + VEC_ACCU_SMALLEST_EPSILON_AROUND_ONE != 1.0.
// In the case of 64 bit doubles (which is almost certainly the case), it's 0.00000000000000022204.
// Don't forget that your epsilons should depend on the possible range of values,
// because for example adding VEC_ACCU_SMALLEST_EPSILON_AROUND_ONE to 1024.0 will have no effect.
# define VEC_ACCU_SMALLEST_EPSILON_AROUND_ONE DBL_EPSILON
2012-03-17 20:01:54 +00:00
vec_accu_t VectorLengthAccu ( const vec3_accu_t v ) ;
2011-01-10 06:15:47 +00:00
// I have a feeling it may be safer to break these #define functions out into actual functions
// in order to avoid accidental loss of precision. For example, say you call
// VectorScaleAccu(vec3_t, vec_t, vec3_accu_t). The scale would take place in 32 bit land
// and the result would be cast to 64 bit, which would cause total loss of precision when
// scaling by a large factor.
//#define DotProductAccu(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2])
//#define VectorSubtractAccu(a, b, c) ((c)[0] = (a)[0] - (b)[0], (c)[1] = (a)[1] - (b)[1], (c)[2] = (a)[2] - (b)[2])
//#define VectorAddAccu(a, b, c) ((c)[0] = (a)[0] + (b)[0], (c)[1] = (a)[1] + (b)[1], (c)[2] = (a)[2] + (b)[2])
//#define VectorCopyAccu(a, b) ((b)[0] = (a)[0], (b)[1] = (a)[1], (b)[2] = (a)[2])
//#define VectorScaleAccu(a, b, c) ((c)[0] = (b) * (a)[0], (c)[1] = (b) * (a)[1], (c)[2] = (b) * (a)[2])
//#define CrossProductAccu(a, b, c) ((c)[0] = (a)[1] * (b)[2] - (a)[2] * (b)[1], (c)[1] = (a)[2] * (b)[0] - (a)[0] * (b)[2], (c)[2] = (a)[0] * (b)[1] - (a)[1] * (b)[0])
//#define Q_rintAccu(in) ((vec_accu_t) floor(in + 0.5))
2012-03-17 20:01:54 +00:00
vec_accu_t DotProductAccu ( const vec3_accu_t a , const vec3_accu_t b ) ;
void VectorSubtractAccu ( const vec3_accu_t a , const vec3_accu_t b , vec3_accu_t out ) ;
void VectorAddAccu ( const vec3_accu_t a , const vec3_accu_t b , vec3_accu_t out ) ;
void VectorCopyAccu ( const vec3_accu_t in , vec3_accu_t out ) ;
void VectorScaleAccu ( const vec3_accu_t in , vec_accu_t scaleFactor , vec3_accu_t out ) ;
void CrossProductAccu ( const vec3_accu_t a , const vec3_accu_t b , vec3_accu_t out ) ;
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 ) ;
2011-01-10 06:15:47 +00:00
2007-11-04 03:34:51 +00:00
# ifdef __cplusplus
}
# endif
# endif /* __MATHLIB__ */