18 #ifndef ZENI_MATRIX4F_HXX
19 #define ZENI_MATRIX4F_HXX
39 assert(-1 < index && index < 4);
40 return row[index << 2];
44 assert(-1 < index && index < 4);
45 return row[index << 2];
54 0.0
f, 1.0
f, 0.0
f, 0.0
f,
55 0.0
f, 0.0
f, 1.0
f, 0.0
f,
56 0.0
f, 0.0
f, 0.0
f, 1.0
f);
60 return Matrix4f(scaling_factor.
i, 0.0f, 0.0f, 0.0f,
61 0.0f, scaling_factor.
j, 0.0f, 0.0f,
62 0.0f, 0.0f, scaling_factor.
k, 0.0f,
63 0.0f, 0.0f, 0.0f, 1.0f);
72 0.0f, 1.0f, 0.0f, translation_factor.
j,
73 0.0f, 0.0f, 1.0f, translation_factor.
k,
74 0.0f, 0.0f, 0.0f, 1.0f);
84 -l.
i, -l.
j, -l.
k, 0.0f,
85 0.0f, 0.0f, 0.0f, 1.0f) *
90 const float denom_x = left -
right;
91 const float denom_y = bottom -
top;
92 const float denom_z = near_ - far_;
94 const float t_x = (left +
right) / denom_x;
95 const float t_y = (bottom +
top) / denom_y;
96 const float t_z = (near_ + far_) / denom_z;
99 0.0
f, -2.0
f / denom_y, 0.0
f, t_y,
100 0.0
f, 0.0
f, -2.0
f / denom_z, t_z,
101 0.0
f, 0.0
f, 0.0
f, 1.0
f);
105 #define cotangent(angle) (1.0f / tan(angle))
106 const float f = float(
cotangent(0.5f * fov_rad_y));
108 const float denom = near_ - far_;
110 return Matrix4f(f / aspect, 0.0f, 0.0f, 0.0f,
112 0.0f, 0.0f, (far_ + near_) / denom, 2.0f * far_ * near_ / denom,
113 0.0f, 0.0f, -1.0f, 0.0f);
123 const float &
left = upper_left.
x;
124 const float &
right = lower_right.
x;
125 const float &
top = upper_left.
y;
126 const float &
bottom = lower_right.
y;
128 const float denom_x = right -
left;
129 const float denom_y = top -
bottom;
130 const float denom_z = near_ - far_;
132 return Matrix4f(2.0
f * near_ / denom_x, 0.0
f, (right + left) / denom_x, 0.0
f,
133 0.0
f, 2.0
f * near_ / denom_y, (top + bottom) / denom_y, 0.0
f,
134 0.0
f, 0.0
f, (near_ + far_) / denom_z, 2.0
f * near_ * far_ / denom_z,
135 0.0
f, 0.0
f, -1.0
f, 0.0
f);
145 assert(-1 < index && index < 4);
146 return Matrix4f_Row(const_cast<float *>(&m_matrix[0][0] + index));
150 assert(-1 < index && index < 4);
158 *mp =
reinterpret_cast<const float *
>(m_matrix),
159 *rp = reinterpret_cast<const float *>(rhs.m_matrix);
161 for(
float *lp = reinterpret_cast<float *>(matrix.m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++mp, ++rp)
171 *mp =
reinterpret_cast<const float *
>(m_matrix),
172 *rp = reinterpret_cast<const float *>(rhs.m_matrix);
174 for(
float *lp = reinterpret_cast<float *>(matrix.m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++mp, ++rp)
183 const float *rp =
reinterpret_cast<const float *
>(rhs.m_matrix);
185 for(
float *lp = reinterpret_cast<float *>(m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++rp)
194 const float *rp =
reinterpret_cast<const float *
>(rhs.m_matrix);
196 for(
float *lp = reinterpret_cast<float *>(m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++rp)
205 for(
int i = 0;
i < 4; ++
i)
206 for(
int j = 0;
j < 4; ++
j)
207 matrix.m_matrix[
j][
i] =
208 m_matrix[0][
i] * rhs.m_matrix[
j][0] +
209 m_matrix[1][
i] * rhs.m_matrix[
j][1] +
210 m_matrix[2][
i] * rhs.m_matrix[
j][2] +
211 m_matrix[3][
i] * rhs.m_matrix[
j][3];
217 return *
this = *
this * rhs;
231 const float *mp =
reinterpret_cast<const float *
>(m_matrix);
233 for(
float *lp = reinterpret_cast<float *>(matrix.m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++mp)
242 const float *mp =
reinterpret_cast<const float *
>(m_matrix);
244 for(
float *lp = reinterpret_cast<float *>(matrix.m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++mp)
251 for(
float *lp = reinterpret_cast<float *>(m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp)
258 for(
float *lp = reinterpret_cast<float *>(m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp)
267 const float *mp =
reinterpret_cast<const float *
>(m_matrix);
269 for(
float *lp = reinterpret_cast<float *>(matrix.m_matrix), *lp_end = lp + 16; lp != lp_end; ++lp, ++mp)
276 assert(-1 < column && column < 3);
277 return Vector3f(m_matrix[column][0], m_matrix[column][1], m_matrix[column][2]);
281 assert(-1 < row && row < 3);
282 return Vector3f(m_matrix[0][row], m_matrix[1][row], m_matrix[2][row]);
Matrix4f operator/(const Matrix4f &rhs) const
Get the product with the inverse.
GLint GLenum GLboolean normalized
Matrix4f get_matrix() const
Get the matrix form of the rotation in row-major order.
Matrix4f & operator+=(const Matrix4f &rhs)
Set equal to the sum.
Matrix4f operator/=(const Matrix4f &rhs)
Set equal to the product with the inverse.
static Matrix4f Frustum(const Point2f &upper_left, const Point2f &lower_right, const float &near, const float &far)
Similar to glFrustum.
A 3D Point represented with floats.
A Featureful 3-Space Vector Class.
GLenum GLenum GLvoid * row
Matrix4f operator-() const
Get the negation.
Matrix4f_Row(float *const &row_)
Matrix4f operator+(const Matrix4f &rhs) const
Get the sum.
A Featureful Quaternion Class.
static Matrix4f Orthographic(const float &left, const float &right, const float &bottom, const float &top, const float &near, const float &far)
Similar to gluOrtho.
GLenum GLenum GLvoid GLvoid * column
Vector3f get_column(const int &column) const
Get a column of the upper-left 3x3 matrix.
Matrix4f operator*(const Matrix4f &rhs) const
Get the product.
GLfloat GLfloat GLfloat top
static Matrix4f Translate(const Vector3f &translation_factor)
static Matrix4f View(const Point3f &position, const Vector3f &forward, const Vector3f &up)
Similar to gluLookAt.
Matrix4f operator*=(const Matrix4f &rhs)
Get the product.
static Matrix4f Identity()
Matrix4f inverted() const
Get the inverse.
const Matrix4f_Row operator[](const int &index) const
Get row 'index'.
const float & operator[](const int &index) const
Get 'index'.
static Matrix4f Rotate(const Quaternion &rotation)
A Featureful 4-Space Matrix Class.
static Matrix4f Perspective(const float &fov_rad_y, const float &aspect, const float &near, const float &far)
Similar to gluPerspective.
Vector3f get_row(const int &row) const
Get a row of the upper left 3x3 matrix.
Matrix4f & operator-=(const Matrix4f &rhs)
Set equal to the difference.
A 2D Point represented with floats.
Vector3f normalized() const
Get the normalized vector.
static Matrix4f Scale(const Vector3f &scaling_factor)