Merge lp:~hikiko/compiz/compiz.matrix-additions into lp:compiz/0.9.12

Proposed by Eleni Maria Stea on 2015-10-01
Status: Work in progress
Proposed branch: lp:~hikiko/compiz/compiz.matrix-additions
Merge into: lp:compiz/0.9.12
Diff against target: 324 lines (+99/-19)
10 files modified
plugins/animation/src/animation.cpp (+1/-1)
plugins/cube/src/cube.cpp (+3/-3)
plugins/cubeaddon/src/cubeaddon.cpp (+3/-3)
plugins/freewins/src/util.cpp (+1/-1)
plugins/opengl/include/opengl/matrix.h (+8/-0)
plugins/opengl/include/opengl/opengl.h (+1/-1)
plugins/opengl/include/opengl/vector.h (+8/-1)
plugins/opengl/src/matrix.cpp (+58/-1)
plugins/opengl/src/vector.cpp (+8/-0)
plugins/td/src/3d.cpp (+8/-8)
To merge this branch: bzr merge lp:~hikiko/compiz/compiz.matrix-additions
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing on 2015-10-05
Andrea Azzarone 2015-10-01 Approve on 2015-10-01
Marco Trevisan (Treviño) 2015-10-01 Pending
Unity Team 2015-10-01 Pending
Review via email: mp+273072@code.launchpad.net

Commit Message

Added a function that calculates the transpose matrix and a function that prints the matrix elements to GLMatrix class.

Description of the Change

Added a function that calculates the transpose matrix and a function that prints the matrix elements to GLMatrix class.

To post a comment you must log in.
Andrea Azzarone (azzar1) :
review: Approve
Marco Trevisan (Treviño) (3v1n0) wrote :

Please update the COMPIZ_OPENGL_ABI and implement the operator<< instead of using printf, so we can use this with std::cout.

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
3979. By Eleni Maria Stea on 2015-10-02

changed OpenGL plugin ABI version

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
3980. By Eleni Maria Stea on 2015-10-02

added operator <<

Eleni Maria Stea (hikiko) wrote :

Well, I added the print function for quick debugging and since it doesn't have any extra dependencies and I can call it without including iostream everytime I need to check a matrix values I wouldn't like to delete it.

But I added the operator << as well in case someone needs to print a matrix in the release at some point (TBH I think that GLMatrix doesn't need to include iostream just for 1 rare case like that... what do you think?)

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, fair enough if you want to keep the print() there, although adding an include when debugging shouldn't be a problem.

However, at least now implement print using std::cout ;-)

Stephen M. Webb (bregma) wrote :

Missing <iosfwd> header in opengl/matrix.h.

3981. By Eleni Maria Stea on 2015-10-05

print uses operator <<

Eleni Maria Stea (hikiko) wrote :

lol, yep, I did it +good idea the <iosfwd>

PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Eleni Maria Stea (hikiko) wrote :

I found more problems in matrix.h/cpp: work in progress

3982. By Eleni Maria Stea on 2015-10-06

fixed operator *, used the correct operator in plugins

3983. By Eleni Maria Stea on 2015-10-06

implemented second operator *, fixed transform

Unmerged revisions

3983. By Eleni Maria Stea on 2015-10-06

implemented second operator *, fixed transform

3982. By Eleni Maria Stea on 2015-10-06

fixed operator *, used the correct operator in plugins

3981. By Eleni Maria Stea on 2015-10-05

print uses operator <<

3980. By Eleni Maria Stea on 2015-10-02

added operator <<

3979. By Eleni Maria Stea on 2015-10-02

changed OpenGL plugin ABI version

3978. By Eleni Maria Stea on 2015-10-01

added transpose and print functions to GLMatrix class that calculate the
transpose and print the matrix elements respectively

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/animation/src/animation.cpp'
2--- plugins/animation/src/animation.cpp 2015-03-16 18:45:33 +0000
3+++ plugins/animation/src/animation.cpp 2015-10-06 07:15:45 +0000
4@@ -835,7 +835,7 @@
5 AnimWindow::expandBBWithPoint2DTransform (GLVector &coords,
6 GLMatrix &transformMat)
7 {
8- GLVector coordsTransformed = transformMat * coords;
9+ GLVector coordsTransformed = coords.transform(transformMat);
10 expandBBWithPoint (coordsTransformed[GLVector::x],
11 coordsTransformed[GLVector::y]);
12 }
13
14=== modified file 'plugins/cube/src/cube.cpp'
15--- plugins/cube/src/cube.cpp 2015-08-05 11:26:09 +0000
16+++ plugins/cube/src/cube.cpp 2015-10-06 07:15:45 +0000
17@@ -849,21 +849,21 @@
18
19 GLMatrix mvp = pm * sTransform;
20
21- GLVector pntA = mvp * points[0];
22+ GLVector pntA = points[0].transform(mvp);
23
24 if (pntA[3] < 0.0f)
25 rv = !rv;
26
27 pntA.homogenize ();
28
29- GLVector pntB = mvp * points[1];
30+ GLVector pntB = points[1].transform(mvp);
31
32 if (pntB[3] < 0.0f)
33 rv = !rv;
34
35 pntB.homogenize ();
36
37- GLVector pntC = mvp * points[2];
38+ GLVector pntC = points[2].transform(mvp);
39 pntC.homogenize ();
40
41 GLVector vecA = pntC - pntA;
42
43=== modified file 'plugins/cubeaddon/src/cubeaddon.cpp'
44--- plugins/cubeaddon/src/cubeaddon.cpp 2015-09-22 13:33:09 +0000
45+++ plugins/cubeaddon/src/cubeaddon.cpp 2015-10-06 07:15:45 +0000
46@@ -1265,14 +1265,14 @@
47 pTransform.rotate (vRotate, cosf (xRotate * (M_PI / 180.0f)),
48 0.0f, sinf (xRotate * (M_PI / 180.0f)));
49
50- point = pTransform * point;
51+ point = point.transform(pTransform);
52
53 pTransform.reset ();
54 pTransform.rotate (xRotate2, 0.0f, 1.0f, 0.0f);
55 pTransform.rotate (vRotate, cosf (xRotate2 * (M_PI / 180.0f)),
56 0.0f, sinf (xRotate2 * (M_PI / 180.0f)));
57
58- point2 = pTransform * point2;
59+ point2 = point2.transform(pTransform);
60
61 switch (optionGetMode ()) {
62 case ModeJumpyReflection:
63@@ -1348,7 +1348,7 @@
64
65 gScreen->glApplyTransform (sAttrib, output, &pTransform);
66 point = GLVector (0.0, 0.0, -cDist + deform, 1.0);
67- point = pTransform * point;
68+ point = point.transform(pTransform);
69
70 rTransform.translate (0.0, 0.0, point[2]);
71 rTransform.rotate (mVRot, 1.0, 0.0, 0.0);
72
73=== modified file 'plugins/freewins/src/util.cpp'
74--- plugins/freewins/src/util.cpp 2013-02-20 14:24:30 +0000
75+++ plugins/freewins/src/util.cpp 2015-10-06 07:15:45 +0000
76@@ -60,7 +60,7 @@
77 GLdouble *resultY,
78 GLdouble *resultZ)
79 {
80- vector = transform * vector;
81+ vector = vector.transform(transform);
82
83 GLint viewport[4]; // Viewport
84 GLdouble modelview[16]; // Modelview Matrix
85
86=== modified file 'plugins/opengl/include/opengl/matrix.h'
87--- plugins/opengl/include/opengl/matrix.h 2012-08-02 11:57:41 +0000
88+++ plugins/opengl/include/opengl/matrix.h 2015-10-06 07:15:45 +0000
89@@ -27,6 +27,8 @@
90 #define _GLMATRIX_H
91
92 #include <opengl/vector.h>
93+#include <iosfwd>
94+#include <iostream>
95
96 class CompOutput;
97
98@@ -45,6 +47,7 @@
99 void toScreenSpace (const CompOutput *output, float z);
100
101 bool invert ();
102+ void transpose ();
103
104 void rotate (const float angle, const float x,
105 const float y, const float z);
106@@ -56,11 +59,16 @@
107 void translate (const float x, const float y, const float z);
108 void translate (const GLVector& vector);
109
110+ void print ();
111+
112+ friend std::ostream& operator<< (std::ostream& os, const GLMatrix& matrix);
113 private:
114 friend GLMatrix operator* (const GLMatrix& lhs,
115 const GLMatrix& rhs);
116 friend GLVector operator* (const GLMatrix& lhs,
117 const GLVector& rhs);
118+ friend GLVector operator* (const GLVector& rhs,
119+ const GLMatrix& lhs);
120
121 float m[16];
122 };
123
124=== modified file 'plugins/opengl/include/opengl/opengl.h'
125--- plugins/opengl/include/opengl/opengl.h 2014-12-10 13:21:23 +0000
126+++ plugins/opengl/include/opengl/opengl.h 2015-10-06 07:15:45 +0000
127@@ -59,7 +59,7 @@
128 #include <opengl/programcache.h>
129 #include <opengl/shadercache.h>
130
131-#define COMPIZ_OPENGL_ABI 7
132+#define COMPIZ_OPENGL_ABI 8
133
134 /*
135 * Some plugins check for #ifdef USE_MODERN_COMPIZ_GL. Support it for now, but
136
137=== modified file 'plugins/opengl/include/opengl/vector.h'
138--- plugins/opengl/include/opengl/vector.h 2015-03-02 08:32:21 +0000
139+++ plugins/opengl/include/opengl/vector.h 2015-10-06 07:15:45 +0000
140@@ -26,6 +26,8 @@
141 #ifndef _GLVECTOR_H
142 #define _GLVECTOR_H
143
144+class GLMatrix;
145+
146 /**
147 * Class which describes a point or vector
148 * in 3D space
149@@ -98,12 +100,17 @@
150 * Returns the normalized version of the vector
151 */
152 GLVector& normalize ();
153-
154+
155 /**
156 * Returns the homogenized version of the vector
157 */
158 GLVector& homogenize ();
159
160+ /**
161+ * Returns the vector transformed by a matrix
162+ */
163+ GLVector transform(const GLMatrix &matrix);
164+
165 private:
166 friend GLVector operator+ (const GLVector& lhs,
167 const GLVector& rhs);
168
169=== modified file 'plugins/opengl/src/matrix.cpp'
170--- plugins/opengl/src/matrix.cpp 2012-12-04 15:28:56 +0000
171+++ plugins/opengl/src/matrix.cpp 2015-10-06 07:15:45 +0000
172@@ -47,7 +47,6 @@
173 */
174
175 #include <core/output.h>
176-
177 #include <opengl/matrix.h>
178
179 #include <string.h>
180@@ -156,6 +155,21 @@
181 return result;
182 }
183
184+GLVector
185+operator* (const GLVector& rhs,
186+ const GLMatrix& lhs)
187+{
188+ GLVector result;
189+ const float *a = lhs.m;
190+
191+ for (int i=0; i<4; i++) {
192+ result[i] = rhs[0] * A(0, i) + rhs[1] * A(1, i) +
193+ rhs[2] * A(2, i) + rhs[3] * A(3, i);
194+ }
195+
196+ return result;
197+}
198+
199 #undef A
200 #undef B
201 #undef P
202@@ -214,6 +228,33 @@
203 }
204
205 /**
206+ * Calculates the 4x4 transpose matrix.
207+**/
208+void GLMatrix::transpose ()
209+{
210+ for (int i=0; i<4; i++) {
211+ for(int j=i+1; j<4; j++)
212+ {
213+ int idx1 = i * 4 + j;
214+ int idx2 = j * 4 + i;
215+
216+ float tmp = m[idx1];
217+ m[idx1] = m[idx2];
218+ m[idx2] = tmp;
219+ }
220+ }
221+}
222+
223+/**
224+ * Prints the 4x4 matrix elements (for debug).
225+ **/
226+
227+void GLMatrix::print()
228+{
229+ std::cout << *this;
230+}
231+
232+/**
233 * Generate a 4x4 transformation matrix from glRotate parameters, and
234 * post-multiply the input matrix by it.
235 *
236@@ -492,3 +533,19 @@
237 assert (pos <= 15);
238 return m[pos];
239 }
240+
241+/**
242+ * Prints the 4x4 matrix elements.
243+ **/
244+
245+std::ostream& operator<< (std::ostream& os, const GLMatrix& matrix)
246+{
247+ for (int i=0; i<16; i++)
248+ {
249+ os << matrix.m[i] << "\t";
250+ if (i % 4 == 3)
251+ os << std::endl;
252+ }
253+
254+ return os;
255+}
256
257=== modified file 'plugins/opengl/src/vector.cpp'
258--- plugins/opengl/src/vector.cpp 2015-03-02 08:32:21 +0000
259+++ plugins/opengl/src/vector.cpp 2015-10-06 07:15:45 +0000
260@@ -49,6 +49,7 @@
261 #include <string.h>
262 #include <math.h>
263 #include <opengl/vector.h>
264+#include <opengl/matrix.h>
265
266 GLVector::GLVector ()
267 {
268@@ -259,3 +260,10 @@
269
270 return *this;
271 }
272+
273+GLVector
274+GLVector::transform(const GLMatrix &matrix)
275+{
276+ GLVector tv = matrix * (*this);
277+ return tv;
278+}
279
280=== modified file 'plugins/td/src/3d.cpp'
281--- plugins/td/src/3d.cpp 2015-08-05 05:57:15 +0000
282+++ plugins/td/src/3d.cpp 2015-10-06 07:15:45 +0000
283@@ -107,34 +107,34 @@
284
285 #define ADDQUAD(x1,y1,x2,y2) \
286 point[GLVector::x] = x1; point[GLVector::y] = y1; \
287- tPoint = transform * point; \
288+ tPoint = point.transform(transform); \
289 SET_V \
290 glVertex4fv (v); \
291 point[GLVector::x] = x2; point[GLVector::y] = y2; \
292- tPoint = transform * point; \
293+ tPoint = point.transform(transform); \
294 SET_V \
295 glVertex4fv (v); \
296- tPoint = tds->mBTransform * point; \
297+ tPoint = point.transform(tds->mBTransform); \
298 SET_V \
299 glVertex4fv (v); \
300 point[GLVector::x] = x1; point[GLVector::y] = y1; \
301- tPoint = tds->mBTransform * point; \
302+ tPoint = point.transform(tds->mBTransform); \
303 SET_V \
304 glVertex4fv (v); \
305
306 #define ADDBEVELQUAD(x1,y1,x2,y2,m1,m2) \
307 point[GLVector::x] = x1; point[GLVector::y] = y1; \
308- tPoint = m1 * point; \
309+ tPoint = point.transform(m1); \
310 SET_V \
311 glVertex4fv (v); \
312- tPoint = m2 * point; \
313+ tPoint = point.transform(m2); \
314 SET_V \
315 glVertex4fv (v); \
316 point[GLVector::x] = x2; point[GLVector::y] = y2; \
317- tPoint = m2 * point; \
318+ tPoint = point.transform(m2); \
319 SET_V \
320 glVertex4fv (v); \
321- tPoint = m1 * point; \
322+ tPoint = point.transform(m1); \
323 SET_V \
324 glVertex4fv (v); \
325

Subscribers

People subscribed via source and target branches