2014-08-08 17:35:34 -07:00
|
|
|
/* matrix.hh
|
|
|
|
* vim: set tw=80:
|
|
|
|
* Eryn Wells <eryn@erynwells.me>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __BASICS_MATRIX_HH__
|
|
|
|
#define __BASICS_MATRIX_HH__
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#include "basics/types.hh"
|
|
|
|
|
|
|
|
|
|
|
|
namespace charles {
|
|
|
|
namespace basics {
|
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
struct Vector4;
|
|
|
|
|
|
|
|
|
|
|
|
/** A 4x4 matrix, used for 3D transforms. */
|
|
|
|
struct Matrix4
|
2014-08-08 17:35:34 -07:00
|
|
|
{
|
2014-08-10 10:51:12 -07:00
|
|
|
/** Create a 4x4 matrix of zeros. */
|
|
|
|
static Matrix4 Zero();
|
2014-08-08 17:35:34 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
/** Create a 4x4 identity matrix. */
|
|
|
|
static Matrix4 Identity();
|
|
|
|
|
|
|
|
/** Create a 4x4 translation matrix. */
|
|
|
|
static Matrix4 Translation(Double x, Double y, Double z);
|
2014-08-08 17:35:34 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
Matrix4();
|
|
|
|
Matrix4(const Double *data);
|
|
|
|
Matrix4(const Matrix4 &rhs);
|
2014-08-08 20:44:31 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
Matrix4& operator=(const Matrix4 &rhs);
|
2014-08-08 20:44:31 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
bool operator==(const Matrix4 &rhs) const;
|
|
|
|
bool operator!=(const Matrix4 &rhs) const;
|
2014-08-08 20:44:31 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
/**
|
|
|
|
* Get the ij'th item. In debug builds, this will assert if i or j are
|
|
|
|
* outside the bounds of the array.
|
|
|
|
*/
|
2014-08-08 21:12:06 -07:00
|
|
|
Double& operator()(UInt i, UInt j);
|
2014-08-10 10:51:12 -07:00
|
|
|
Double operator()(UInt i, UInt j) const;
|
|
|
|
|
|
|
|
/** Get the underlying C array */
|
|
|
|
const Double *CArray() const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: For completeness, matrix addition and subtraction, though I have
|
|
|
|
* yet to find a need for them...
|
|
|
|
*/
|
2014-08-08 17:35:34 -07:00
|
|
|
|
2014-08-09 08:31:37 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Scalar multiplication
|
|
|
|
* @{
|
|
|
|
*/
|
2014-08-10 10:51:12 -07:00
|
|
|
Matrix4 operator*(Double rhs) const;
|
|
|
|
Matrix4 operator/(Double rhs) const;
|
|
|
|
Matrix4& operator*=(Double rhs);
|
|
|
|
Matrix4& operator/=(Double rhs);
|
2014-08-09 08:31:37 -07:00
|
|
|
/** @} */
|
2014-08-08 17:35:34 -07:00
|
|
|
|
2014-08-10 10:51:12 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Matrix multiplication
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
Matrix4 operator*(const Matrix4 &rhs) const;
|
|
|
|
Vector4 operator*(const Vector4 &rhs) const;
|
|
|
|
/** @} */
|
2014-08-08 17:35:34 -07:00
|
|
|
|
2014-08-08 21:12:06 -07:00
|
|
|
protected:
|
2014-08-10 10:51:12 -07:00
|
|
|
/** The matrix data */
|
|
|
|
Double mData[16];
|
2014-08-08 17:35:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-08 23:05:24 -07:00
|
|
|
/** Scalar multiplication, scalar factor on the left. */
|
2014-08-10 10:51:12 -07:00
|
|
|
Matrix4 operator*(const Double &lhs, const Matrix4 &rhs);
|
2014-08-08 17:35:34 -07:00
|
|
|
|
|
|
|
} /* namespace basics */
|
|
|
|
} /* namespace charles */
|
|
|
|
|
|
|
|
#endif /* __BASICS_MATRIX_HH__ */
|