Do all the clean up needed for Object
This commit is contained in:
parent
2c2bf09140
commit
70576c382a
2 changed files with 75 additions and 36 deletions
|
@ -9,19 +9,18 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "basics.h"
|
#include "object.hh"
|
||||||
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "object.h"
|
|
||||||
#include "basics/basics.hh"
|
#include "basics/basics.hh"
|
||||||
|
|
||||||
|
|
||||||
|
using charles::basics::Ray;
|
||||||
using charles::basics::Vector4;
|
using charles::basics::Vector4;
|
||||||
|
|
||||||
|
|
||||||
namespace charles {
|
namespace charles {
|
||||||
|
|
||||||
#pragma mark - Objects
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* charles::Object::Object --
|
* charles::Object::Object --
|
||||||
*/
|
*/
|
||||||
|
@ -38,6 +37,9 @@ Object::~Object()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::GetMaterial --
|
||||||
|
*/
|
||||||
Material&
|
Material&
|
||||||
Object::GetMaterial()
|
Object::GetMaterial()
|
||||||
{
|
{
|
||||||
|
@ -45,6 +47,9 @@ Object::GetMaterial()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::SetMaterial --
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Object::SetMaterial(const Material& material)
|
Object::SetMaterial(const Material& material)
|
||||||
{
|
{
|
||||||
|
@ -61,28 +66,60 @@ Object::Intersect(const basics::Ray& ray,
|
||||||
Stats& stats)
|
Stats& stats)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
/* TODO: Remove basics:: when the old Ray class goes away. */
|
return DoIntersect(ToObjectSpace(ray), t, stats);
|
||||||
basics::Ray objRay = ToObjectSpace(ray);
|
}
|
||||||
return DoIntersect(objRay, t, stats);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::Normal --
|
||||||
|
*/
|
||||||
|
Vector4
|
||||||
|
Object::Normal(const Vector4& p)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return FromObjectSpace(DoNormal(ToObjectSpace(p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* charles::Object::ToObjectSpace --
|
* charles::Object::ToObjectSpace --
|
||||||
*/
|
*/
|
||||||
/* TODO: Remove basics:: when the old Ray class goes away. */
|
Ray
|
||||||
basics::Ray
|
Object::ToObjectSpace(const Ray& ray)
|
||||||
Object::ToObjectSpace(const basics::Ray& ray)
|
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
/* TODO: Remove basics:: when the old Ray class goes away. */
|
Ray objRay(ray);
|
||||||
basics::Ray objRay(ray);
|
|
||||||
objRay.origin = mTranslation * objRay.origin;
|
objRay.origin = mTranslation * objRay.origin;
|
||||||
objRay.direction = mTranslation * objRay.direction;
|
objRay.direction = mTranslation * objRay.direction;
|
||||||
return objRay;
|
return objRay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::ToObjectSpace --
|
||||||
|
*/
|
||||||
|
Vector4
|
||||||
|
Object::ToObjectSpace(const Vector4& v)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mTranslation * v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::FromObjectSpace --
|
||||||
|
*/
|
||||||
|
Vector4
|
||||||
|
Object::FromObjectSpace(const Vector4& v)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::Object::Write --
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
Object::Write(std::ostream& ost)
|
Object::Write(std::ostream& ost)
|
||||||
const
|
const
|
||||||
|
@ -91,6 +128,9 @@ Object::Write(std::ostream& ost)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* charles::operator<< --
|
||||||
|
*/
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<<(std::ostream& ost,
|
operator<<(std::ostream& ost,
|
||||||
const Object& object)
|
const Object& object)
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
/* object.h
|
/* object.h
|
||||||
*
|
* vim: set tw=80:
|
||||||
* Declaration of abstract, top-level scene objects. The Object class is the top of this hierarchy. All other scene
|
|
||||||
* objects are based on it. The Shape class defines a visible shape in the scene.
|
|
||||||
*
|
|
||||||
* Eryn Wells <eryn@erynwells.me>
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -13,7 +10,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "basics.h"
|
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
#include "stats.hh"
|
#include "stats.hh"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
@ -30,9 +26,6 @@ struct Object
|
||||||
Object(const basics::Vector4& origin = basics::Vector4());
|
Object(const basics::Vector4& origin = basics::Vector4());
|
||||||
virtual ~Object();
|
virtual ~Object();
|
||||||
|
|
||||||
Vector3 GetOrigin() const;
|
|
||||||
void SetOrigin(const Vector3& origin);
|
|
||||||
|
|
||||||
Material& GetMaterial();
|
Material& GetMaterial();
|
||||||
void SetMaterial(const Material& material);
|
void SetMaterial(const Material& material);
|
||||||
|
|
||||||
|
@ -45,25 +38,37 @@ struct Object
|
||||||
bool Intersect(const basics::Ray& ray, TVector& t, Stats& stats) const;
|
bool Intersect(const basics::Ray& ray, TVector& t, Stats& stats) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the given ray intersects with this object. All intersection
|
* Get the normal vector at the given point p. p is assumed to be on the
|
||||||
* t values are returned in the `t` argument, in increasing order.
|
* surface.
|
||||||
*
|
|
||||||
* @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, Stats& stats) const = 0;
|
basics::Vector4 Normal(const basics::Vector4& p) const;
|
||||||
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
|
||||||
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
|
||||||
|
|
||||||
|
/** Write a string representation of this object to the stream. */
|
||||||
virtual void Write(std::ostream& ost) const;
|
virtual void Write(std::ostream& ost) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Do the actual intersection work. Subclasses are expected to override
|
||||||
|
* this.
|
||||||
|
*/
|
||||||
virtual bool DoIntersect(const basics::Ray& ray, TVector& t, Stats& stats) const = 0;
|
virtual bool DoIntersect(const basics::Ray& ray, TVector& t, Stats& stats) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do the actual work of finding a normal for point p. Subclasses are
|
||||||
|
* expected to override this.
|
||||||
|
*/
|
||||||
|
virtual basics::Vector4 DoNormal(const basics::Vector4& p) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** Convert `ray` to object space from global space. */
|
||||||
basics::Ray ToObjectSpace(const basics::Ray& ray) const;
|
basics::Ray ToObjectSpace(const basics::Ray& ray) const;
|
||||||
|
|
||||||
|
/** Convert `v` to object space from global space. */
|
||||||
|
basics::Vector4 ToObjectSpace(const basics::Vector4& v) const;
|
||||||
|
|
||||||
|
/** Convert `v` to global space from object space. */
|
||||||
|
basics::Vector4 FromObjectSpace(const basics::Vector4& v) const;
|
||||||
|
|
||||||
/** A translation matrix from global coordinates to this object's space. */
|
/** A translation matrix from global coordinates to this object's space. */
|
||||||
basics::Matrix4 mTranslation;
|
basics::Matrix4 mTranslation;
|
||||||
|
|
||||||
|
@ -72,13 +77,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** Write a string representation of the Object to an output stream. */
|
||||||
* Write a string representation of the Object to an output stream.
|
|
||||||
*
|
|
||||||
* @param [in] ost The output stream
|
|
||||||
* @param [in] object The object
|
|
||||||
* @returns The output stream
|
|
||||||
*/
|
|
||||||
std::ostream& operator<<(std::ostream& ost, const Object& object);
|
std::ostream& operator<<(std::ostream& ost, const Object& object);
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
Loading…
Add table
Add a link
Reference in a new issue