00001
00012 #ifndef CVECTOR3F_H
00013 #define CVECTOR3F_H
00014
00015
00020 class CVector3f
00021 {
00022 public:
00023 float x;
00024 float y;
00025 float z;
00031 inline CVector3f(float a = 0, float b = 0, float c = 0)
00032 { x = a; y = b; z = c; }
00033
00038 inline CVector3f(const CVector3f& v)
00039 { x = v.x; y = v.y; z = v.z; }
00040
00045 inline float& operator[] (int i)
00046 {
00047 switch(i)
00048 {
00049 case 0: return x;
00050 case 1: return y;
00051 case 2: return z;
00052 default: POP_ILLEGAL("Component index not valid."); return x;
00053 }
00054 }
00055
00061 inline float Norm() const
00062 { return(sqrtf(x*x + y*y + z*z)); }
00063
00071 inline void Normalize()
00072 { float Temp = sqrtf(x*x + y*y + z*z); x /= Temp; y /= Temp; z /= Temp; }
00073
00074
00080 inline CVector3f operator + (const CVector3f &v) const
00081 {
00082 return CVector3f(x + v.x, y + v.y, z + v.z);
00083 }
00084
00090 inline CVector3f operator - (const CVector3f &v) const
00091 {
00092 return CVector3f(x - v.x, y - v.y, z - v.z);
00093 }
00094
00100 inline float operator * (const CVector3f &v) const
00101 {
00102 return (x*v.x + y*v.y + z*v.z);
00103 }
00104
00117 inline CVector3f operator ^ (const CVector3f &v) const
00118 {
00119 return CVector3f(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
00120 }
00121
00127 inline CVector3f operator * (float k) const
00128 {
00129 return CVector3f(k*x, k*y, k*z);
00130 }
00131
00139 inline CVector3f operator / (float k) const
00140 {
00141 return CVector3f(x/k, y/k, z/k);
00142 }
00143
00150 inline CVector3f operator >> (const CVector3f &v) const
00151 {
00152 float Temp = (x*v.x + y*v.y + z*v.z) / (v.x*v.x + v.y*v.y + v.z*v.z);
00153 return CVector3f(Temp*v.x, Temp*v.y, Temp*v.z);
00154 }
00155
00161 inline CVector3f operator - () const
00162 {
00163 return CVector3f(-x, -y, -z);
00164 }
00165
00166
00170 inline CVector3f& operator += (const CVector3f &v)
00171 {
00172 x += v.x;
00173 y += v.y;
00174 z += v.z;
00175 return (*this);
00176 }
00177
00181 inline CVector3f& operator -= (const CVector3f &v)
00182 {
00183 x -= v.x;
00184 y -= v.y;
00185 z -= v.z;
00186 return (*this);
00187 }
00188
00192 inline CVector3f& operator ^= (const CVector3f &v)
00193 {
00194 (*this) = CVector3f(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
00195 return (*this);
00196 }
00197
00201 inline CVector3f& operator *= (float k)
00202 {
00203 x *= k;
00204 y *= k;
00205 z *= k;
00206 return (*this);
00207 }
00208
00212 inline CVector3f& operator /= (float k)
00213 {
00214 x /= k;
00215 y /= k;
00216 z /= k;
00217 return (*this);
00218 }
00219
00223 inline CVector3f& operator >>= (const CVector3f &v)
00224 {
00225 float Temp = (x*v.x + y*v.y + z*v.z) / (v.x*v.x + v.y*v.y + v.z*v.z);
00226 x = v.x * Temp;
00227 y = v.y * Temp;
00228 z = v.z * Temp;
00229 return (*this);
00230 }
00231
00232 friend CVector3f operator * (float k, const CVector3f &v);
00233 };
00234
00240 inline CVector3f operator * (float k, const CVector3f &v)
00241 {
00242 return CVector3f(k*v.x, k*v.y, k*v.z);
00243 }
00244
00248 inline std::ostream& operator << (std::ostream& o, const CVector3f &v)
00249 {
00250 o << "( " << v.x << " , " << v.y << " , " << v.z << " )";
00251 return o;
00252 }
00253
00254
00255 #endif // CVECTOR3F_H
00256