00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #ifndef PI
00025 #define PI (3.141592654)
00026 #endif
00027
00028 #define DegToRad(d) ((d)*PI/180.0)
00029 #define RadToDeg(r) ((r)*180.0/PI)
00030 #define Sgn(d) (IsZero(d) ? 0 : (d) > 0 ? 1 : -1)
00031 #define SgnPow(d, p) (IsZero(d) ? 0 : (pow(fabs(d), p) * Sgn(d)))
00032
00033 class Vector
00034 {
00035 public:
00036 double x, y, z;
00037
00038 Vector() {x = y = z = 0;}
00039 Vector(double x, double y, double z);
00040 void Set(double x, double y, double z);
00041
00042 Vector Normal(Vector& a, Vector& b);
00043 double Angle(Vector& a, Vector& b);
00044 double Angle(Vector& a);
00045 void Angle(double& u, double& v);
00046 Vector Angle();
00047
00048 Vector Unit();
00049 Vector& Unitalize();
00050 double Length();
00051 double Sum();
00052 double CrossSum();
00053 Vector Cross();
00054 Vector Pow(double exp);
00055
00056 Vector& Min(Vector& a);
00057 Vector& Max(Vector& a);
00058 Vector Abs();
00059
00060 Vector Reflect(Vector& n);
00061 Vector Refract(Vector& n, double nFront, double nBack, double* nOut = NULL);
00062 Vector Refract2(Vector& n, double nFrom, double nTo, double* nOut = NULL);
00063
00064 Vector operator - ();
00065 double& operator [] (int i);
00066
00067 double operator | (Vector& v);
00068 Vector operator % (Vector& v);
00069
00070 bool operator == (const Vector& v) const;
00071 bool operator != (const Vector& v) const;
00072
00073 Vector operator + (double d);
00074 Vector operator + (Vector& v);
00075 Vector operator - (double d);
00076 Vector operator - (Vector& v);
00077 Vector operator * (double d);
00078 Vector operator * (Vector& v);
00079 Vector operator / (double d);
00080 Vector operator / (Vector& v);
00081 Vector& operator += (double d);
00082 Vector& operator += (Vector& v);
00083 Vector& operator -= (double d);
00084 Vector& operator -= (Vector& v);
00085 Vector& operator *= (double d);
00086 Vector& operator *= (Vector& v);
00087 Vector& operator /= (double d);
00088 Vector& operator /= (Vector& v);
00089 };
00090
00091 class Ray
00092 {
00093 public:
00094 Vector p, d;
00095
00096 Ray() {}
00097 Ray(Vector& p, Vector& d);
00098 void Set(Vector& p, Vector& d);
00099
00100 double GetDistanceFrom(Ray& r);
00101 double GetDistanceFrom(Vector& v);
00102
00103 Vector operator [] (double t);
00104 };
00105
00106 class XForm
00107 {
00108 class Matrix
00109 {
00110 public:
00111 double mat[4][4];
00112
00113 Matrix();
00114 void Initalize();
00115
00116 Matrix operator * (Matrix& m);
00117 Matrix& operator *= (Matrix& m);
00118 } m;
00119
00120 bool m_isWorldToLocal;
00121
00122 public:
00123 XForm() {}
00124 XForm(Ray& r, Vector& s, bool isWorldToLocal = true);
00125
00126 void Initalize();
00127 void Initalize(Ray& r, Vector& s, bool isWorldToLocal = true);
00128
00129 void operator *= (Vector& s);
00130 void operator += (Vector& t);
00131 void operator <<= (Vector& r);
00132
00133 void operator /= (Vector& s);
00134 void operator -= (Vector& t);
00135 void operator >>= (Vector& r);
00136
00137
00138 Vector operator < (Vector& n);
00139 Vector operator << (Vector& v);
00140 Ray operator << (Ray& r);
00141 };