00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(AFX_FixedVector4_H__AD959187_7A1C_11D2_957C_00A0C9A4CA3E__INCLUDED_)
00022 #define AFX_FixedVector4_H__AD959187_7A1C_11D2_957C_00A0C9A4CA3E__INCLUDED_
00023
00024 #include <common/FixedVector.h>
00025 #include <common/Vector4.h>
00026
00027 class FixedVector4
00028 {
00029 public:
00030 FixedVector4()
00031 {
00032 V[0] = V[1] = V[2] = V[3] = 0;
00033 }
00034
00035 FixedVector4(const FixedVector &v, fixed a = 1)
00036 {
00037 V[0] = ((FixedVector &) v)[0];
00038 V[1] = ((FixedVector &) v)[1];
00039 V[2] = ((FixedVector &) v)[2];
00040 V[3] = a;
00041 }
00042
00043 FixedVector4(const FixedVector4 &cc1, const FixedVector4 &cc2, fixed scal)
00044 {
00045 FixedVector4 &c1 = (FixedVector4 &) cc1;
00046 FixedVector4 &c2 = (FixedVector4 &) cc2;
00047
00048 V[0] = (c1[0]*(fixed(1)-scal) + c2[0]*scal);
00049 V[1] = (c1[1]*(fixed(1)-scal) + c2[1]*scal);
00050 V[2] = (c1[2]*(fixed(1)-scal) + c2[2]*scal);
00051 V[3] = (c1[3]*(fixed(1)-scal) + c2[3]*scal);
00052 }
00053
00054 FixedVector4(const FixedVector4 &v)
00055 {
00056 V[0] = ((FixedVector4 &) v)[0];
00057 V[1] = ((FixedVector4 &) v)[1];
00058 V[2] = ((FixedVector4 &) v)[2];
00059 V[3] = ((FixedVector4 &) v)[3];
00060 }
00061
00062 FixedVector4(const fixed Pt[4])
00063 {
00064 V[0] = Pt[0];
00065 V[1] = Pt[1];
00066 V[2] = Pt[2];
00067 V[3] = Pt[3];
00068 }
00069
00070 FixedVector4(const fixed ptA, const fixed ptB, const fixed ptC, fixed ptD=0)
00071 {
00072 V[0] = ptA;
00073 V[1] = ptB;
00074 V[2] = ptC;
00075 V[3] = ptD;
00076 }
00077
00078 void zero()
00079 {
00080 V[0] = V[1] = V[2] = V[3] = 0;
00081 }
00082
00083 bool operator==(const FixedVector4 &Vin)
00084 {
00085 FixedVector4 &Vin1 = (FixedVector4 &) Vin;
00086 return (Vin1.V[0]==V[0] && Vin1.V[1]==V[1] &&
00087 Vin1.V[2]==V[2] && Vin1.V[3]==V[3]);
00088 }
00089
00090 bool operator!=(const FixedVector4 &Vin1)
00091 {
00092 return !((*this) == Vin1);
00093 }
00094
00095 FixedVector4 &operator+=(const FixedVector4 &qc)
00096 {
00097 V[0] += qc.V[0];
00098 V[1] += qc.V[1];
00099 V[2] += qc.V[2];
00100 V[3] += qc.V[3];
00101
00102 return *this;
00103 }
00104
00105 FixedVector4 operator*(const FixedVector4 &qc)
00106 {
00107 FixedVector4 qa;
00108 FixedVector4 &qb = *this;
00109
00110
00111 qa[0] = qb[0]*qc[0] - qb[1]*qc[1] - qb[2]*qc[2] - qb[3]*qc[3];
00112 qa[1] = qb[0]*qc[1] + qb[1]*qc[0] + qb[2]*qc[3] - qb[3]*qc[2];
00113 qa[2] = qb[0]*qc[2] + qb[2]*qc[0] + qb[3]*qc[1] - qb[1]*qc[3];
00114 qa[3] = qb[0]*qc[3] + qb[3]*qc[0] + qb[1]*qc[2] - qb[2]*qc[1];
00115
00116 return qa;
00117 }
00118
00119
00120 FixedVector4 lerp(FixedVector4 &c1, FixedVector4 &c2)
00121 {
00122 return FixedVector4(
00123 c1[0] * (fixed(1) - V[0]) + c2[0] * V[0],
00124 c1[1] * (fixed(1) - V[1]) + c2[1] * V[1],
00125 c1[2] * (fixed(1) - V[2]) + c2[2] * V[2],
00126 c1[3] * (fixed(1) - V[3]) + c2[3] * V[3]);
00127 }
00128
00129 void Normalize();
00130
00131 Vector4 &asVector4()
00132 {
00133 static Vector4 a[10];
00134 static unsigned int count = 0;
00135
00136 Vector4 &b = a[++count % 10];
00137 b[0] = V[0].asFloat();
00138 b[1] = V[1].asFloat();
00139 b[2] = V[2].asFloat();
00140 b[3] = V[3].asFloat();
00141 return b;
00142 }
00143
00144 void asVector(Vector4 &dest)
00145 {
00146 dest[0] = V[0].asFloat();
00147 dest[1] = V[1].asFloat();
00148 dest[2] = V[2].asFloat();
00149 dest[3] = V[3].asFloat();
00150 }
00151
00152
00153 void setQuatFromAxisAndAngle(FixedVector &axis, fixed angle);
00154 void getRotationMatrix(fixed *R);
00155 void getOpenGLRotationMatrix(float *R);
00156 void getRelativeVector(FixedVector &result, FixedVector &position);
00157 static void dDQfromW(FixedVector4 &dq, FixedVector &w, FixedVector4 &q);
00158
00159 fixed &operator[](const int m) { DIALOG_ASSERT(m<=3); return V[m]; }
00160 fixed const &operator[](const int m) const { DIALOG_ASSERT(m<=3); return V[m]; }
00161
00162 static FixedVector4 &getNullVector();
00163
00164 protected:
00165 fixed V[4];
00166
00167 };
00168
00169 #endif // !defined(AFX_FixedVector4_H__AD959187_7A1C_11D2_957C_00A0C9A4CA3E__INCLUDED_)
00170