#ifndef VEC_H #define VEC_H #include #include class Vec3D { private: double val[3]; public: Vec3D() { val[0]=0; val[1]=0; val[2]=0; } Vec3D( const Vec3D& other ); Vec3D(double v1, double v2, double v3) { setValues(v1,v2,v3); } void setValues(double v1, double v2, double v3) { val[0] = v1, val[1] = v2, val[2] = v3; } void setVal0(double v) { val[0] = v; } void setVal1(double v) { val[1] = v; } void setVal2(double v) { val[2] = v; } double getV0() const { return val[0]; } double getV1() const { return val[1]; } double getV2() const { return val[2]; } void print() const; Vec3D cross( const Vec3D& v) const; double dot( const Vec3D& v) const; double operator[](int i) const { return val[i]; } Vec3D operator=(const Vec3D& other); Vec3D operator+(const Vec3D& other) const; Vec3D operator-(const Vec3D& other) const; Vec3D operator-(); // unary minus Vec3D operator*(const double x) const; Vec3D operator/(const double x) const; bool operator==(const Vec3D& other) const; bool operator!=(const Vec3D& other) const; bool operator>(const Vec3D& other) const; double mag() const { return sqrt(val[0]*val[0] + val[1]*val[1] + val[2]*val[2]); } Vec3D norm() const; }; std::ostream& operator<<(std::ostream& o, const Vec3D& v); class Ray { private: Vec3D o, d; //origin, direction Vec3D* col; Ray() { col = NULL; } //hidden constructor (use mkRayPoints) public: // start at 'a' going in 'b-a' static Ray mkRayPoints( Vec3D a, Vec3D b ); // start at 'a' going in 'b' static Ray mkRayDirected( Vec3D a, Vec3D b ); ~Ray() { collide(NULL); } const Vec3D getDir() const { return d; } const Vec3D getOrig() const { return o; } Vec3D* collide() { return col; } void collide(Vec3D* c) { if (col) delete col; col = c; } //Ray operator=(const Ray& other); void print() const; // Return me the *minimum* distance from this ray to the given point, thanks! double minDistanceTo(Vec3D p) const; }; #endif