Merge lp:~hikiko/compiz/compiz.glvector-fixes into lp:compiz/0.9.12

Proposed by Eleni Maria Stea
Status: Merged
Approved by: Stephen M. Webb
Approved revision: 3928
Merged at revision: 3939
Proposed branch: lp:~hikiko/compiz/compiz.glvector-fixes
Merge into: lp:compiz/0.9.12
Diff against target: 207 lines (+25/-28)
4 files modified
plugins/animation/src/glide.cpp (+4/-6)
plugins/expo/src/expo.cpp (+2/-2)
plugins/opengl/include/opengl/vector.h (+1/-1)
plugins/opengl/src/vector.cpp (+18/-19)
To merge this branch: bzr merge lp:~hikiko/compiz/compiz.glvector-fixes
Reviewer Review Type Date Requested Status
Stephen M. Webb Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+251421@code.launchpad.net

Commit message

Change in GLVector implementation

Bug:
The GLVectors of compiz are 4 dimensional (x, y, z, w): https://en.wikipedia.org/wiki/Homogeneous_coordinates The w coordinate should be initialized to 1 and be preserved when we perform vector operations (additions/multiplications etc) otherwise the transformations won't be correct. For example: if we add or subtract the w values during two vectors addition we might have unexpected projections when the new w value is > 1 or divisions by 0 (when the new w is 0) because opengl divides the x,y,z values by w.

Solution:
- Changed the constructors to initialize w to 1 and not to 0 by default.
- Fixed the vector operations to use the x, y, z coordinates only.
- Fixed the existing constructors in plugins to initialize w to 1 and not to 0.

Description of the change

Change in GLVector implementation

Bug:
The GLVectors of compiz are 4 dimensional (x, y, z, w): https://en.wikipedia.org/wiki/Homogeneous_coordinates The w coordinate should be initialized to 1 and be preserved when we perform vector operations (additions/multiplications etc) otherwise the transformations won't be correct. For example: if we add or subtract the w values during two vectors addition we might have unexpected projections when the new w value is > 1 or divisions by 0 (when the new w is 0) because opengl divides the x,y,z values by w.

Solution:
- Changed the constructors to initialize w to 1 and not to 0 by default.
- Fixed the vector operations to use the x, y, z coordinates only.
- Fixed the existing constructors in plugins to initialize w to 1 and not to 0.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/animation/src/glide.cpp'
2--- plugins/animation/src/glide.cpp 2013-05-19 15:04:07 +0000
3+++ plugins/animation/src/glide.cpp 2015-03-02 09:39:43 +0000
4@@ -122,11 +122,11 @@
5 mAWindow->savedOutRect () :
6 mWindow->outputRect ());
7
8- GLVector rotAxis (1, 0, 0, 0);
9+ GLVector rotAxis (1, 0, 0, 1);
10 GLVector rotAxisOffset (outRect.x () + outRect.width () / 2.0f,
11 outRect.y () + outRect.height () / 2.0f,
12- 0, 0);
13- GLVector translation (0, 0, finalz * forwardProgress, 0);
14+ 0, 1);
15+ GLVector translation (0, 0, finalz * forwardProgress, 1);
16
17 float rotAngle = finalRotAng * forwardProgress;
18 glideModRotAngle = fmodf (rotAngle + 720, 360.0f);
19@@ -142,9 +142,7 @@
20 // animation rotation
21 mTransform.rotate (rotAngle, rotAxis);
22
23- // intentional scaling of z by 0 to prevent weird opacity results and
24- // flashing that happen when z coords are between 0 and 1 (bug in compiz?)
25- mTransform.scale (1.0f, 1.0f, 0.0f);
26+ mTransform.scale (1.0f, 1.0f, 1.0f);
27
28 // place window rotation axis at origin
29 mTransform.translate (-rotAxisOffset);
30
31=== modified file 'plugins/expo/src/expo.cpp'
32--- plugins/expo/src/expo.cpp 2014-06-24 18:40:39 +0000
33+++ plugins/expo/src/expo.cpp 2015-03-02 09:39:43 +0000
34@@ -778,10 +778,10 @@
35
36 /* Zoom animation stuff */
37 /* camera position for the selected viewport */
38- GLVector vpCamPos (0, 0, 0, 0);
39+ GLVector vpCamPos (0, 0, 0, 1);
40
41 /* camera position during expo mode */
42- GLVector expoCamPos (0, 0, 0, 0);
43+ GLVector expoCamPos (0, 0, 0, 1);
44
45 float sx = screen->width () / static_cast <float> (output->width ());
46 float sy = screen->height () / static_cast <float> (output->height ());
47
48=== modified file 'plugins/opengl/include/opengl/vector.h'
49--- plugins/opengl/include/opengl/vector.h 2012-05-17 10:41:21 +0000
50+++ plugins/opengl/include/opengl/vector.h 2015-03-02 09:39:43 +0000
51@@ -40,7 +40,7 @@
52 } VectorCoordsEnum;
53
54 GLVector ();
55- GLVector (float x, float y, float z, float w = 0.0f);
56+ GLVector (float x, float y, float z, float w = 1.0f);
57
58 /**
59 * Returns a reference to the x, y, z or w value by using
60
61=== modified file 'plugins/opengl/src/vector.cpp'
62--- plugins/opengl/src/vector.cpp 2012-12-04 15:28:01 +0000
63+++ plugins/opengl/src/vector.cpp 2015-03-02 09:39:43 +0000
64@@ -52,7 +52,8 @@
65
66 GLVector::GLVector ()
67 {
68- memset (v, 0, sizeof (v));
69+ v[0] = v[1] = v[2] = 0.0;
70+ v[3] = 1.0;
71 }
72
73 GLVector::GLVector (float x,
74@@ -63,7 +64,7 @@
75 v[0] = x;
76 v[1] = y;
77 v[2] = z;
78- v[3] = w;
79+ v[3] = 1.0;
80 }
81
82 float&
83@@ -95,7 +96,7 @@
84 GLVector&
85 GLVector::operator+= (const GLVector& rhs)
86 {
87- for (int i = 0; i < 4; i++)
88+ for (int i = 0; i < 3; i++)
89 v[i] += rhs[i];
90
91 return *this;
92@@ -107,7 +108,7 @@
93 {
94 GLVector result;
95
96- for (int i = 0; i < 4; i++)
97+ for (int i = 0; i < 3; i++)
98 result[i] = lhs[i] + rhs[i];
99
100 return result;
101@@ -116,7 +117,7 @@
102 GLVector&
103 GLVector::operator-= (const GLVector& rhs)
104 {
105- for (int i = 0; i < 4; i++)
106+ for (int i = 0; i < 3; i++)
107 v[i] -= rhs[i];
108
109 return *this;
110@@ -128,7 +129,7 @@
111 {
112 GLVector result;
113
114- for (int i = 0; i < 4; i++)
115+ for (int i = 0; i < 3; i++)
116 result[i] = lhs[i] - rhs[i];
117
118 return result;
119@@ -139,7 +140,7 @@
120 {
121 GLVector result;
122
123- for (int i = 0; i < 4; i++)
124+ for (int i = 0; i < 3; i++)
125 result[i] = -vector[i];
126
127 return result;
128@@ -148,7 +149,7 @@
129 GLVector&
130 GLVector::operator*= (const float k)
131 {
132- for (int i = 0; i < 4; i++)
133+ for (int i = 0; i < 3; i++)
134 v[i] *= k;
135
136 return *this;
137@@ -160,7 +161,7 @@
138 {
139 float result = 0;
140
141- for (int i = 0; i < 4; i++)
142+ for (int i = 0; i < 3; i++)
143 result += lhs[i] * rhs[i];
144
145 return result;
146@@ -172,7 +173,7 @@
147 {
148 GLVector result;
149
150- for (int i = 0; i < 4; i++)
151+ for (int i = 0; i < 3; i++)
152 result[i] = k * vector[i];
153
154 return result;
155@@ -188,7 +189,7 @@
156 GLVector&
157 GLVector::operator/= (const float k)
158 {
159- for (int i = 0; i < 4; i++)
160+ for (int i = 0; i < 3; i++)
161 v[i] /= k;
162
163 return *this;
164@@ -200,7 +201,7 @@
165 {
166 GLVector result;
167
168- for (int i = 0; i < 4; i++)
169+ for (int i = 0; i < 3; i++)
170 result[i] = vector[i] / k;
171
172 return result;
173@@ -222,7 +223,7 @@
174 result[0] = lhs[1] * rhs[2] - lhs[2] * rhs[1];
175 result[1] = lhs[2] * rhs[0] - lhs[0] * rhs[2];
176 result[2] = lhs[0] * rhs[1] - lhs[1] * rhs[0];
177- result[3] = 0.0f;
178+ result[3] = 1.0f;
179
180 return result;
181 }
182@@ -230,22 +231,20 @@
183 float
184 GLVector::norm ()
185 {
186- if (v[3] != 0.0)
187- return 1.0;
188 return sqrt ((v[0] * v[0]) + (v[1] * v[1]) + (v[2] * v[2]));
189 }
190
191 GLVector &
192 GLVector::normalize ()
193 {
194- float normal = norm ();
195+ float mag = norm ();
196
197- /* Vector is not homogenous */
198- if (normal == 1.0)
199+ /* avoid division by 0 */
200+ if (mag == 0.0)
201 return *this;
202
203 for (unsigned int i = 0; i < 3; i++)
204- v[i] /= normal;
205+ v[i] /= mag;
206 return *this;
207 }
208

Subscribers

People subscribed via source and target branches