00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #pragma once
00015
00016 #include "GeomExport.h"
00017 #include "maxheap.h"
00018 #include "point3.h"
00019 #include "assert1.h"
00020
00021 class GEOMEXPORT Point4;
00022
00043 class GEOMEXPORT Point4: public MaxHeapOperators {
00044 public:
00045 float x,y,z,w;
00046
00047
00049 Point4(){ }
00051 Point4(float X, float Y, float Z, float W) {
00052 x = X; y = Y; z = Z; w = W;
00053 }
00055 Point4(double X, double Y, double Z, double W) {
00056 x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
00057 }
00059 Point4(int X, int Y, int Z, int W) {
00060 x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
00061 }
00063 Point4(const Point3& a, float W=0.0f) {
00064 x = a.x; y = a.y; z = a.z; w = W;
00065 }
00066
00067 Point4(const Point4& a) {
00068 x = a.x; y = a.y; z = a.z; w = a.w;
00069 }
00071 Point4(float af[4]) {
00072 x = af[0]; y = af[1]; z = af[2]; w = af[3];
00073 }
00074
00075
00076 static const Point4 Origin;
00077 static const Point4 XAxis;
00078 static const Point4 YAxis;
00079 static const Point4 ZAxis;
00080 static const Point4 WAxis;
00081
00085 float& operator[](int i) {
00086 return (&x)[i];
00087 }
00091 const float& operator[](int i) const {
00092 return (&x)[i];
00093 }
00094
00095
00097 operator float*() {
00098 return(&x);
00099 }
00100
00101
00103 Point4 operator-() const {
00104 return(Point4(-x,-y,-z, -w));
00105 }
00107 Point4 operator+() const {
00108 return *this;
00109 }
00110
00111
00112 float Length() const;
00113 float FLength() const;
00114 float LengthSquared() const;
00115 int MaxComponent() const;
00116 int MinComponent() const;
00117 Point4 Normalize() const;
00118 Point4 FNormalize() const;
00119
00120
00123 inline Point4& operator-=(const Point4&);
00126 inline Point4& operator+=(const Point4&);
00129 inline Point4& operator*=(float);
00132 inline Point4& operator/=(float);
00136 inline Point4& operator*=(const Point4&);
00149 inline Point4& Set(float X, float Y, float Z, float W);
00150
00151
00154 int operator==(const Point4& p) const {
00155 return ((p.x==x)&&(p.y==y)&&(p.z==z)&&(p.w==w));
00156 }
00157 int operator!=(const Point4& p) const {
00158 return ((p.x!=x)||(p.y!=y)||(p.z!=z)||(p.w!=w));
00159 }
00160
00171 int Equals(const Point4& p, float epsilon = 1E-6f);
00172
00173
00174 Point4& Unify();
00175 float LengthUnify();
00176
00177
00180 inline Point4 operator-(const Point4&) const;
00183 inline Point4 operator+(const Point4&) const;
00187 inline Point4 operator/(const Point4&) const;
00192 inline Point4 operator*(const Point4&) const;
00193
00194 inline float operator%(const Point4&) const;
00195 };
00196
00197 GEOMEXPORT float Length(const Point4&);
00198 GEOMEXPORT float FLength(const Point4&);
00199 GEOMEXPORT float LengthSquared(const Point4&);
00200 GEOMEXPORT int MaxComponent(const Point4&);
00201 GEOMEXPORT int MinComponent(const Point4&);
00202 GEOMEXPORT Point4 Normalize(const Point4&);
00203 GEOMEXPORT Point4 FNormalize(const Point4&);
00204 GEOMEXPORT Point4 CrossProd(const Point4& a, const Point4& b, const Point4& c);
00205
00206
00207
00208 inline float Point4::Length() const {
00209 return (float)sqrt(x*x+y*y+z*z+w*w);
00210 }
00211
00212 inline float Point4::FLength() const {
00213 return Sqrt(x*x+y*y+z*z+w*w);
00214 }
00215
00216 inline float Point4::LengthSquared() const {
00217 return (x*x+y*y+z*z+w*w);
00218 }
00219
00220 inline float Length(const Point4& v) {
00221 return v.Length();
00222 }
00223
00224 inline float FLength(const Point4& v) {
00225 return v.FLength();
00226 }
00227
00228 inline float LengthSquared(const Point4& v) {
00229 return v.LengthSquared();
00230 }
00231
00232 inline Point4& Point4::operator-=(const Point4& a) {
00233 x -= a.x; y -= a.y; z -= a.z; w -= a.w;
00234
00235 return *this;
00236 }
00237
00238 inline Point4& Point4::operator+=(const Point4& a) {
00239 x += a.x; y += a.y; z += a.z; w += a.w;
00240 return *this;
00241 }
00242
00243 inline Point4& Point4::operator*=(float f) {
00244 x *= f; y *= f; z *= f; w *= f;
00245
00246 return *this;
00247 }
00248
00249 inline Point4& Point4::operator/=(float f) {
00250 if (f==0.0f) f = .000001f;
00251 x /= f; y /= f; z /= f; w /= f;
00252
00253 return *this;
00254 }
00255
00256 inline Point4& Point4::operator*=(const Point4& a) {
00257 x *= a.x; y *= a.y; z *= a.z; w *= a.w;
00258
00259 return *this;
00260 }
00261
00262 inline Point4& Point4::Set(float X, float Y, float Z, float W) {
00263 x = X;
00264 y = Y;
00265 z = Z;
00266 w = W;
00267
00268 return *this;
00269 }
00270
00271 inline Point4 Point4::operator-(const Point4& b) const {
00272 return(Point4(x-b.x,y-b.y,z-b.z, w-b.w));
00273 }
00274
00275 inline Point4 Point4::operator+(const Point4& b) const {
00276 return(Point4(x+b.x,y+b.y,z+b.z, w+b.w));
00277 }
00278
00279 inline Point4 Point4::operator/(const Point4& b) const {
00280 assert(b.x != 0.0f && b.y != 0.0f && b.z != 0.0f && b.w != 0.0f);
00281 return Point4(x/b.x,y/b.y,z/b.z,w/b.w);
00282 }
00283
00284 inline Point4 Point4::operator*(const Point4& b) const {
00285 return Point4(x*b.x, y*b.y, z*b.z,w*b.w);
00286 }
00287
00290 inline Point4 operator*(float f, const Point4& a) {
00291 return(Point4(a.x*f, a.y*f, a.z*f, a.w*f));
00292 }
00293
00296 inline Point4 operator*(const Point4& a, float f) {
00297 return(Point4(a.x*f, a.y*f, a.z*f, a.w*f));
00298 }
00299
00302 inline Point4 operator/(const Point4& a, float f) {
00303 assert( f != 0.0f );
00304 return(Point4(a.x/f, a.y/f, a.z/f, a.w/f));
00305 }
00306
00309 inline Point4 operator+(const Point4& a, float f) {
00310 return(Point4(a.x+f, a.y+f, a.z+f, a.w+f));
00311 }
00312
00313 inline float Point4::operator%(const Point4& b) const {
00314 return (x*b.x + y*b.y + z*b.z + w*b.w);
00315 }
00316
00317 inline int Point4::Equals(const Point4& p, float epsilon) {
00318 return (fabs(p.x - x) <= epsilon && fabs(p.y - y) <= epsilon
00319 && fabs(p.z - z) <= epsilon && fabs(p.w - w) <= epsilon);
00320 }
00321
00322 inline float DotProd(const Point4& a, const Point4& b) {
00323 return(a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w);
00324 }
00325
00326