charles/src/object.cc

103 lines
1.6 KiB
C++
Raw Normal View History

2013-09-07 16:09:19 -07:00
/* object.c
*
* Definition of generic scene objects.
2013-09-07 16:09:19 -07:00
*
* Eryn Wells <eryn@erynwells.me>
*/
#include <cassert>
#include <cmath>
#include <cstdlib>
2013-09-07 22:22:27 -07:00
2013-09-07 16:48:50 -07:00
#include "basics.h"
#include "material.h"
2013-09-07 16:09:19 -07:00
#include "object.h"
#include "basics/basics.hh"
using charles::basics::Vector4;
2013-09-07 16:09:19 -07:00
namespace charles {
#pragma mark - Objects
2013-09-07 16:48:50 -07:00
/*
* charles::Object::Object --
*/
Object::Object(const Vector4& origin)
: mTranslation(basics::TranslationMatrix(origin.X(), origin.Y(), origin.Z())),
mMaterial()
{ }
/*
2014-08-09 08:59:11 -07:00
* charles::Object::~Object --
*/
Object::~Object()
{ }
2013-09-07 18:26:32 -07:00
Material&
Object::GetMaterial()
{
return mMaterial;
}
void
Object::SetMaterial(const Material& material)
{
mMaterial = material;
}
/*
* charles::Object::Intersect --
*/
bool
Object::Intersect(const basics::Ray& ray,
TVector& t,
Stats& stats)
const
{
/* TODO: Remove basics:: when the old Ray class goes away. */
basics::Ray objRay = ToObjectSpace(ray);
return DoIntersect(objRay, t, stats);
}
/*
* charles::Object::ToObjectSpace --
*/
/* TODO: Remove basics:: when the old Ray class goes away. */
basics::Ray
Object::ToObjectSpace(const basics::Ray& ray)
const
{
/* TODO: Remove basics:: when the old Ray class goes away. */
basics::Ray objRay(ray);
objRay.origin = mTranslation * objRay.origin;
objRay.direction = mTranslation * objRay.direction;
return objRay;
}
void
Object::Write(std::ostream& ost)
const
{
ost << "[Object]";
}
std::ostream&
operator<<(std::ostream& ost,
const Object& object)
{
object.Write(ost);
return ost;
}
} /* namespace charles */