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:
parent
ac8421b5e1
commit
2036521f42
2 changed files with 48 additions and 88 deletions
|
@ -13,6 +13,8 @@
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
|
|
||||||
#pragma mark - Objects
|
#pragma mark - Objects
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -30,86 +32,42 @@ Object::Object()
|
||||||
*
|
*
|
||||||
* Constructor. Create a new Object with an origin at o.
|
* Constructor. Create a new Object with an origin at o.
|
||||||
*/
|
*/
|
||||||
Object::Object(Vector3 o)
|
Object::Object(Vector3 origin)
|
||||||
: origin(o)
|
: mOrigin(origin),
|
||||||
|
mMaterial()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Object::get_origin --
|
|
||||||
* Object::set_origin --
|
|
||||||
*
|
|
||||||
* Get and set the Object's origin.
|
|
||||||
*/
|
|
||||||
Vector3
|
Vector3
|
||||||
Object::get_origin()
|
Object::GetOrigin()
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
return origin;
|
return mOrigin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Object::~Object()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Object::set_origin(const Vector3& v)
|
Object::SetOrigin(const Vector3& origin)
|
||||||
{
|
{
|
||||||
origin = v;
|
mOrigin = origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::ostream &
|
Material&
|
||||||
operator<<(std::ostream &os, const Object &o)
|
Object::GetMaterial()
|
||||||
{
|
{
|
||||||
// Stream objects like this: [Object origin]
|
return mMaterial;
|
||||||
os << "[Object " << o.origin << "]";
|
|
||||||
return os;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
void
|
||||||
Shape::set_material(Material *mat)
|
Object::SetMaterial(const Material& material)
|
||||||
{
|
{
|
||||||
material = mat;
|
mMaterial = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} /* namespace charles */
|
||||||
|
|
52
src/object.h
52
src/object.h
|
@ -10,47 +10,49 @@
|
||||||
#define __OBJECT_H__
|
#define __OBJECT_H__
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
#include "types.hh"
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
|
|
||||||
class Object
|
struct Object
|
||||||
{
|
{
|
||||||
public:
|
typedef std::shared_ptr<Object> Ptr;
|
||||||
|
|
||||||
Object();
|
Object();
|
||||||
Object(Vector3 o);
|
Object(Vector3 o);
|
||||||
|
virtual ~Object();
|
||||||
|
|
||||||
Vector3 get_origin() const;
|
Vector3 GetOrigin() const;
|
||||||
void set_origin(const Vector3& v);
|
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;
|
* Determines if the given ray intersects with this object. All intersection
|
||||||
};
|
* t values are returned in the `t` argument, in increasing order.
|
||||||
|
*
|
||||||
std::ostream &operator<<(std::ostream &os, const Object &o);
|
* @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
|
||||||
class Shape
|
*/
|
||||||
: public Object
|
virtual bool DoesIntersect(const Ray& ray, TVector& t) const = 0;
|
||||||
{
|
|
||||||
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;
|
|
||||||
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
||||||
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Material *material;
|
/** The location of this object. */
|
||||||
|
Vector3 mOrigin;
|
||||||
|
|
||||||
|
/** This object's material, surface properties, etc. */
|
||||||
|
Material mMaterial;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} /* namespace charles */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue