17#ifndef __gui_opengl_transformation_h__
18#define __gui_opengl_transformation_h__
38 vec4 (
float x,
float y,
float z,
float w) {
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = w; }
39 vec4 (
const Eigen::Quaternionf& V) {
v[0] = V.x();
v[1] = V.y();
v[2] = V.z();
v[3] = V.w(); }
41 vec4 (
const Cont& p,
float w) {
v[0] = p[0];
v[1] = p[1];
v[2] = p[2];
v[3] = w; }
42 vec4 (
const float* p) { memcpy (
v, p,
sizeof(
v)); }
45 memset (
v, 0,
sizeof (
v));
48 operator const GLfloat* ()
const {
return v; }
49 operator GLfloat* () {
return v; }
52 for (
size_t i = 0; i < 4; ++i)
53 stream <<
v[i] <<
" ";
68 mat4 (
const mat4& a) { memcpy (
m, a.
m,
sizeof(
m)); }
69 mat4 (
const float* p) { memcpy (
m, p,
sizeof(
m)); }
70 mat4 (
const Eigen::Quaternionf& v)
72 const auto R = v.matrix();
74 for (
size_t i = 0; i != 3; ++i) {
75 for (
size_t j = 0; j != 3; ++j)
76 (*
this)(i,j) =
R(i,j);
83 for (
size_t i = 0; i != size_t(a.rows()); ++i) {
84 for (
size_t j = 0; j != 4; ++j)
85 (*
this)(i,j) = a(i,j);
88 (*this)(3,0) = (*
this)(3,1) = (*
this)(3,2) = 0.0f;
93 mat4& operator= (
const mat4& a) { memcpy (
m, a.
m,
sizeof(
m));
return *
this; }
96 memset (
m, 0,
sizeof (
m));
99 operator const GLfloat* ()
const {
return m; }
100 operator GLfloat* () {
return m; }
102 GLfloat& operator() (
size_t i,
size_t j) {
return m[i+4*j]; }
103 const GLfloat& operator() (
size_t i,
size_t j)
const {
return m[i+4*j]; }
105 mat4 operator* (
const mat4& a)
const {
107 for (
size_t j = 0; j < 4; ++j) {
108 for (
size_t i = 0; i < 4; ++i) {
110 for (
size_t k = 0; k < 4; ++k)
111 t(i,j) += (*this)(i,k) * a(k,j);
118 vec4 operator* (
const vec4& v)
const {
121 for (
size_t j = 0; j < 4; ++j)
122 for (
size_t i = 0; i < 4; ++i)
123 r[i] += (*
this)(i,j) * v[j];
133 for (
size_t i = 0; i < 4; ++i) {
134 for (
size_t j = 0; j < 4; ++j)
135 stream <<
m(i,j) <<
" ";
152 m(0,0) = m(1,1) = m(2,2) = m(3,3) = 1.0f;
161 for (
size_t j = 0; j < 4; ++j)
162 for (
size_t i = 0; i < 4; ++i)
173 Eigen::Matrix<float, 4, 4> A;
174 for (
size_t i = 0; i != 4; ++i) {
175 for (
size_t j = 0; j != 4; ++j)
178 return A.inverse().eval();
183 inline mat4 ortho (
float L,
float R,
float B,
float T,
float N,
float F)
192 m(0,3) = (
R+L)/(
R-L);
193 m(1,3) = (T+B)/(T-B);
194 m(2,3) = (F+N)/(F-N);
201 inline mat4 frustum (
float L,
float R,
float B,
float T,
float N,
float F)
206 m(0,0) = 2.0f*N/(
R-L);
207 m(1,1) = 2.0f*N/(T-B);
208 m(0,2) = (
R+L)/(
R-L);
209 m(1,2) = (T+B)/(T-B);
210 m(2,2) = (F+N)/(N-F);
212 m(2,3) = 2.0f*F*N/(N-F);
228 template <
class Cont>
friend std::ostream & operator<<(std::ostream &stream, const mat4 &m)
friend std::ostream & operator<<(std::ostream &stream, const vec4 &v)
mat4 ortho(float L, float R, float B, float T, float N, float F)
mat4 frustum(float L, float R, float B, float T, float N, float F)
mat4 scale(float x, float y, float z)
mat4 transpose(const mat4 &a)
mat4 translate(float x, float y, float z)