diff --git a/src/object.cc b/src/object.cc index b74dcbe..866ffc3 100644 --- a/src/object.cc +++ b/src/object.cc @@ -12,32 +12,26 @@ #include "basics.h" #include "material.h" #include "object.h" +#include "basics/basics.hh" + + +using charles::basics::Vector4; + namespace charles { #pragma mark - Objects -/* - * Object::Object -- - * - * Default constructor. Create a new Object with an origin at (0, 0, 0). - */ -Object::Object() - : Object(Vector3::Zero) -{ } - - -/* - * Object::Object -- - * - * Constructor. Create a new Object with an origin at o. - */ -Object::Object(Vector3 origin) - : mOrigin(origin), +Object::Object(const Vector4& origin) + : mTranslation(basics::TranslationMatrix(origin.X(), origin.Y(), origin.Z())), mMaterial() { } +/* + */ + + Vector3 Object::GetOrigin() const diff --git a/src/object.h b/src/object.h index 4f906a7..4480edb 100644 --- a/src/object.h +++ b/src/object.h @@ -18,6 +18,8 @@ #include "stats.hh" #include "texture.h" #include "types.hh" +#include "basics/basics.hh" + namespace charles { @@ -25,8 +27,7 @@ struct Object { typedef std::shared_ptr Ptr; - Object(); - Object(Vector3 o); + Object(const basics::Vector4& origin = basics::Vector4()); virtual ~Object(); Vector3 GetOrigin() const; diff --git a/src/objectSphere.cc b/src/objectSphere.cc index 5adfb4d..d0ea008 100644 --- a/src/objectSphere.cc +++ b/src/objectSphere.cc @@ -14,32 +14,19 @@ #include "object.h" #include "objectSphere.hh" + +using charles::basics::Vector4; + + namespace charles { /* - * Sphere::Sphere -- - * - * Default constructor. Create a Sphere with radius 1.0. + * charles::Sphere::Sphere -- */ -Sphere::Sphere() - : Sphere(1.0) -{ } - - -/* - * Sphere::Sphere -- - * - * Constructor. Create a Sphere with the given radius. - */ -Sphere::Sphere(Double r) - : Sphere(Vector3::Zero, r) -{ } - - -Sphere::Sphere(Vector3 o, - Double r) - : Object(o), - mRadius(r) +Sphere::Sphere(const Vector4& origin, + Double radius) + : Object(origin), + mRadius(radius) { } @@ -69,13 +56,10 @@ Sphere::DoesIntersect(const Ray& ray, { stats.sphereIntersectionTests++; - /* Origin of the vector in object space. */ - Vector3 rayOriginObj = ray.origin - GetOrigin(); - /* Coefficients for quadratic equation. */ Double a = ray.direction.dot(ray.direction); - Double b = ray.direction.dot(rayOriginObj) * 2.0; - Double c = rayOriginObj.dot(rayOriginObj) - (mRadius * mRadius); + Double b = ray.direction.dot(ray.origin) * 2.0; + Double c = ray.origin.dot(ray.origin) - (mRadius * mRadius); /* Discriminant for the quadratic equation. */ Double discrim = (b * b) - (4.0 * a * c); diff --git a/src/objectSphere.hh b/src/objectSphere.hh index 12f9061..9597868 100644 --- a/src/objectSphere.hh +++ b/src/objectSphere.hh @@ -10,6 +10,8 @@ #include "basics.h" #include "object.h" +#include "basics/basics.hh" + namespace charles { @@ -17,9 +19,7 @@ class Sphere : public Object { public: - Sphere(); - Sphere(Double r); - Sphere(Vector3 o, Double r); + Sphere(const basics::Vector4& origin = basics::Vector4(), Double radius = 1.0); Double GetRadius() const; void SetRadius(Double r);