00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 class XVector;
00024
00025 inline XVector operator* (const XVector &lval, const QFLOAT obj);
00026
00027 inline XVector operator* (const QFLOAT obj, const XVector &rval);
00028
00029 inline XVector operator+= (XVector &lval, const XVector &obj);
00030
00031 inline QFLOAT DotProduct (const XVector &a, const XVector &b);
00032 inline void Normalize(XVector &r);
00033 class YVector;
00034 class XVector {
00035 public:
00036 QFLOAT i,j,k;
00037 XVector () {}
00038 private:
00039 friend class Quadsquare;
00040 friend class QuadTree;
00041 friend class CoordinateSelect;
00042 friend class AIScript;
00043 friend class PlanetaryTransform;
00044 friend class SphericalTransform;
00045 inline YVector operator = (const YVector &);
00046 public:
00047 inline XVector (const YVector &);
00048 inline YVector Cast() const;
00049 XVector(QFLOAT i,QFLOAT j,QFLOAT k) {
00050 this->i = i;
00051 this->j = j;
00052 this->k = k;
00053 }
00054 inline void Set (QFLOAT x, QFLOAT y, QFLOAT z) {i=x;j=y;k=z;}
00055 void Yaw(QFLOAT rad);
00056 void Roll (QFLOAT rad);
00057 void Pitch(QFLOAT rad);
00058 XVector Scale (QFLOAT s)const {return XVector (s*i,s*j,s*k);}
00059 XVector Transform ( const XVector &p, const XVector &q, const XVector &r) {
00060 XVector tvect = XVector ( DotProduct(*this, p), DotProduct(*this,q), DotProduct(*this,r));
00061 *this = tvect;
00062 return *this;
00063 }
00064 XVector operator+ (const XVector &obj) const {return XVector (i + obj.i, j + obj.j, k + obj.k);}
00065 XVector operator- (const XVector &obj) const {return XVector (i - obj.i, j - obj.j, k - obj.k);}
00066 XVector Normalize(){::Normalize (*this); return *this;};
00067 XVector operator- () const {return XVector (-i, -j, -k);}
00068 bool operator== (const XVector &b) {return (i==b.i && j==b.j && k==b.k);};
00069 XVector Cross(const XVector &v) const {return XVector ( this->j*v.k-this->k*v.j,
00070 this->k*v.i-this->i*v.k,
00071 this->i*v.j-this->j*v.i);}
00072 QFLOAT operator* (const XVector &b) const {return (i*b.i+j*b.j+k*b.k);};
00073 QFLOAT Dot(const XVector &b) const {return DotProduct(*this, b);}
00074 QFLOAT Magnitude2d () const {return XSQRT(i*i+j*j);}
00075 QFLOAT Magnitude() const {return XSQRT(i*i+j*j+k*k);};
00076 QFLOAT MagnitudeSquared() const { return i*i + j*j + k*k; };
00077
00078 inline const XVector Transform(const class Matrix &m1) const;
00079
00080 XVector Min(const XVector &other) {
00081 return XVector((i<other.i)?i:other.i,
00082 (j<other.j)?j:other.j,
00083 (k<other.k)?k:other.k);
00084 }
00085 XVector Max(const XVector &other) {
00086 return XVector((i>other.i)?i:other.i,
00087 (j>other.j)?j:other.j,
00088 (k>other.k)?k:other.k);
00089 }
00090 XVector (struct _object *);
00091 };
00092
00093
00094 inline XVector operator/ (const XVector &lval, const QFLOAT obj) {XVector retval(lval.i / obj, lval.j / obj, lval.k / obj); return retval;}
00095
00096 inline XVector operator+= (XVector &lval, const XVector &obj) {lval.i += obj.i; lval.j += obj.j; lval.k += obj.k; return lval;}
00097
00098 inline XVector operator*= (XVector &lval, const QFLOAT &obj) {lval.i *= obj; lval.j *= obj, lval.k *= obj; return lval;}
00099
00100 inline void Normalize(XVector &r)
00101 {
00102 QFLOAT size = XSQRT(r.i*r.i+r.j*r.j+r.k*r.k);
00103 if( size>0.00001)
00104 {
00105 r.i /= size;
00106 r.j /= size;
00107 r.k /= size;
00108 }
00109 }
00110
00111 inline QFLOAT DotProduct(const XVector &a,const XVector &b)
00112 {
00113 return (a.i*b.i+a.j*b.j+a.k*b.k);
00114 }
00115
00116 inline XVector operator* (const XVector &lval, const double obj) {XVector retval(lval.i * obj, lval.j * obj, lval.k * obj); return retval;}
00117 inline XVector operator* (const XVector &lval, const float obj) {XVector retval(lval.i * obj, lval.j * obj, lval.k * obj); return retval;}
00118
00119 inline XVector operator* (const double obj, const XVector &rval) {return XVector(rval.i * obj, rval.j * obj, rval.k * obj); }
00120
00121 inline XVector operator* (const float obj, const XVector &rval) {return XVector(rval.i * obj, rval.j * obj, rval.k * obj); }
00122 inline XVector operator* (const XVector &lval, const int obj) {XVector retval(lval.i * obj, lval.j * obj, lval.k * obj); return retval;}
00123
00124 inline XVector operator* (const int obj, const XVector &rval) {return XVector(rval.i * obj, rval.j * obj, rval.k * obj); }
00125
00126
00127
00128
00129 inline void ScaledCrossProduct(const XVector &a, const XVector &b, XVector &r) {
00130 r.i = a.j*b.k-a.k*b.j;
00131 r.j = a.k*b.i-a.i*b.k;
00132 r.k = a.i*b.j-a.j*b.i;
00133 QFLOAT size = XSQRT(r.i*r.i+r.j*r.j+r.k*r.k);
00134 if( size<0.00001)
00135 {
00136 r.i = r.j = r.k = 0;
00137 }
00138 else
00139 {
00140 r.i /= size;
00141 r.j /= size;
00142 r.k /= size;
00143 }
00144 }
00145
00146
00147 inline XVector PolygonNormal(XVector v1, XVector v2, XVector v3)
00148 {
00149 XVector temp;
00150 ScaledCrossProduct(v2-v1, v3-v1, temp);
00151 return temp;
00152 }
00153
00154 inline XVector Transform(const XVector &p, const XVector &q, const XVector &r, const XVector &v)
00155 {
00156 return XVector(p.i * v.i + q.i * v.j + r.i * v.k,
00157 p.j * v.i + q.j * v.j + r.j * v.k,
00158 p.k * v.i + q.k * v.j + r.k * v.k);
00159 }
00160 inline XVector CrossProduct(const XVector& v1, const XVector& v2) {
00161 XVector result;
00162 result.i = v1.j * v2.k - v1.k * v2.j;
00163 result.j = v1.k * v2.i - v1.i * v2.k;
00164 result.k = v1.i * v2.j - v1.j * v2.i;
00165 return result;
00166 }
00167 inline void CrossProduct(const XVector & a, const XVector & b, XVector & RES) {RES = a.Cross(b);}
00168
00169 void Yaw (QFLOAT rad, XVector &p,XVector &q, XVector &r);
00170 void Pitch (QFLOAT rad,XVector &p, XVector &q, XVector &r);
00171 void Roll (QFLOAT rad,XVector &p, XVector &q, XVector &r);
00172 void ResetVectors (XVector &p, XVector &q, XVector &r);
00173 void MakeRVector (XVector &p, XVector &q, XVector &r);
00174 void Orthogonize(XVector &p, XVector &q, XVector &r);
00175