#ifndef GEOMETRY_H #define GEOMETRY_H #include /* * template friend methods aren't compiled on WIN32 systems because * they create an internal compiler error in Visual C++ 6.0 SP5 - sjd */ template class Tuple; template class Point; template class Vector; template class Color; template class TexCoord; template class Ray; template class Matrix; typedef Point Point2i; typedef Point Point2d; typedef Point Point2f; typedef Point Point2c; typedef Point Point3i; typedef Point Point3d; typedef Point Point3f; typedef Point Point3c; typedef Point Point4i; typedef Point Point4d; typedef Point Point4f; typedef Point Point4c; typedef Vector Vector2i; typedef Vector Vector2d; typedef Vector Vector2f; typedef Vector Vector2c; typedef Vector Vector3i; typedef Vector Vector3d; typedef Vector Vector3f; typedef Vector Vector3c; typedef Vector Vector4i; typedef Vector Vector4d; typedef Vector Vector4f; typedef Vector Vector4c; typedef Color Color3d; typedef Color3d Colord; typedef TexCoord TexCoord2d; typedef Ray Rayd; typedef Matrix Matrixd; typedef Matrix Matrixf; template istream& operator >> (istream& stream, Tuple& inputTuple); template ostream& operator << (ostream& stream, const Tuple& outputTuple); template class Tuple { public: Tuple (); Tuple (const Tuple& toCopy); virtual ~Tuple (); Tuple& operator = (const Tuple& toCopy); T const * ptr () const; T& operator [] (int index) const; T& get (int index) const; virtual void glLoad () = 0; int size () { return N; } protected: T* data; }; template class Point : public Tuple { public: Point (T t1 = 0, T t2 = 0, T t3 = 0, T t4 = 0); virtual ~Point (); Point (const Point& toCopy); Point& operator = (const Point& toCopy); bool operator == (const Point& toCompare); bool operator != (const Point& toCompare); Point operator + (const Vector& toAdd); Point& operator += (const Vector& toAdd); #ifndef WIN32 template friend Point operator + (const Vector& v, const Point& p); #endif Point operator - (const Vector& toSub); Point& operator -= (const Vector& toSub); #ifndef WIN32 template friend Point operator - (const Vector& v, const Point& p); #endif void glLoad (); }; template class Vector : public Tuple { public: Vector (T t1 = 0, T t2 = 0, T t3 = 0, T t4 = 0); virtual ~Vector (); Vector (const Point& dest); Vector (const Point& start, const Point& end); Vector (const Vector& toCopy); Vector& operator = (const Point& dest); Vector& operator = (const Vector& toCopy); bool operator == (const Vector& toCompare) const; bool operator != (const Vector& toCompare) const; Vector operator + (const Vector& toAdd) const; Vector& operator += (const Vector& toAdd); Vector operator - () const; Vector operator - (const Vector& toSub) const; Vector& operator -= (const Vector& toSub); Vector operator * (const Vector& toMult) const; Vector& operator *= (const Vector& toMult); Vector operator / (const Vector& toDiv) const; Vector& operator /= (const Vector& toDiv); Vector operator * (double scaleFactor) const; Vector& operator *= (double scaleFactor); #ifndef WIN32 template friend Vector operator * (double scaleFactor, const Vector& v); #endif Vector operator / (double scaleFactor) const; Vector& operator /= (double scaleFactor); T dot (const Vector& toDot); Vector cross (const Vector& toCross); Vector& normalize (); Vector getUnit (); double length (); void glLoad (); }; template class Color : public Tuple { public: Color (T t1 = 0, T t2 = 0, T t3 = 0, T t4 = 0); virtual ~Color (); Color (const Color& toCopy); Color& operator = (const Color& toCopy); Color operator + (const Color& toAdd) const; Color& operator += (const Color& toAdd); Color operator - (const Color& toSub) const; Color& operator -= (const Color& toSub); Color operator * (const Color& toMult) const; Color& operator *= (const Color& toMult); Color operator * (double scaleFactor) const; Color& operator *= (double scaleFactor); #ifndef WIN32 template friend Color operator * (double scaleFactor, const Color& c); #endif Color operator / (double scaleFactor) const; Color& operator /= (double scaleFactor); bool operator == (const Color& toCompare); bool operator != (const Color& toCompare); double intensity () const; void glLoad (); void clampTo (double min, double max); }; template class TexCoord : public Tuple { public: TexCoord (T t1 = 0, T t2 = 0, T t3 = 0, T t4 = 0); virtual ~TexCoord (); TexCoord (const TexCoord& toCopy); TexCoord& operator = (const TexCoord& toCopy); bool operator == (const TexCoord& toCompare); bool operator != (const TexCoord& toCompare); TexCoord operator + (const TexCoord& toAdd) const; TexCoord& operator += (const TexCoord& toAdd); TexCoord operator - (const TexCoord& toSub) const; TexCoord& operator -= (const TexCoord& toSub); TexCoord operator * (const TexCoord& toMult) const; TexCoord& operator *= (const TexCoord& toMult); TexCoord operator * (double scaleFactor) const; TexCoord& operator *= (double scaleFactor); #ifndef WIN32 template friend TexCoord operator * (double scaleFactor, const TexCoord& t); #endif void glLoad (); }; template istream& operator >> (istream& in, Ray& r); template ostream& operator << (ostream& out, const Ray& r); template class Ray { public: Ray (); Ray (const Point& position_, const Vector& direction_); Ray (const Ray& toCopy); Point translate (double alpha); void setPos (Point newPos); Point getPos () const; void setDir (Vector newDir); Vector getDir () const; private: Point position; Vector direction; }; template istream& operator >> (istream& in, Matrix& m); template ostream& operator << (ostream& out, const Matrix& m); template class Matrix { public: Matrix (); Matrix (const Matrix& toCopy); Matrix& operator = (const Matrix& toCopy); T const * ptr () const; T& operator () (int i, int j); T operator () (int i, int j) const; T& get (int i, int j); T get (int i, int j) const; Matrix operator * (const Matrix& toMult) const; Matrix& operator *= (const Matrix& toMult); Matrix leftMult (const Matrix& toMult) const; Matrix rightMult (const Matrix& toMult) const; Point multPos (const Point& toMult) const; Point operator * (const Point& toMult) const; Vector multDir (const Vector& toMult) const; Vector operator * (const Vector& toMult) const; Ray operator * (const Ray& toMult) const; Matrix transpose () const; Matrix invert () const; double det (); static Matrix IdentityMatrix (); private: T data[4][4]; }; #include "geometry.icc" #endif // GEOMETRY_H