diff --git a/src/object.cc b/src/object.cc index 2e8a00f..d23d8a6 100644 --- a/src/object.cc +++ b/src/object.cc @@ -13,6 +13,8 @@ #include "material.h" #include "object.h" +namespace charles { + #pragma mark - Objects /* @@ -30,86 +32,42 @@ Object::Object() * * Constructor. Create a new Object with an origin at o. */ -Object::Object(Vector3 o) - : origin(o) +Object::Object(Vector3 origin) + : mOrigin(origin), + mMaterial() { } -/* - * Object::get_origin -- - * Object::set_origin -- - * - * Get and set the Object's origin. - */ Vector3 -Object::get_origin() +Object::GetOrigin() const { - return origin; + return mOrigin; } + +Object::~Object() +{ } + + void -Object::set_origin(const Vector3& v) +Object::SetOrigin(const Vector3& origin) { - origin = v; + mOrigin = origin; } -std::ostream & -operator<<(std::ostream &os, const Object &o) +Material& +Object::GetMaterial() { - // Stream objects like this: [Object origin] - os << "[Object " << o.origin << "]"; - return os; + return mMaterial; } -#pragma mark - Shapes - -/* - * Shape::Shape -- - * - * Default constructor. Create a new Shape with an origin at (0, 0, 0). - */ -Shape::Shape() - : Shape(Vector3::Zero) -{ } - - -/* - * Shape::Shape -- - * - * Constructor. Create a new Shape with an origin at o. - */ -Shape::Shape(Vector3 o) - : Object(o), - material(NULL) -{ } - - -/* - * Shape::~Shape() -- - * - * Destructor. - */ -Shape::~Shape() -{ } - - -/* - * Shape::get_material -- - * Shape::set_material -- - * - * Get and set the Material applied to this shape. - */ -Material* -Shape::get_material() - const -{ - return material; -} void -Shape::set_material(Material *mat) +Object::SetMaterial(const Material& material) { - material = mat; + mMaterial = material; } + +} /* namespace charles */ diff --git a/src/object.h b/src/object.h index 7d47586..f5052a8 100644 --- a/src/object.h +++ b/src/object.h @@ -10,47 +10,49 @@ #define __OBJECT_H__ #include +#include #include "basics.h" #include "material.h" #include "texture.h" +#include "types.hh" +namespace charles { -class Object +struct Object { -public: + typedef std::shared_ptr Ptr; + Object(); Object(Vector3 o); + virtual ~Object(); - Vector3 get_origin() const; - void set_origin(const Vector3& v); + Vector3 GetOrigin() const; + void SetOrigin(const Vector3& origin); - friend std::ostream &operator<<(std::ostream &os, const Object &o); + Material& GetMaterial(); + void SetMaterial(const Material& material); -private: - Vector3 origin; -}; - -std::ostream &operator<<(std::ostream &os, const Object &o); - - -class Shape - : public Object -{ -public: - Shape(); - Shape(Vector3 o); - virtual ~Shape(); - - Material* get_material() const; - void set_material(Material *mat); - - virtual int does_intersect(const Ray &ray, float **t) const = 0; + /** + * Determines if the given ray intersects with this object. All intersection + * t values are returned in the `t` argument, in increasing order. + * + * @param [in] ray The ray to test for intersection + * @param [out] t A vector of all intersection t values + * @return `true` if the ray intersects with this object + */ + virtual bool DoesIntersect(const Ray& ray, TVector& t) const = 0; virtual bool point_is_on_surface(const Vector3 &p) const = 0; virtual Vector3 compute_normal(const Vector3 &p) const = 0; private: - Material *material; + /** The location of this object. */ + Vector3 mOrigin; + + /** This object's material, surface properties, etc. */ + Material mMaterial; }; +} /* namespace charles */ + #endif