From 8af03c3f3d7ce9fe2d5bf243f53065e9c2ccb7b0 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 15 Aug 2014 22:32:44 -0700 Subject: [PATCH] Implement Object::Place Places the object by manipulating its translation matrix. --- src/basics/matrix.cc | 10 ++++++++++ src/basics/matrix.hh | 1 + src/object.cc | 10 ++++++++++ src/object.hh | 3 +++ 4 files changed, 24 insertions(+) diff --git a/src/basics/matrix.cc b/src/basics/matrix.cc index 92fa60a..1a89f7f 100644 --- a/src/basics/matrix.cc +++ b/src/basics/matrix.cc @@ -44,6 +44,16 @@ Matrix4::Identity() } +/* + * charles::basics::Translation -- + */ +/* static */ Matrix4 +Matrix4::Translation(const Vector4& p) +{ + return Translation(p.X(), p.Y(), p.Z()); +} + + /* * charles::basics::TranslationMatrix -- */ diff --git a/src/basics/matrix.hh b/src/basics/matrix.hh index b6bae04..4e6ebdf 100644 --- a/src/basics/matrix.hh +++ b/src/basics/matrix.hh @@ -30,6 +30,7 @@ struct Matrix4 /** Create a 4x4 translation matrix. */ static Matrix4 Translation(Double x, Double y, Double z); + static Matrix4 Translation(const Vector4 &p); Matrix4(); Matrix4(const Double *data); diff --git a/src/object.cc b/src/object.cc index 3b0bdf6..e9afe35 100644 --- a/src/object.cc +++ b/src/object.cc @@ -47,6 +47,16 @@ Object::GetMaterial() } +/* + * charles::Object::Place -- + */ +void +Object::Place(const Vector4 &p) +{ + mTranslation = Matrix4::Translation(p); +} + + /* * charles::Object::SetMaterial -- */ diff --git a/src/object.hh b/src/object.hh index 9bb47a7..6b9a58b 100644 --- a/src/object.hh +++ b/src/object.hh @@ -27,6 +27,8 @@ struct Object Material& GetMaterial(); void SetMaterial(const Material& material); + void Place(const basics::Vector4 &p); + /** * Determine if the given ray intersects with this object. Converts the * ray's origin and direction to object space before calling the protected @@ -67,6 +69,7 @@ private: /** 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. */ basics::Matrix4 mTranslation;