Object::Intersect

A new intersect method that converts to object space before doing the intersection. Now all objects are at their own origin!
This commit is contained in:
Eryn Wells 2014-08-09 09:59:00 -07:00
parent 519eb347d1
commit d0d667d6d2
2 changed files with 50 additions and 1 deletions

View file

@ -22,6 +22,9 @@ namespace charles {
#pragma mark - Objects
/*
* charles::Object::Object --
*/
Object::Object(const Vector4& origin)
: mTranslation(basics::TranslationMatrix(origin.X(), origin.Y(), origin.Z())),
mMaterial()
@ -49,6 +52,37 @@ Object::SetMaterial(const Material& 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