123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- extern const vec3_t vec3_origin;
- { \
- (dest)[0] = (a)[1] * (b)[2] - (a)[2] * (b)[1]; \
- (dest)[1] = (a)[2] * (b)[0] - (a)[0] * (b)[2]; \
- (dest)[2] = (a)[0] * (b)[1] - (a)[1] * (b)[0]; \
- }
- { \
- (a)[0] = -((a)[0]); \
- (a)[1] = -((a)[1]); \
- (a)[2] = -((a)[2]); \
- }
- { \
- (dest)[0] = (a)[0] + (scale) * (b)[0]; \
- (dest)[1] = (a)[1] + (scale) * (b)[1]; \
- (dest)[2] = (a)[2] + (scale) * (b)[2]; \
- }
- { \
- (dest)[0] = (a)[0] + scale * (b)[0]; \
- (dest)[1] = (a)[1] + scale * (b)[1]; \
- (dest)[2] = (a)[2] + scale * (b)[2]; \
- }
- inline vec_t VectorNormalize(vec3_t v)
- {
- double length;
- length = DotProduct(v, v);
- length = sqrt(length);
- if (length < NORMAL_EPSILON)
- {
- VectorClear(v);
- return 0.0;
- }
- v[0] /= length;
- v[1] /= length;
- v[2] /= length;
- return length;
- }
- inline bool VectorCompare(const vec3_t v1, const vec3_t v2)
- {
- int i;
- for (i = 0; i < 3; i++)
- {
- if (fabs(v1[i] - v2[i]) > EQUAL_EPSILON)
- {
- return false;
- }
- }
- return true;
- }
- inline unsigned int rotl(unsigned value, unsigned int amt)
- {
- unsigned t1, t2;
- t1 = value >> ((sizeof(unsigned) * CHAR_BIT) - amt);
- t2 = value << amt;
- return (t1 | t2);
- }
- inline unsigned int rotr(unsigned value, unsigned int amt)
- {
- unsigned t1, t2;
- t1 = value << ((sizeof(unsigned) * CHAR_BIT) - amt);
- t2 = value >> amt;
- return (t1 | t2);
- }
- inline bool isPointFinite(const vec_t* p)
- {
- if (finite(p[0]) && finite(p[1]) && finite(p[2]))
- {
- return true;
- }
- return false;
- }
- typedef enum
- {
- plane_x = 0,
- plane_y,
- plane_z,
- plane_anyx,
- plane_anyy,
- plane_anyz
- }
- planetypes;
- inline planetypes PlaneTypeForNormal(vec3_t normal)
- {
- vec_t ax, ay, az;
- ax = fabs(normal[0]);
- ay = fabs(normal[1]);
- az = fabs(normal[2]);
- if (ax >= 1.0 - NORMAL_EPSILON && ay <= NORMAL_EPSILON && az <= NORMAL_EPSILON)
- {
- return plane_x;
- }
- if (ay >= 1.0 - NORMAL_EPSILON && az <= NORMAL_EPSILON && ax <= NORMAL_EPSILON)
- {
- return plane_y;
- }
- if (az >= 1.0 - NORMAL_EPSILON && ax <= NORMAL_EPSILON && ay <= NORMAL_EPSILON)
- {
- return plane_z;
- }
- if ((ax >= ay) && (ax >= az))
- {
- return plane_anyx;
- }
- if ((ay >= ax) && (ay >= az))
- {
- return plane_anyy;
- }
- return plane_anyz;
- }
- inline planetypes PlaneTypeForNormal(vec3_t normal)
- {
- vec_t ax, ay, az;
- ax = fabs(normal[0]);
- if (ax == 1.0)
- {
- return plane_x;
- }
- ay = fabs(normal[1]);
- if (ay == 1.0)
- {
- return plane_y;
- }
- az = fabs(normal[2]);
- if (az == 1.0)
- {
- return plane_z;
- }
- if ((ax > ay) && (ax > az))
- {
- return plane_anyx;
- }
- if ((ay > ax) && (ay > az))
- {
- return plane_anyy;
- }
- return plane_anyz;
- }
|