Get a column vector of a matrix

This commit is contained in:
Eryn Wells 2014-08-16 00:43:43 -07:00
parent 1daf1619ef
commit c45d698424
6 changed files with 28 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include <cstring>
#include <stdexcept>
#include <sstream>
#include <type_traits>
#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 --
*/

View file

@ -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;

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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;