Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/AffineTransform2D.cpp @ 574:911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 18 Apr 2019 18:06:29 +0200 |
parents | b70e9be013e4 |
children | 919226caca82 |
comparison
equal
deleted
inserted
replaced
573:adc1be326b62 | 574:911297a277c4 |
---|---|
88 matrix_(1, 0), matrix_(1, 1), matrix_(1, 2), | 88 matrix_(1, 0), matrix_(1, 1), matrix_(1, 2), |
89 interpolation, clear); | 89 interpolation, clear); |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 void AffineTransform2D::ConvertToOpenGLMatrix(float target[16], | |
94 unsigned int canvasWidth, | |
95 unsigned int canvasHeight) const | |
96 { | |
97 const AffineTransform2D t = AffineTransform2D::Combine( | |
98 CreateOpenGLClipspace(canvasWidth, canvasHeight), *this); | |
99 | |
100 const Matrix source = t.GetHomogeneousMatrix(); | |
101 | |
102 if (source.size1() != 3 || | |
103 source.size2() != 3) | |
104 { | |
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
106 } | |
107 | |
108 // "z" must be in the [-1,1] range, otherwise the texture does not show up | |
109 float z = 0; | |
110 | |
111 // Embed the 3x3 affine transform of the 2D plane into a 4x4 | |
112 // matrix (3D) for OpenGL. The matrix must be transposed. | |
113 | |
114 target[0] = static_cast<float>(source(0, 0)); | |
115 target[1] = static_cast<float>(source(1, 0)); | |
116 target[2] = 0; | |
117 target[3] = static_cast<float>(source(2, 0)); | |
118 target[4] = static_cast<float>(source(0, 1)); | |
119 target[5] = static_cast<float>(source(1, 1)); | |
120 target[6] = 0; | |
121 target[7] = static_cast<float>(source(2, 1)); | |
122 target[8] = 0; | |
123 target[9] = 0; | |
124 target[10] = -1; | |
125 target[11] = 0; | |
126 target[12] = static_cast<float>(source(0, 2)); | |
127 target[13] = static_cast<float>(source(1, 2)); | |
128 target[14] = -z; | |
129 target[15] = static_cast<float>(source(2, 2)); | |
130 } | |
131 | |
132 | |
93 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) | 133 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) |
94 { | 134 { |
95 AffineTransform2D t; | 135 AffineTransform2D t; |
96 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_); | 136 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_); |
97 return t; | 137 return t; |
161 t.matrix_(1, 0) = sine; | 201 t.matrix_(1, 0) = sine; |
162 t.matrix_(1, 1) = cosine; | 202 t.matrix_(1, 1) = cosine; |
163 | 203 |
164 return t; | 204 return t; |
165 } | 205 } |
206 | |
207 | |
208 AffineTransform2D AffineTransform2D::CreateOpenGLClipspace(unsigned int canvasWidth, | |
209 unsigned int canvasHeight) | |
210 { | |
211 AffineTransform2D t; | |
212 t.matrix_(0, 0) = 2.0 / static_cast<double>(canvasWidth); | |
213 t.matrix_(0, 2) = -1.0; | |
214 t.matrix_(1, 1) = -2.0 / static_cast<double>(canvasHeight); | |
215 t.matrix_(1, 2) = 1.0; | |
216 | |
217 return t; | |
218 } | |
166 } | 219 } |