From c45d698424a9b88ea1f3e351045cc56afbcf4bb3 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 16 Aug 2014 00:43:43 -0700 Subject: [PATCH] Get a column vector of a matrix --- src/basics/matrix.cc | 9 +++++++++ src/basics/matrix.hh | 1 + src/basics/vector.cc | 13 ++++++++++++- src/basics/vector.hh | 1 + src/object.cc | 2 ++ src/object.hh | 3 +++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/basics/matrix.cc b/src/basics/matrix.cc index 1a89f7f..bd95a71 100644 --- a/src/basics/matrix.cc +++ b/src/basics/matrix.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include "basics/matrix.hh" @@ -187,6 +188,14 @@ Matrix4::operator()(UInt i, } +Vector4 +Matrix4::Column(const UInt i) + const noexcept +{ + return Vector4(operator()(i,0), operator()(i,1), operator()(i,2), operator()(i,3)); +} + + /* * charles::basics::Matrix4::CArray -- */ diff --git a/src/basics/matrix.hh b/src/basics/matrix.hh index 4e6ebdf..9a93164 100644 --- a/src/basics/matrix.hh +++ b/src/basics/matrix.hh @@ -47,6 +47,7 @@ struct Matrix4 */ Double& operator()(UInt i, UInt j); Double operator()(UInt i, UInt j) const; + Vector4 Column(const UInt i) const noexcept; /** Get the underlying C array */ const Double *CArray() const; diff --git a/src/basics/vector.cc b/src/basics/vector.cc index 76e2b52..02a07ff 100644 --- a/src/basics/vector.cc +++ b/src/basics/vector.cc @@ -33,11 +33,22 @@ Vector4::Vector4() Vector4::Vector4(Double x, Double y, Double z) + : Vector4(x, y, z, 1.0) +{ } + + +/* + * charles::basics::Vector4::Vector4 -- + */ +Vector4::Vector4(Double x, + Double y, + Double z, + Double w) { mData[0] = x; mData[1] = y; mData[2] = z; - mData[3] = 1.0; + mData[3] = w; } diff --git a/src/basics/vector.hh b/src/basics/vector.hh index e8b99a2..b83a5c2 100644 --- a/src/basics/vector.hh +++ b/src/basics/vector.hh @@ -20,6 +20,7 @@ struct Vector4 { Vector4(); Vector4(Double x, Double y, Double z); + Vector4(Double x, Double y, Double z, Double w); Vector4 &operator=(const Vector4 &rhs); diff --git a/src/object.cc b/src/object.cc index 80b2151..419e507 100644 --- a/src/object.cc +++ b/src/object.cc @@ -144,7 +144,9 @@ std::ostream& operator<<(std::ostream& ost, const Object& object) { + ost << "["; object.Write(ost); + ost << " translate=" << object.mTranslation.Column(3) << "]"; return ost; } diff --git a/src/object.hh b/src/object.hh index 6b9a58b..ee2fca2 100644 --- a/src/object.hh +++ b/src/object.hh @@ -60,6 +60,9 @@ protected: virtual basics::Vector4 DoNormal(const basics::Vector4& p) const = 0; private: + friend std::ostream& operator<<(std::ostream& ost, const Object& object); + + /** Convert `ray` to object space from global space. */ basics::Ray ToObjectSpace(basics::Ray ray) const;