#include #include "scene.h" #include "vec.h" using namespace std; Vec3D::Vec3D( const Vec3D& other ) { // compiler don't be stupid, unroll this loop for (int i=0; i<3; ++i) val[i] = other.val[i]; } Vec3D Vec3D::norm() const { Vec3D ret = *this; double m = mag(); for (int i=0; i<3; ++i) ret.val[i] /= m; return ret; } void Vec3D::print() const { cout << "("<val[i] *= -1; return *this; } Vec3D Vec3D::operator*(const double x) const { Vec3D res = *this; for (int i=0; i<3; ++i) res.val[i] *= x; return res; } Vec3D Vec3D::operator/(const double x) const { Vec3D res = *this; for (int i=0; i<3; ++i) res.val[i] /= x; return res; } bool Vec3D::operator==(const Vec3D& other) const { return ((*this) - other).mag() < EPS; } bool Vec3D::operator!=(const Vec3D& other) const { return !((*this) == other); } bool Vec3D::operator>(const Vec3D& other) const { for (int i=0; i<3; ++i) if (this->val[i] > other.val[i]) return true; return false; } ostream& operator<<(ostream& o, const Vec3D& v) { o << "(" << v[0] << ", " << v[1] << ", " << v[2] << ")"; return o; } Ray Ray::mkRayPoints( Vec3D a, Vec3D b ) { Ray r; r.d = b - a; r.o = a; return r; } Ray Ray::mkRayDirected( Vec3D a, Vec3D b ) { Ray r; r.o = a; r.d = b; return r; } double Ray::minDistanceTo(Vec3D p) const { return d.cross(p-o).mag() / d.mag(); } void Ray::print() const { cout << "[Ray "; o.print(); cout << " << L"; d.print(); cout << "]"; }