Update code style for Object

- Remove Shape, because it seems to be mostly extra. All renderable objects now
derive from Object, rather than Shape
- Light (which inherited from Object before) now defines its own origin, but
this is coming in a later commit...
- Use charles namespace

- Use a std::vector<double> instead of float** to pass back intersection points.
This is kind of a biggie because it made the render process 50% slower :( I'll
have to work out why and maybe fix it...
This commit is contained in:
Eryn Wells 2014-07-20 16:46:49 -07:00
parent ac8421b5e1
commit 2036521f42
2 changed files with 48 additions and 88 deletions

View file

@ -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 */

View file

@ -10,47 +10,49 @@
#define __OBJECT_H__
#include <iostream>
#include <vector>
#include "basics.h"
#include "material.h"
#include "texture.h"
#include "types.hh"
namespace charles {
class Object
struct Object
{
public:
typedef std::shared_ptr<Object> 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