convert line ends
[canaan.git] / prj / cam / src / ai / aidist.h
blob4439078eef8fcaa7ee34e9ba96c9d321e792dfd9
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/ai/aidist.h,v 1.4 1998/07/23 13:14:44 TOML Exp $
8 //
9 //
12 #ifndef __AIDIST_H
13 #define __AIDIST_H
15 #include <matrixc.h>
16 #include <fastflts.h>
18 #pragma once
20 inline float AIDistance(float x1, float y1, float x2, float y2)
22 float a, b;
24 a = x2 - x1;
25 b = y2 - y1;
27 a = ffabsf(a);
28 b = ffabsf(b);
30 if (pflt(b, a))
31 return (a + b/2);
32 else
33 return (b + a/2);
36 inline float AIDistance(const mxs_vector &p1, const mxs_vector &p2)
38 float a, b, c;
40 a = p2.x - p1.x;
41 b = p2.y - p1.y;
42 c = p2.z - p1.z;
44 a = ffabsf(a);
45 b = ffabsf(b);
46 c = ffabsf(c);
48 if (pflt(b, a) && pflt(c, a))
49 return (a + b/2 + c/2);
51 if (pflt(a, b) && pflt(c, b))
52 return (b + a/2 + c/2);
54 return (c + a/2 + b/2);
57 inline float AIXYDistance(const mxs_vector &p1, const mxs_vector &p2)
59 float a, b;
61 a = p2.x - p1.x;
62 b = p2.y - p1.y;
64 a = ffabsf(a);
65 b = ffabsf(b);
67 if (pflt(b, a))
68 return (a + b/2);
70 return (b + a/2);
73 inline float AIXYDistanceSq(const mxs_vector &p1, const mxs_vector &p2)
75 return ((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
78 inline float AIDistanceSq(float x1, float y1, float x2, float y2)
80 return ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
83 inline float AIDistanceSq(const mxs_vector &a, const mxs_vector &b)
85 return ((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z));
88 ///////////////////////////////////////
90 inline BOOL AIInsideSphere(const mxs_vector & loc, const mxs_vector & center, float radiusSq)
92 return pflt(AIDistanceSq(loc, center), radiusSq);
95 inline BOOL AIInsideCylinder(const mxs_vector & loc, const mxs_vector & center, float radiusSq, float halfHeight)
97 if (pflt(ffabsf(center.z - loc.z), halfHeight))
98 return pflt(AIXYDistanceSq(loc, center), radiusSq);
99 return FALSE;
102 inline BOOL AIInsideSphere(const mxs_vector & loc, const mxs_vector & center, float radiusSq, float * pDistSq)
104 *pDistSq = AIDistanceSq(loc, center);
105 return pflt(*pDistSq, radiusSq);
108 inline BOOL AIInsideCylinder(const mxs_vector & loc, const mxs_vector & center, float radiusSq, float halfHeight, float * pDistSq)
110 *pDistSq = AIDistanceSq(loc, center);
111 if (pflt(ffabsf(center.z - loc.z), halfHeight))
112 return pflt(AIXYDistanceSq(loc, center), radiusSq);
113 return FALSE;
116 ///////////////////////////////////////
118 #endif /* !__AIDIST_H */