picrate 0.7.0-java → 0.8.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -1
- data/.travis.yml +2 -5
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/Rakefile +15 -27
- data/docs/_config.yml +1 -1
- data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -1
- data/docs/_posts/2018-11-18-building-gem.md +1 -1
- data/lib/picrate/app.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/mvnw +127 -51
- data/mvnw.cmd +182 -0
- data/pom.rb +39 -30
- data/pom.xml +50 -37
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/core/LibraryProxy.java +0 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +1 -1
- data/src/main/java/monkstone/vecmath/GfxRender.java +87 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +48 -50
- data/src/main/java/processing/awt/PShapeJava2D.java +10 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +315 -371
- data/src/main/java/processing/core/PApplet.java +15424 -15495
- data/src/main/java/processing/core/PConstants.java +4 -4
- data/src/main/java/processing/core/PFont.java +394 -369
- data/src/main/java/processing/core/PGraphics.java +11 -10
- data/src/main/java/processing/core/PImage.java +1389 -1435
- data/src/main/java/processing/core/PMatrix2D.java +297 -294
- data/src/main/java/processing/core/PMatrix3D.java +641 -594
- data/src/main/java/processing/core/PShape.java +1755 -1784
- data/src/main/java/processing/core/PShapeOBJ.java +145 -133
- data/src/main/java/processing/core/PShapeSVG.java +808 -801
- data/src/main/java/processing/core/PStyle.java +141 -149
- data/src/main/java/processing/core/PSurface.java +111 -117
- data/src/main/java/processing/core/PSurfaceNone.java +178 -187
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +349 -346
- data/src/main/java/processing/opengl/FontTexture.java +40 -59
- data/src/main/java/processing/opengl/FrameBuffer.java +28 -18
- data/src/main/java/processing/opengl/LinePath.java +7 -7
- data/src/main/java/processing/opengl/LineStroker.java +6 -10
- data/src/main/java/processing/opengl/PGL.java +56 -44
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +909 -2338
- data/src/main/java/processing/opengl/PJOGL.java +1722 -1763
- data/src/main/java/processing/opengl/PShader.java +1308 -1192
- data/src/main/java/processing/opengl/PShapeOpenGL.java +487 -1811
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +482 -497
- data/src/main/java/processing/opengl/Texture.java +99 -76
- data/src/main/java/processing/opengl/VertexBuffer.java +41 -43
- data/vendors/Rakefile +1 -1
- metadata +7 -4
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
2
|
|
3
|
-
/*
|
3
|
+
/*
|
4
4
|
Part of the Processing project - http://processing.org
|
5
5
|
|
6
6
|
Copyright (c) 2005-12 Ben Fry and Casey Reas
|
@@ -18,200 +18,186 @@
|
|
18
18
|
Public License along with this library; if not, write to the
|
19
19
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
20
20
|
Boston, MA 02111-1307 USA
|
21
|
-
*/
|
22
|
-
|
21
|
+
*/
|
23
22
|
package processing.core;
|
24
23
|
|
25
|
-
|
26
24
|
/**
|
27
|
-
* 4x4 matrix implementation.
|
28
|
-
*
|
29
|
-
*
|
30
|
-
* a vector (x, y, z, w) in {@code mult()}.
|
25
|
+
* 4x4 matrix implementation. Matrices are used to describe a transformation;
|
26
|
+
* see {@link PMatrix} for a general description. This matrix looks like the
|
27
|
+
* following when multiplying a vector (x, y, z, w) in {@code mult()}.
|
31
28
|
* <pre>
|
32
29
|
* [m00 m01 m02 m03][x] [m00*x + m01*y + m02*z + m03*w] [x']
|
33
30
|
* [m10 m11 m12 m13][y] = [m10*x + m11*y + m12*z + m13*w] = [y']
|
34
31
|
* [m20 m21 m22 m23][z] [m20*x + m21*y + m22*z + m23*w] [z']
|
35
|
-
* [m30 m31 m32 m33][w] [m30*x + m31*y + m32*z + m33*w] [w']</pre>
|
36
|
-
*
|
37
|
-
*
|
32
|
+
* [m30 m31 m32 m33][w] [m30*x + m31*y + m32*z + m33*w] [w']</pre> (x', y', z',
|
33
|
+
* w') is returned. The values in the matrix determine the transformation. They
|
34
|
+
* are modified by the various transformation functions.
|
38
35
|
*
|
39
|
-
* To transform 3D coordinates, w is set to 1, amd w' is made to be 1 by
|
40
|
-
*
|
41
|
-
*
|
36
|
+
* To transform 3D coordinates, w is set to 1, amd w' is made to be 1 by setting
|
37
|
+
* the bottom row of the matrix to <code>[0 0 0 1]</code>. The resulting point
|
38
|
+
* is then (x', y', z').
|
42
39
|
*/
|
43
40
|
public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
/**
|
43
|
+
*
|
44
|
+
*/
|
45
|
+
public float m00,
|
50
46
|
/**
|
51
47
|
*
|
52
48
|
*/
|
53
49
|
m01,
|
54
|
-
|
55
50
|
/**
|
56
51
|
*
|
57
52
|
*/
|
58
53
|
m02,
|
59
|
-
|
60
54
|
/**
|
61
55
|
*
|
62
56
|
*/
|
63
57
|
m03;
|
64
58
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
59
|
+
/**
|
60
|
+
*
|
61
|
+
*/
|
62
|
+
public float m10,
|
70
63
|
/**
|
71
64
|
*
|
72
65
|
*/
|
73
66
|
m11,
|
74
|
-
|
75
67
|
/**
|
76
68
|
*
|
77
69
|
*/
|
78
70
|
m12,
|
79
|
-
|
80
71
|
/**
|
81
72
|
*
|
82
73
|
*/
|
83
74
|
m13;
|
84
75
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
76
|
+
/**
|
77
|
+
*
|
78
|
+
*/
|
79
|
+
public float m20,
|
90
80
|
/**
|
91
81
|
*
|
92
82
|
*/
|
93
83
|
m21,
|
94
|
-
|
95
84
|
/**
|
96
85
|
*
|
97
86
|
*/
|
98
87
|
m22, m23;
|
99
88
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
89
|
+
/**
|
90
|
+
*
|
91
|
+
*/
|
92
|
+
public float m30,
|
105
93
|
/**
|
106
94
|
*
|
107
95
|
*/
|
108
96
|
m31,
|
109
|
-
|
110
97
|
/**
|
111
98
|
*
|
112
99
|
*/
|
113
100
|
m32,
|
114
|
-
|
115
101
|
/**
|
116
102
|
*
|
117
103
|
*/
|
118
104
|
m33;
|
119
105
|
|
120
|
-
|
121
106
|
// locally allocated version to avoid creating new memory
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
*/
|
107
|
+
/**
|
108
|
+
*
|
109
|
+
*/
|
126
110
|
protected PMatrix3D inverseCopy;
|
127
111
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
112
|
+
/**
|
113
|
+
*
|
114
|
+
*/
|
115
|
+
public PMatrix3D() {
|
132
116
|
reset();
|
133
117
|
}
|
134
118
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
119
|
+
/**
|
120
|
+
*
|
121
|
+
* @param m00
|
122
|
+
* @param m01
|
123
|
+
* @param m02
|
124
|
+
* @param m10
|
125
|
+
* @param m11
|
126
|
+
* @param m12
|
127
|
+
*/
|
128
|
+
public PMatrix3D(float m00, float m01, float m02,
|
129
|
+
float m10, float m11, float m12) {
|
146
130
|
set(m00, m01, m02, 0,
|
147
|
-
|
148
|
-
|
149
|
-
|
131
|
+
m10, m11, m12, 0,
|
132
|
+
0, 0, 1, 0,
|
133
|
+
0, 0, 0, 1);
|
150
134
|
}
|
151
135
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
136
|
+
/**
|
137
|
+
*
|
138
|
+
* @param m00
|
139
|
+
* @param m01
|
140
|
+
* @param m02
|
141
|
+
* @param m03
|
142
|
+
* @param m10
|
143
|
+
* @param m11
|
144
|
+
* @param m12
|
145
|
+
* @param m13
|
146
|
+
* @param m20
|
147
|
+
* @param m21
|
148
|
+
* @param m22
|
149
|
+
* @param m23
|
150
|
+
* @param m30
|
151
|
+
* @param m31
|
152
|
+
* @param m32
|
153
|
+
* @param m33
|
154
|
+
*/
|
155
|
+
public PMatrix3D(float m00, float m01, float m02, float m03,
|
156
|
+
float m10, float m11, float m12, float m13,
|
157
|
+
float m20, float m21, float m22, float m23,
|
158
|
+
float m30, float m31, float m32, float m33) {
|
175
159
|
set(m00, m01, m02, m03,
|
176
|
-
|
177
|
-
|
178
|
-
|
160
|
+
m10, m11, m12, m13,
|
161
|
+
m20, m21, m22, m23,
|
162
|
+
m30, m31, m32, m33);
|
179
163
|
}
|
180
164
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
165
|
+
/**
|
166
|
+
*
|
167
|
+
* @param matrix
|
168
|
+
*/
|
169
|
+
public PMatrix3D(PMatrix matrix) {
|
186
170
|
set(matrix);
|
187
171
|
}
|
188
172
|
|
189
|
-
|
173
|
+
@Override
|
190
174
|
public void reset() {
|
191
175
|
set(1, 0, 0, 0,
|
192
|
-
|
193
|
-
|
194
|
-
|
176
|
+
0, 1, 0, 0,
|
177
|
+
0, 0, 1, 0,
|
178
|
+
0, 0, 0, 1);
|
195
179
|
}
|
196
180
|
|
197
|
-
|
198
181
|
/**
|
199
182
|
* Returns a copy of this PMatrix.
|
200
|
-
|
183
|
+
*
|
184
|
+
* @return
|
201
185
|
*/
|
186
|
+
@Override
|
202
187
|
public PMatrix3D get() {
|
203
188
|
PMatrix3D outgoing = new PMatrix3D();
|
204
189
|
outgoing.set(this);
|
205
190
|
return outgoing;
|
206
191
|
}
|
207
192
|
|
208
|
-
|
209
193
|
/**
|
210
|
-
* Copies the matrix contents into a 16 entry float array.
|
211
|
-
*
|
212
|
-
|
213
|
-
|
194
|
+
* Copies the matrix contents into a 16 entry float array. If target is null
|
195
|
+
* (or not the correct size), a new array will be created.
|
196
|
+
*
|
197
|
+
* @param target
|
198
|
+
* @return
|
214
199
|
*/
|
200
|
+
@Override
|
215
201
|
public float[] get(float[] target) {
|
216
202
|
if ((target == null) || (target.length != 16)) {
|
217
203
|
target = new float[16];
|
@@ -239,28 +225,28 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
239
225
|
return target;
|
240
226
|
}
|
241
227
|
|
242
|
-
|
228
|
+
@Override
|
243
229
|
public void set(PMatrix matrix) {
|
244
230
|
if (matrix instanceof PMatrix3D) {
|
245
231
|
PMatrix3D src = (PMatrix3D) matrix;
|
246
232
|
set(src.m00, src.m01, src.m02, src.m03,
|
247
|
-
|
248
|
-
|
249
|
-
|
233
|
+
src.m10, src.m11, src.m12, src.m13,
|
234
|
+
src.m20, src.m21, src.m22, src.m23,
|
235
|
+
src.m30, src.m31, src.m32, src.m33);
|
250
236
|
} else {
|
251
237
|
PMatrix2D src = (PMatrix2D) matrix;
|
252
238
|
set(src.m00, src.m01, 0, src.m02,
|
253
|
-
|
254
|
-
|
255
|
-
|
239
|
+
src.m10, src.m11, 0, src.m12,
|
240
|
+
0, 0, 1, 0,
|
241
|
+
0, 0, 0, 1);
|
256
242
|
}
|
257
243
|
}
|
258
244
|
|
259
|
-
|
245
|
+
@Override
|
260
246
|
public void set(float[] source) {
|
261
247
|
if (source.length == 6) {
|
262
248
|
set(source[0], source[1], source[2],
|
263
|
-
|
249
|
+
source[3], source[4], source[5]);
|
264
250
|
|
265
251
|
} else if (source.length == 16) {
|
266
252
|
m00 = source[0];
|
@@ -285,98 +271,116 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
285
271
|
}
|
286
272
|
}
|
287
273
|
|
288
|
-
|
274
|
+
@Override
|
289
275
|
public void set(float m00, float m01, float m02,
|
290
|
-
|
276
|
+
float m10, float m11, float m12) {
|
291
277
|
set(m00, m01, 0, m02,
|
292
|
-
|
293
|
-
|
294
|
-
|
278
|
+
m10, m11, 0, m12,
|
279
|
+
0, 0, 1, 0,
|
280
|
+
0, 0, 0, 1);
|
295
281
|
}
|
296
282
|
|
297
|
-
|
283
|
+
@Override
|
298
284
|
public void set(float m00, float m01, float m02, float m03,
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
this.m00 = m00;
|
303
|
-
this.
|
304
|
-
this.
|
305
|
-
this.
|
285
|
+
float m10, float m11, float m12, float m13,
|
286
|
+
float m20, float m21, float m22, float m23,
|
287
|
+
float m30, float m31, float m32, float m33) {
|
288
|
+
this.m00 = m00;
|
289
|
+
this.m01 = m01;
|
290
|
+
this.m02 = m02;
|
291
|
+
this.m03 = m03;
|
292
|
+
this.m10 = m10;
|
293
|
+
this.m11 = m11;
|
294
|
+
this.m12 = m12;
|
295
|
+
this.m13 = m13;
|
296
|
+
this.m20 = m20;
|
297
|
+
this.m21 = m21;
|
298
|
+
this.m22 = m22;
|
299
|
+
this.m23 = m23;
|
300
|
+
this.m30 = m30;
|
301
|
+
this.m31 = m31;
|
302
|
+
this.m32 = m32;
|
303
|
+
this.m33 = m33;
|
306
304
|
}
|
307
305
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
306
|
+
/**
|
307
|
+
*
|
308
|
+
* @param tx
|
309
|
+
* @param ty
|
310
|
+
*/
|
311
|
+
@Override
|
312
|
+
public void translate(float tx, float ty) {
|
314
313
|
translate(tx, ty, 0);
|
315
314
|
}
|
316
315
|
|
317
316
|
// public void invTranslate(float tx, float ty) {
|
318
317
|
// invTranslate(tx, ty, 0);
|
319
318
|
// }
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
m03 += tx*m00 + ty*m01 + tz*m02;
|
329
|
-
m13 += tx*m10 + ty*m11 + tz*m12;
|
330
|
-
m23 += tx*m20 + ty*m21 + tz*m22;
|
331
|
-
m33 += tx*m30 + ty*m31 + tz*m32;
|
319
|
+
/**
|
320
|
+
*
|
321
|
+
* @param tx
|
322
|
+
* @param ty
|
323
|
+
* @param tz
|
324
|
+
*/
|
325
|
+
@Override
|
326
|
+
public void translate(float tx, float ty, float tz) {
|
327
|
+
m03 += tx * m00 + ty * m01 + tz * m02;
|
328
|
+
m13 += tx * m10 + ty * m11 + tz * m12;
|
329
|
+
m23 += tx * m20 + ty * m21 + tz * m22;
|
330
|
+
m33 += tx * m30 + ty * m31 + tz * m32;
|
332
331
|
}
|
333
332
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
333
|
+
/**
|
334
|
+
*
|
335
|
+
* @param angle
|
336
|
+
*/
|
337
|
+
@Override
|
338
|
+
public void rotate(float angle) {
|
339
339
|
rotateZ(angle);
|
340
340
|
}
|
341
341
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
342
|
+
/**
|
343
|
+
*
|
344
|
+
* @param angle
|
345
|
+
*/
|
346
|
+
@Override
|
347
|
+
public void rotateX(float angle) {
|
347
348
|
float c = cos(angle);
|
348
349
|
float s = sin(angle);
|
349
|
-
apply(1, 0, 0, 0,
|
350
|
+
apply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
350
351
|
}
|
351
352
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
353
|
+
/**
|
354
|
+
*
|
355
|
+
* @param angle
|
356
|
+
*/
|
357
|
+
@Override
|
358
|
+
public void rotateY(float angle) {
|
357
359
|
float c = cos(angle);
|
358
360
|
float s = sin(angle);
|
359
|
-
apply(c, 0, s, 0,
|
361
|
+
apply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
360
362
|
}
|
361
363
|
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
364
|
+
/**
|
365
|
+
*
|
366
|
+
* @param angle
|
367
|
+
*/
|
368
|
+
@Override
|
369
|
+
public void rotateZ(float angle) {
|
367
370
|
float c = cos(angle);
|
368
371
|
float s = sin(angle);
|
369
|
-
apply(c, -s, 0, 0,
|
372
|
+
apply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
370
373
|
}
|
371
374
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
375
|
+
/**
|
376
|
+
*
|
377
|
+
* @param angle
|
378
|
+
* @param v0
|
379
|
+
* @param v1
|
380
|
+
* @param v2
|
381
|
+
*/
|
382
|
+
@Override
|
383
|
+
public void rotate(float angle, float v0, float v1, float v2) {
|
380
384
|
float norm2 = v0 * v0 + v1 * v1 + v2 * v2;
|
381
385
|
if (norm2 < PConstants.EPSILON) {
|
382
386
|
// The vector is zero, cannot apply rotation.
|
@@ -395,70 +399,83 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
395
399
|
float s = sin(angle);
|
396
400
|
float t = 1.0f - c;
|
397
401
|
|
398
|
-
apply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
+
apply((t * v0 * v0) + c, (t * v0 * v1) - (s * v2), (t * v0 * v2) + (s * v1), 0,
|
403
|
+
(t * v0 * v1) + (s * v2), (t * v1 * v1) + c, (t * v1 * v2) - (s * v0), 0,
|
404
|
+
(t * v0 * v2) - (s * v1), (t * v1 * v2) + (s * v0), (t * v2 * v2) + c, 0,
|
405
|
+
0, 0, 0, 1);
|
402
406
|
}
|
403
407
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
408
|
+
/**
|
409
|
+
*
|
410
|
+
* @param s
|
411
|
+
*/
|
412
|
+
@Override
|
413
|
+
public void scale(float s) {
|
409
414
|
//apply(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
410
415
|
scale(s, s, s);
|
411
416
|
}
|
412
417
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
418
|
+
/**
|
419
|
+
*
|
420
|
+
* @param sx
|
421
|
+
* @param sy
|
422
|
+
*/
|
423
|
+
@Override
|
424
|
+
public void scale(float sx, float sy) {
|
419
425
|
//apply(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
420
426
|
scale(sx, sy, 1);
|
421
427
|
}
|
422
428
|
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
429
|
+
/**
|
430
|
+
*
|
431
|
+
* @param x
|
432
|
+
* @param y
|
433
|
+
* @param z
|
434
|
+
*/
|
435
|
+
@Override
|
436
|
+
public void scale(float x, float y, float z) {
|
430
437
|
//apply(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
431
|
-
m00 *= x;
|
432
|
-
|
433
|
-
|
434
|
-
|
438
|
+
m00 *= x;
|
439
|
+
m01 *= y;
|
440
|
+
m02 *= z;
|
441
|
+
m10 *= x;
|
442
|
+
m11 *= y;
|
443
|
+
m12 *= z;
|
444
|
+
m20 *= x;
|
445
|
+
m21 *= y;
|
446
|
+
m22 *= z;
|
447
|
+
m30 *= x;
|
448
|
+
m31 *= y;
|
449
|
+
m32 *= z;
|
435
450
|
}
|
436
451
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
452
|
+
/**
|
453
|
+
*
|
454
|
+
* @param angle
|
455
|
+
*/
|
456
|
+
@Override
|
457
|
+
public void shearX(float angle) {
|
442
458
|
float t = (float) Math.tan(angle);
|
443
459
|
apply(1, t, 0, 0,
|
444
|
-
|
445
|
-
|
446
|
-
|
460
|
+
0, 1, 0, 0,
|
461
|
+
0, 0, 1, 0,
|
462
|
+
0, 0, 0, 1);
|
447
463
|
}
|
448
464
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
465
|
+
/**
|
466
|
+
*
|
467
|
+
* @param angle
|
468
|
+
*/
|
469
|
+
@Override
|
470
|
+
public void shearY(float angle) {
|
454
471
|
float t = (float) Math.tan(angle);
|
455
472
|
apply(1, 0, 0, 0,
|
456
|
-
|
457
|
-
|
458
|
-
|
473
|
+
t, 1, 0, 0,
|
474
|
+
0, 0, 1, 0,
|
475
|
+
0, 0, 0, 1);
|
459
476
|
}
|
460
477
|
|
461
|
-
|
478
|
+
@Override
|
462
479
|
public void apply(PMatrix source) {
|
463
480
|
if (source instanceof PMatrix2D) {
|
464
481
|
apply((PMatrix2D) source);
|
@@ -467,80 +484,94 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
467
484
|
}
|
468
485
|
}
|
469
486
|
|
470
|
-
|
487
|
+
@Override
|
471
488
|
public void apply(PMatrix2D source) {
|
472
489
|
apply(source.m00, source.m01, 0, source.m02,
|
473
|
-
|
474
|
-
|
475
|
-
|
490
|
+
source.m10, source.m11, 0, source.m12,
|
491
|
+
0, 0, 1, 0,
|
492
|
+
0, 0, 0, 1);
|
476
493
|
}
|
477
494
|
|
478
|
-
|
495
|
+
@Override
|
479
496
|
public void apply(PMatrix3D source) {
|
480
497
|
apply(source.m00, source.m01, source.m02, source.m03,
|
481
|
-
|
482
|
-
|
483
|
-
|
498
|
+
source.m10, source.m11, source.m12, source.m13,
|
499
|
+
source.m20, source.m21, source.m22, source.m23,
|
500
|
+
source.m30, source.m31, source.m32, source.m33);
|
484
501
|
}
|
485
502
|
|
486
|
-
|
503
|
+
@Override
|
487
504
|
public void apply(float n00, float n01, float n02,
|
488
|
-
|
505
|
+
float n10, float n11, float n12) {
|
489
506
|
apply(n00, n01, 0, n02,
|
490
|
-
|
491
|
-
|
492
|
-
|
507
|
+
n10, n11, 0, n12,
|
508
|
+
0, 0, 1, 0,
|
509
|
+
0, 0, 0, 1);
|
493
510
|
}
|
494
511
|
|
495
|
-
|
512
|
+
@Override
|
496
513
|
public void apply(float n00, float n01, float n02, float n03,
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
float r00 = m00*n00 + m01*n10 + m02*n20 + m03*n30;
|
502
|
-
float r01 = m00*n01 + m01*n11 + m02*n21 + m03*n31;
|
503
|
-
float r02 = m00*n02 + m01*n12 + m02*n22 + m03*n32;
|
504
|
-
float r03 = m00*n03 + m01*n13 + m02*n23 + m03*n33;
|
505
|
-
|
506
|
-
float r10 = m10*n00 + m11*n10 + m12*n20 + m13*n30;
|
507
|
-
float r11 = m10*n01 + m11*n11 + m12*n21 + m13*n31;
|
508
|
-
float r12 = m10*n02 + m11*n12 + m12*n22 + m13*n32;
|
509
|
-
float r13 = m10*n03 + m11*n13 + m12*n23 + m13*n33;
|
510
|
-
|
511
|
-
float r20 = m20*n00 + m21*n10 + m22*n20 + m23*n30;
|
512
|
-
float r21 = m20*n01 + m21*n11 + m22*n21 + m23*n31;
|
513
|
-
float r22 = m20*n02 + m21*n12 + m22*n22 + m23*n32;
|
514
|
-
float r23 = m20*n03 + m21*n13 + m22*n23 + m23*n33;
|
515
|
-
|
516
|
-
float r30 = m30*n00 + m31*n10 + m32*n20 + m33*n30;
|
517
|
-
float r31 = m30*n01 + m31*n11 + m32*n21 + m33*n31;
|
518
|
-
float r32 = m30*n02 + m31*n12 + m32*n22 + m33*n32;
|
519
|
-
float r33 = m30*n03 + m31*n13 + m32*n23 + m33*n33;
|
520
|
-
|
521
|
-
m00 = r00;
|
522
|
-
|
523
|
-
|
524
|
-
|
514
|
+
float n10, float n11, float n12, float n13,
|
515
|
+
float n20, float n21, float n22, float n23,
|
516
|
+
float n30, float n31, float n32, float n33) {
|
517
|
+
|
518
|
+
float r00 = m00 * n00 + m01 * n10 + m02 * n20 + m03 * n30;
|
519
|
+
float r01 = m00 * n01 + m01 * n11 + m02 * n21 + m03 * n31;
|
520
|
+
float r02 = m00 * n02 + m01 * n12 + m02 * n22 + m03 * n32;
|
521
|
+
float r03 = m00 * n03 + m01 * n13 + m02 * n23 + m03 * n33;
|
522
|
+
|
523
|
+
float r10 = m10 * n00 + m11 * n10 + m12 * n20 + m13 * n30;
|
524
|
+
float r11 = m10 * n01 + m11 * n11 + m12 * n21 + m13 * n31;
|
525
|
+
float r12 = m10 * n02 + m11 * n12 + m12 * n22 + m13 * n32;
|
526
|
+
float r13 = m10 * n03 + m11 * n13 + m12 * n23 + m13 * n33;
|
527
|
+
|
528
|
+
float r20 = m20 * n00 + m21 * n10 + m22 * n20 + m23 * n30;
|
529
|
+
float r21 = m20 * n01 + m21 * n11 + m22 * n21 + m23 * n31;
|
530
|
+
float r22 = m20 * n02 + m21 * n12 + m22 * n22 + m23 * n32;
|
531
|
+
float r23 = m20 * n03 + m21 * n13 + m22 * n23 + m23 * n33;
|
532
|
+
|
533
|
+
float r30 = m30 * n00 + m31 * n10 + m32 * n20 + m33 * n30;
|
534
|
+
float r31 = m30 * n01 + m31 * n11 + m32 * n21 + m33 * n31;
|
535
|
+
float r32 = m30 * n02 + m31 * n12 + m32 * n22 + m33 * n32;
|
536
|
+
float r33 = m30 * n03 + m31 * n13 + m32 * n23 + m33 * n33;
|
537
|
+
|
538
|
+
m00 = r00;
|
539
|
+
m01 = r01;
|
540
|
+
m02 = r02;
|
541
|
+
m03 = r03;
|
542
|
+
m10 = r10;
|
543
|
+
m11 = r11;
|
544
|
+
m12 = r12;
|
545
|
+
m13 = r13;
|
546
|
+
m20 = r20;
|
547
|
+
m21 = r21;
|
548
|
+
m22 = r22;
|
549
|
+
m23 = r23;
|
550
|
+
m30 = r30;
|
551
|
+
m31 = r31;
|
552
|
+
m32 = r32;
|
553
|
+
m33 = r33;
|
525
554
|
}
|
526
555
|
|
527
|
-
|
528
556
|
/**
|
529
557
|
* Apply the 3D equivalent of the 2D matrix supplied to the left of this one.
|
530
|
-
|
558
|
+
*
|
559
|
+
* @param left
|
531
560
|
*/
|
561
|
+
@Override
|
532
562
|
public void preApply(PMatrix2D left) {
|
533
563
|
preApply(left.m00, left.m01, 0, left.m02,
|
534
|
-
|
535
|
-
|
536
|
-
|
564
|
+
left.m10, left.m11, 0, left.m12,
|
565
|
+
0, 0, 1, 0,
|
566
|
+
0, 0, 0, 1);
|
537
567
|
}
|
538
568
|
|
539
|
-
|
540
569
|
/**
|
541
570
|
* Apply another matrix to the left of this one.
|
542
|
-
|
571
|
+
*
|
572
|
+
* @param source
|
543
573
|
*/
|
574
|
+
@Override
|
544
575
|
public void preApply(PMatrix source) {
|
545
576
|
if (source instanceof PMatrix2D) {
|
546
577
|
preApply((PMatrix2D) source);
|
@@ -549,107 +580,121 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
549
580
|
}
|
550
581
|
}
|
551
582
|
|
552
|
-
|
553
583
|
/**
|
554
584
|
* Apply another matrix to the left of this one.
|
555
|
-
|
585
|
+
*
|
586
|
+
* @param left
|
556
587
|
*/
|
588
|
+
@Override
|
557
589
|
public void preApply(PMatrix3D left) {
|
558
590
|
preApply(left.m00, left.m01, left.m02, left.m03,
|
559
|
-
|
560
|
-
|
561
|
-
|
591
|
+
left.m10, left.m11, left.m12, left.m13,
|
592
|
+
left.m20, left.m21, left.m22, left.m23,
|
593
|
+
left.m30, left.m31, left.m32, left.m33);
|
562
594
|
}
|
563
595
|
|
564
|
-
|
565
596
|
/**
|
566
597
|
* Apply the 3D equivalent of the 2D matrix supplied to the left of this one.
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
598
|
+
*
|
599
|
+
* @param n00
|
600
|
+
* @param n01
|
601
|
+
* @param n10
|
602
|
+
* @param n02
|
603
|
+
* @param n11
|
604
|
+
* @param n12
|
573
605
|
*/
|
606
|
+
@Override
|
574
607
|
public void preApply(float n00, float n01, float n02,
|
575
|
-
|
608
|
+
float n10, float n11, float n12) {
|
576
609
|
preApply(n00, n01, 0, n02,
|
577
|
-
|
578
|
-
|
579
|
-
|
610
|
+
n10, n11, 0, n12,
|
611
|
+
0, 0, 1, 0,
|
612
|
+
0, 0, 0, 1);
|
580
613
|
}
|
581
614
|
|
582
|
-
|
583
615
|
/**
|
584
616
|
* Apply another matrix to the left of this one.
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
617
|
+
*
|
618
|
+
* @param n00
|
619
|
+
* @param n01
|
620
|
+
* @param n03
|
621
|
+
* @param n02
|
622
|
+
* @param n32
|
623
|
+
* @param n10
|
624
|
+
* @param n12
|
625
|
+
* @param n23
|
626
|
+
* @param n20
|
627
|
+
* @param n11
|
628
|
+
* @param n21
|
629
|
+
* @param n13
|
630
|
+
* @param n31
|
631
|
+
* @param n22
|
632
|
+
* @param n30
|
633
|
+
* @param n33
|
601
634
|
*/
|
635
|
+
@Override
|
602
636
|
public void preApply(float n00, float n01, float n02, float n03,
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
float r00 = n00*m00 + n01*m10 + n02*m20 + n03*m30;
|
608
|
-
float r01 = n00*m01 + n01*m11 + n02*m21 + n03*m31;
|
609
|
-
float r02 = n00*m02 + n01*m12 + n02*m22 + n03*m32;
|
610
|
-
float r03 = n00*m03 + n01*m13 + n02*m23 + n03*m33;
|
611
|
-
|
612
|
-
float r10 = n10*m00 + n11*m10 + n12*m20 + n13*m30;
|
613
|
-
float r11 = n10*m01 + n11*m11 + n12*m21 + n13*m31;
|
614
|
-
float r12 = n10*m02 + n11*m12 + n12*m22 + n13*m32;
|
615
|
-
float r13 = n10*m03 + n11*m13 + n12*m23 + n13*m33;
|
616
|
-
|
617
|
-
float r20 = n20*m00 + n21*m10 + n22*m20 + n23*m30;
|
618
|
-
float r21 = n20*m01 + n21*m11 + n22*m21 + n23*m31;
|
619
|
-
float r22 = n20*m02 + n21*m12 + n22*m22 + n23*m32;
|
620
|
-
float r23 = n20*m03 + n21*m13 + n22*m23 + n23*m33;
|
621
|
-
|
622
|
-
float r30 = n30*m00 + n31*m10 + n32*m20 + n33*m30;
|
623
|
-
float r31 = n30*m01 + n31*m11 + n32*m21 + n33*m31;
|
624
|
-
float r32 = n30*m02 + n31*m12 + n32*m22 + n33*m32;
|
625
|
-
float r33 = n30*m03 + n31*m13 + n32*m23 + n33*m33;
|
626
|
-
|
627
|
-
m00 = r00;
|
628
|
-
|
629
|
-
|
630
|
-
|
637
|
+
float n10, float n11, float n12, float n13,
|
638
|
+
float n20, float n21, float n22, float n23,
|
639
|
+
float n30, float n31, float n32, float n33) {
|
640
|
+
|
641
|
+
float r00 = n00 * m00 + n01 * m10 + n02 * m20 + n03 * m30;
|
642
|
+
float r01 = n00 * m01 + n01 * m11 + n02 * m21 + n03 * m31;
|
643
|
+
float r02 = n00 * m02 + n01 * m12 + n02 * m22 + n03 * m32;
|
644
|
+
float r03 = n00 * m03 + n01 * m13 + n02 * m23 + n03 * m33;
|
645
|
+
|
646
|
+
float r10 = n10 * m00 + n11 * m10 + n12 * m20 + n13 * m30;
|
647
|
+
float r11 = n10 * m01 + n11 * m11 + n12 * m21 + n13 * m31;
|
648
|
+
float r12 = n10 * m02 + n11 * m12 + n12 * m22 + n13 * m32;
|
649
|
+
float r13 = n10 * m03 + n11 * m13 + n12 * m23 + n13 * m33;
|
650
|
+
|
651
|
+
float r20 = n20 * m00 + n21 * m10 + n22 * m20 + n23 * m30;
|
652
|
+
float r21 = n20 * m01 + n21 * m11 + n22 * m21 + n23 * m31;
|
653
|
+
float r22 = n20 * m02 + n21 * m12 + n22 * m22 + n23 * m32;
|
654
|
+
float r23 = n20 * m03 + n21 * m13 + n22 * m23 + n23 * m33;
|
655
|
+
|
656
|
+
float r30 = n30 * m00 + n31 * m10 + n32 * m20 + n33 * m30;
|
657
|
+
float r31 = n30 * m01 + n31 * m11 + n32 * m21 + n33 * m31;
|
658
|
+
float r32 = n30 * m02 + n31 * m12 + n32 * m22 + n33 * m32;
|
659
|
+
float r33 = n30 * m03 + n31 * m13 + n32 * m23 + n33 * m33;
|
660
|
+
|
661
|
+
m00 = r00;
|
662
|
+
m01 = r01;
|
663
|
+
m02 = r02;
|
664
|
+
m03 = r03;
|
665
|
+
m10 = r10;
|
666
|
+
m11 = r11;
|
667
|
+
m12 = r12;
|
668
|
+
m13 = r13;
|
669
|
+
m20 = r20;
|
670
|
+
m21 = r21;
|
671
|
+
m22 = r22;
|
672
|
+
m23 = r23;
|
673
|
+
m30 = r30;
|
674
|
+
m31 = r31;
|
675
|
+
m32 = r32;
|
676
|
+
m33 = r33;
|
631
677
|
}
|
632
678
|
|
633
|
-
|
634
679
|
//////////////////////////////////////////////////////////////
|
635
|
-
|
636
|
-
|
637
680
|
/**
|
638
|
-
* Multiply source by this matrix, and return the result.
|
639
|
-
*
|
640
|
-
*
|
641
|
-
*
|
642
|
-
|
643
|
-
|
644
|
-
|
681
|
+
* Multiply source by this matrix, and return the result. The result will be
|
682
|
+
* stored in target if target is non-null, and target will then be the matrix
|
683
|
+
* returned. This improves performance if you reuse target, so it's
|
684
|
+
* recommended if you call this many times in draw().
|
685
|
+
*
|
686
|
+
* @param source
|
687
|
+
* @param target
|
688
|
+
* @return
|
645
689
|
*/
|
690
|
+
@Override
|
646
691
|
public PVector mult(PVector source, PVector target) {
|
647
692
|
if (target == null) {
|
648
693
|
target = new PVector();
|
649
694
|
}
|
650
|
-
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
|
651
|
-
|
652
|
-
|
695
|
+
target.set(m00 * source.x + m01 * source.y + m02 * source.z + m03,
|
696
|
+
m10 * source.x + m11 * source.y + m12 * source.z + m13,
|
697
|
+
m20 * source.x + m21 * source.y + m22 * source.z + m23);
|
653
698
|
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
|
654
699
|
// if (tw != 0 && tw != 1) {
|
655
700
|
// target.div(tw);
|
@@ -672,195 +717,208 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
672
717
|
}
|
673
718
|
return target;
|
674
719
|
}
|
675
|
-
|
676
|
-
|
677
|
-
|
720
|
+
*/
|
678
721
|
/**
|
679
|
-
* Multiply a three or four element vector against this matrix. If out is
|
680
|
-
*
|
722
|
+
* Multiply a three or four element vector against this matrix. If out is null
|
723
|
+
* or not length 3 or 4, a new float array (length 3) will be returned.
|
681
724
|
* Supplying and recycling a target array improves performance, so it's
|
682
725
|
* recommended if you call this many times in draw.
|
683
|
-
|
684
|
-
|
685
|
-
|
726
|
+
*
|
727
|
+
* @param source
|
728
|
+
* @param target
|
729
|
+
* @return
|
686
730
|
*/
|
731
|
+
@Override
|
687
732
|
public float[] mult(float[] source, float[] target) {
|
688
733
|
if (target == null || target.length < 3) {
|
689
734
|
target = new float[3];
|
690
735
|
}
|
691
736
|
if (source == target) {
|
692
|
-
throw new RuntimeException("The source and target vectors used in "
|
693
|
-
|
737
|
+
throw new RuntimeException("The source and target vectors used in "
|
738
|
+
+ "PMatrix3D.mult() cannot be identical.");
|
694
739
|
}
|
695
740
|
if (target.length == 3) {
|
696
|
-
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03;
|
697
|
-
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13;
|
698
|
-
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23;
|
741
|
+
target[0] = m00 * source[0] + m01 * source[1] + m02 * source[2] + m03;
|
742
|
+
target[1] = m10 * source[0] + m11 * source[1] + m12 * source[2] + m13;
|
743
|
+
target[2] = m20 * source[0] + m21 * source[1] + m22 * source[2] + m23;
|
699
744
|
//float w = m30*source[0] + m31*source[1] + m32*source[2] + m33;
|
700
745
|
//if (w != 0 && w != 1) {
|
701
746
|
// target[0] /= w; target[1] /= w; target[2] /= w;
|
702
747
|
//}
|
703
748
|
} else if (target.length > 3) {
|
704
|
-
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03*source[3];
|
705
|
-
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13*source[3];
|
706
|
-
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23*source[3];
|
707
|
-
target[3] = m30*source[0] + m31*source[1] + m32*source[2] + m33*source[3];
|
749
|
+
target[0] = m00 * source[0] + m01 * source[1] + m02 * source[2] + m03 * source[3];
|
750
|
+
target[1] = m10 * source[0] + m11 * source[1] + m12 * source[2] + m13 * source[3];
|
751
|
+
target[2] = m20 * source[0] + m21 * source[1] + m22 * source[2] + m23 * source[3];
|
752
|
+
target[3] = m30 * source[0] + m31 * source[1] + m32 * source[2] + m33 * source[3];
|
708
753
|
}
|
709
754
|
return target;
|
710
755
|
}
|
711
756
|
|
712
|
-
|
713
757
|
/**
|
714
|
-
* Returns the x-coordinate of the result of multiplying the point (x, y)
|
715
|
-
*
|
716
|
-
|
717
|
-
|
718
|
-
|
758
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y) by
|
759
|
+
* this matrix.
|
760
|
+
*
|
761
|
+
* @param x
|
762
|
+
* @param y
|
763
|
+
* @return
|
719
764
|
*/
|
720
765
|
public float multX(float x, float y) {
|
721
|
-
return m00*x + m01*y + m03;
|
766
|
+
return m00 * x + m01 * y + m03;
|
722
767
|
}
|
723
768
|
|
724
|
-
|
725
769
|
/**
|
726
|
-
* Returns the y-coordinate of the result of multiplying the point (x, y)
|
727
|
-
*
|
728
|
-
|
729
|
-
|
730
|
-
|
770
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y) by
|
771
|
+
* this matrix.
|
772
|
+
*
|
773
|
+
* @param x
|
774
|
+
* @param y
|
775
|
+
* @return
|
731
776
|
*/
|
732
777
|
public float multY(float x, float y) {
|
733
|
-
return m10*x + m11*y + m13;
|
778
|
+
return m10 * x + m11 * y + m13;
|
734
779
|
}
|
735
780
|
|
736
|
-
|
737
781
|
/**
|
738
782
|
* Returns the x-coordinate of the result of multiplying the point (x, y, z)
|
739
783
|
* by this matrix.
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
784
|
+
*
|
785
|
+
* @param x
|
786
|
+
* @param y
|
787
|
+
* @param z
|
788
|
+
* @return
|
744
789
|
*/
|
745
790
|
public float multX(float x, float y, float z) {
|
746
|
-
return m00*x + m01*y + m02*z + m03;
|
791
|
+
return m00 * x + m01 * y + m02 * z + m03;
|
747
792
|
}
|
748
793
|
|
749
|
-
|
750
794
|
/**
|
751
795
|
* Returns the y-coordinate of the result of multiplying the point (x, y, z)
|
752
796
|
* by this matrix.
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
797
|
+
*
|
798
|
+
* @param x
|
799
|
+
* @param y
|
800
|
+
* @param z
|
801
|
+
* @return
|
757
802
|
*/
|
758
803
|
public float multY(float x, float y, float z) {
|
759
|
-
return m10*x + m11*y + m12*z + m13;
|
804
|
+
return m10 * x + m11 * y + m12 * z + m13;
|
760
805
|
}
|
761
806
|
|
762
|
-
|
763
807
|
/**
|
764
808
|
* Returns the z-coordinate of the result of multiplying the point (x, y, z)
|
765
809
|
* by this matrix.
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
810
|
+
*
|
811
|
+
* @param x
|
812
|
+
* @param y
|
813
|
+
* @param z
|
814
|
+
* @return
|
770
815
|
*/
|
771
816
|
public float multZ(float x, float y, float z) {
|
772
|
-
return m20*x + m21*y + m22*z + m23;
|
817
|
+
return m20 * x + m21 * y + m22 * z + m23;
|
773
818
|
}
|
774
819
|
|
775
|
-
|
776
820
|
/**
|
777
|
-
* Returns the fourth element of the result of multiplying the vector
|
778
|
-
*
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
821
|
+
* Returns the fourth element of the result of multiplying the vector (x, y,
|
822
|
+
* z) by this matrix. (Acts as if w = 1 was supplied.)
|
823
|
+
*
|
824
|
+
* @param x
|
825
|
+
* @param y
|
826
|
+
* @param z
|
827
|
+
* @return
|
783
828
|
*/
|
784
829
|
public float multW(float x, float y, float z) {
|
785
|
-
return m30*x + m31*y + m32*z + m33;
|
830
|
+
return m30 * x + m31 * y + m32 * z + m33;
|
786
831
|
}
|
787
832
|
|
788
|
-
|
789
833
|
/**
|
790
|
-
* Returns the x-coordinate of the result of multiplying the vector
|
791
|
-
*
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
834
|
+
* Returns the x-coordinate of the result of multiplying the vector (x, y, z,
|
835
|
+
* w) by this matrix.
|
836
|
+
*
|
837
|
+
* @param x
|
838
|
+
* @param y
|
839
|
+
* @param z
|
840
|
+
* @param w
|
841
|
+
* @return
|
797
842
|
*/
|
798
843
|
public float multX(float x, float y, float z, float w) {
|
799
|
-
return m00*x + m01*y + m02*z + m03*w;
|
844
|
+
return m00 * x + m01 * y + m02 * z + m03 * w;
|
800
845
|
}
|
801
846
|
|
802
|
-
|
803
847
|
/**
|
804
|
-
* Returns the y-coordinate of the result of multiplying the vector
|
805
|
-
*
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
848
|
+
* Returns the y-coordinate of the result of multiplying the vector (x, y, z,
|
849
|
+
* w) by this matrix.
|
850
|
+
*
|
851
|
+
* @param x
|
852
|
+
* @param w
|
853
|
+
* @param y
|
854
|
+
* @param z
|
855
|
+
* @return
|
811
856
|
*/
|
812
857
|
public float multY(float x, float y, float z, float w) {
|
813
|
-
return m10*x + m11*y + m12*z + m13*w;
|
858
|
+
return m10 * x + m11 * y + m12 * z + m13 * w;
|
814
859
|
}
|
815
860
|
|
816
|
-
|
817
861
|
/**
|
818
|
-
* Returns the z-coordinate of the result of multiplying the vector
|
819
|
-
*
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
862
|
+
* Returns the z-coordinate of the result of multiplying the vector (x, y, z,
|
863
|
+
* w) by this matrix.
|
864
|
+
*
|
865
|
+
* @param x
|
866
|
+
* @param y
|
867
|
+
* @param z
|
868
|
+
* @param w
|
869
|
+
* @return
|
825
870
|
*/
|
826
871
|
public float multZ(float x, float y, float z, float w) {
|
827
|
-
return m20*x + m21*y + m22*z + m23*w;
|
872
|
+
return m20 * x + m21 * y + m22 * z + m23 * w;
|
828
873
|
}
|
829
874
|
|
830
|
-
|
831
875
|
/**
|
832
|
-
* Returns the w-coordinate of the result of multiplying the vector
|
833
|
-
*
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
876
|
+
* Returns the w-coordinate of the result of multiplying the vector (x, y, z,
|
877
|
+
* w) by this matrix.
|
878
|
+
*
|
879
|
+
* @param x
|
880
|
+
* @param y
|
881
|
+
* @param z
|
882
|
+
* @param w
|
883
|
+
* @return
|
839
884
|
*/
|
840
885
|
public float multW(float x, float y, float z, float w) {
|
841
|
-
return m30*x + m31*y + m32*z + m33*w;
|
886
|
+
return m30 * x + m31 * y + m32 * z + m33 * w;
|
842
887
|
}
|
843
888
|
|
844
|
-
|
845
889
|
/**
|
846
890
|
* Transpose this matrix; rows become columns and columns rows.
|
847
891
|
*/
|
892
|
+
@Override
|
848
893
|
public void transpose() {
|
849
894
|
float temp;
|
850
|
-
temp = m01;
|
851
|
-
|
852
|
-
|
853
|
-
temp =
|
854
|
-
|
855
|
-
|
895
|
+
temp = m01;
|
896
|
+
m01 = m10;
|
897
|
+
m10 = temp;
|
898
|
+
temp = m02;
|
899
|
+
m02 = m20;
|
900
|
+
m20 = temp;
|
901
|
+
temp = m03;
|
902
|
+
m03 = m30;
|
903
|
+
m30 = temp;
|
904
|
+
temp = m12;
|
905
|
+
m12 = m21;
|
906
|
+
m21 = temp;
|
907
|
+
temp = m13;
|
908
|
+
m13 = m31;
|
909
|
+
m31 = temp;
|
910
|
+
temp = m23;
|
911
|
+
m23 = m32;
|
912
|
+
m32 = temp;
|
856
913
|
}
|
857
914
|
|
858
|
-
|
859
915
|
/**
|
860
|
-
* Invert this matrix. Will not necessarily succeed, because some matrices
|
861
|
-
*
|
916
|
+
* Invert this matrix. Will not necessarily succeed, because some matrices map
|
917
|
+
* more than one point to the same image point, and so are irreversible.
|
918
|
+
*
|
862
919
|
* @return true if successful
|
863
920
|
*/
|
921
|
+
@Override
|
864
922
|
public boolean invert() {
|
865
923
|
float determinant = determinant();
|
866
924
|
if (determinant == 0) {
|
@@ -868,28 +926,28 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
868
926
|
}
|
869
927
|
|
870
928
|
// first row
|
871
|
-
float t00 =
|
929
|
+
float t00 = determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
872
930
|
float t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33);
|
873
|
-
float t02 =
|
931
|
+
float t02 = determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33);
|
874
932
|
float t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32);
|
875
933
|
|
876
934
|
// second row
|
877
935
|
float t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33);
|
878
|
-
float t11 =
|
936
|
+
float t11 = determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33);
|
879
937
|
float t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33);
|
880
|
-
float t13 =
|
938
|
+
float t13 = determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32);
|
881
939
|
|
882
940
|
// third row
|
883
|
-
float t20 =
|
941
|
+
float t20 = determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33);
|
884
942
|
float t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33);
|
885
|
-
float t22 =
|
943
|
+
float t22 = determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33);
|
886
944
|
float t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32);
|
887
945
|
|
888
946
|
// fourth row
|
889
947
|
float t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23);
|
890
|
-
float t31 =
|
948
|
+
float t31 = determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23);
|
891
949
|
float t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23);
|
892
|
-
float t33 =
|
950
|
+
float t33 = determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
893
951
|
|
894
952
|
// transpose and divide by the determinant
|
895
953
|
m00 = t00 / determinant;
|
@@ -915,161 +973,155 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
915
973
|
return true;
|
916
974
|
}
|
917
975
|
|
918
|
-
|
919
976
|
/**
|
920
977
|
* Calculate the determinant of a 3x3 matrix.
|
978
|
+
*
|
921
979
|
* @return result
|
922
980
|
*/
|
923
981
|
private float determinant3x3(float t00, float t01, float t02,
|
924
|
-
|
925
|
-
|
926
|
-
return (t00 * (t11 * t22 - t12 * t21)
|
927
|
-
|
928
|
-
|
982
|
+
float t10, float t11, float t12,
|
983
|
+
float t20, float t21, float t22) {
|
984
|
+
return (t00 * (t11 * t22 - t12 * t21)
|
985
|
+
+ t01 * (t12 * t20 - t10 * t22)
|
986
|
+
+ t02 * (t10 * t21 - t11 * t20));
|
929
987
|
}
|
930
988
|
|
931
|
-
|
932
989
|
/**
|
933
990
|
* @return the determinant of the matrix
|
934
991
|
*/
|
992
|
+
@Override
|
935
993
|
public float determinant() {
|
936
|
-
float f
|
937
|
-
m00
|
994
|
+
float f
|
995
|
+
= m00
|
938
996
|
* ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32)
|
939
|
-
|
940
|
-
|
941
|
-
|
997
|
+
- m13 * m22 * m31
|
998
|
+
- m11 * m23 * m32
|
999
|
+
- m12 * m21 * m33);
|
942
1000
|
f -= m01
|
943
1001
|
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
|
944
|
-
|
945
|
-
|
946
|
-
|
1002
|
+
- m13 * m22 * m30
|
1003
|
+
- m10 * m23 * m32
|
1004
|
+
- m12 * m20 * m33);
|
947
1005
|
f += m02
|
948
1006
|
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
|
949
|
-
|
950
|
-
|
951
|
-
|
1007
|
+
- m13 * m21 * m30
|
1008
|
+
- m10 * m23 * m31
|
1009
|
+
- m11 * m20 * m33);
|
952
1010
|
f -= m03
|
953
1011
|
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
|
954
|
-
|
955
|
-
|
956
|
-
|
1012
|
+
- m12 * m21 * m30
|
1013
|
+
- m10 * m22 * m31
|
1014
|
+
- m11 * m20 * m32);
|
957
1015
|
return f;
|
958
1016
|
}
|
959
1017
|
|
960
|
-
|
961
1018
|
//////////////////////////////////////////////////////////////
|
962
|
-
|
963
1019
|
// REVERSE VERSIONS OF MATRIX OPERATIONS
|
964
|
-
|
965
1020
|
// These functions should not be used, as they will be removed in the future.
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
*/
|
973
|
-
|
974
|
-
|
1021
|
+
/**
|
1022
|
+
*
|
1023
|
+
* @param tx
|
1024
|
+
* @param ty
|
1025
|
+
* @param tz
|
1026
|
+
*/
|
975
1027
|
protected void invTranslate(float tx, float ty, float tz) {
|
976
1028
|
preApply(1, 0, 0, -tx,
|
977
|
-
|
978
|
-
|
979
|
-
|
1029
|
+
0, 1, 0, -ty,
|
1030
|
+
0, 0, 1, -tz,
|
1031
|
+
0, 0, 0, 1);
|
980
1032
|
}
|
981
1033
|
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
1034
|
+
/**
|
1035
|
+
*
|
1036
|
+
* @param angle
|
1037
|
+
*/
|
1038
|
+
protected void invRotateX(float angle) {
|
987
1039
|
float c = cos(-angle);
|
988
1040
|
float s = sin(-angle);
|
989
|
-
preApply(1, 0, 0, 0,
|
1041
|
+
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
990
1042
|
}
|
991
1043
|
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
1044
|
+
/**
|
1045
|
+
*
|
1046
|
+
* @param angle
|
1047
|
+
*/
|
1048
|
+
protected void invRotateY(float angle) {
|
997
1049
|
float c = cos(-angle);
|
998
1050
|
float s = sin(-angle);
|
999
|
-
preApply(c, 0, s, 0,
|
1051
|
+
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
1000
1052
|
}
|
1001
1053
|
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1054
|
+
/**
|
1055
|
+
*
|
1056
|
+
* @param angle
|
1057
|
+
*/
|
1058
|
+
protected void invRotateZ(float angle) {
|
1007
1059
|
float c = cos(-angle);
|
1008
1060
|
float s = sin(-angle);
|
1009
|
-
preApply(c, -s, 0, 0,
|
1061
|
+
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
1010
1062
|
}
|
1011
1063
|
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1064
|
+
/**
|
1065
|
+
*
|
1066
|
+
* @param angle
|
1067
|
+
* @param v0
|
1068
|
+
* @param v1
|
1069
|
+
* @param v2
|
1070
|
+
*/
|
1071
|
+
protected void invRotate(float angle, float v0, float v1, float v2) {
|
1020
1072
|
//TODO should make sure this vector is normalized
|
1021
1073
|
|
1022
1074
|
float c = cos(-angle);
|
1023
1075
|
float s = sin(-angle);
|
1024
1076
|
float t = 1.0f - c;
|
1025
1077
|
|
1026
|
-
preApply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1078
|
+
preApply((t * v0 * v0) + c, (t * v0 * v1) - (s * v2), (t * v0 * v2) + (s * v1), 0,
|
1079
|
+
(t * v0 * v1) + (s * v2), (t * v1 * v1) + c, (t * v1 * v2) - (s * v0), 0,
|
1080
|
+
(t * v0 * v2) - (s * v1), (t * v1 * v2) + (s * v0), (t * v2 * v2) + c, 0,
|
1081
|
+
0, 0, 0, 1);
|
1030
1082
|
}
|
1031
1083
|
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
preApply(1/x, 0, 0, 0,
|
1084
|
+
/**
|
1085
|
+
*
|
1086
|
+
* @param x
|
1087
|
+
* @param y
|
1088
|
+
* @param z
|
1089
|
+
*/
|
1090
|
+
protected void invScale(float x, float y, float z) {
|
1091
|
+
preApply(1 / x, 0, 0, 0, 0, 1 / y, 0, 0, 0, 0, 1 / z, 0, 0, 0, 0, 1);
|
1040
1092
|
}
|
1041
1093
|
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1094
|
+
/**
|
1095
|
+
*
|
1096
|
+
* @param n00
|
1097
|
+
* @param n01
|
1098
|
+
* @param n02
|
1099
|
+
* @param n03
|
1100
|
+
* @param n10
|
1101
|
+
* @param n11
|
1102
|
+
* @param n12
|
1103
|
+
* @param n13
|
1104
|
+
* @param n20
|
1105
|
+
* @param n21
|
1106
|
+
* @param n22
|
1107
|
+
* @param n23
|
1108
|
+
* @param n30
|
1109
|
+
* @param n31
|
1110
|
+
* @param n32
|
1111
|
+
* @param n33
|
1112
|
+
* @return
|
1113
|
+
*/
|
1114
|
+
protected boolean invApply(float n00, float n01, float n02, float n03,
|
1115
|
+
float n10, float n11, float n12, float n13,
|
1116
|
+
float n20, float n21, float n22, float n23,
|
1117
|
+
float n30, float n31, float n32, float n33) {
|
1066
1118
|
if (inverseCopy == null) {
|
1067
1119
|
inverseCopy = new PMatrix3D();
|
1068
1120
|
}
|
1069
1121
|
inverseCopy.set(n00, n01, n02, n03,
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1122
|
+
n10, n11, n12, n13,
|
1123
|
+
n20, n21, n22, n23,
|
1124
|
+
n30, n31, n32, n33);
|
1073
1125
|
if (!inverseCopy.invert()) {
|
1074
1126
|
return false;
|
1075
1127
|
}
|
@@ -1077,77 +1129,72 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
1077
1129
|
return true;
|
1078
1130
|
}
|
1079
1131
|
|
1080
|
-
|
1081
1132
|
//////////////////////////////////////////////////////////////
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
*/
|
1086
|
-
|
1087
|
-
|
1133
|
+
/**
|
1134
|
+
*
|
1135
|
+
*/
|
1088
1136
|
public void print() {
|
1089
1137
|
/*
|
1090
1138
|
System.out.println(m00 + " " + m01 + " " + m02 + " " + m03 + "\n" +
|
1091
1139
|
m10 + " " + m11 + " " + m12 + " " + m13 + "\n" +
|
1092
1140
|
m20 + " " + m21 + " " + m22 + " " + m23 + "\n" +
|
1093
1141
|
m30 + " " + m31 + " " + m32 + " " + m33 + "\n");
|
1094
|
-
|
1142
|
+
*/
|
1095
1143
|
int big = (int) Math.abs(max(max(max(max(abs(m00), abs(m01)),
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1144
|
+
max(abs(m02), abs(m03))),
|
1145
|
+
max(max(abs(m10), abs(m11)),
|
1146
|
+
max(abs(m12), abs(m13)))),
|
1147
|
+
max(max(max(abs(m20), abs(m21)),
|
1148
|
+
max(abs(m22), abs(m23))),
|
1149
|
+
max(max(abs(m30), abs(m31)),
|
1150
|
+
max(abs(m32), abs(m33))))));
|
1103
1151
|
|
1104
1152
|
int digits = 1;
|
1105
1153
|
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
1106
1154
|
digits = 5;
|
1107
1155
|
} else {
|
1108
|
-
while ((big /= 10) != 0)
|
1156
|
+
while ((big /= 10) != 0) {
|
1157
|
+
digits++; // cheap log()
|
1158
|
+
}
|
1109
1159
|
}
|
1110
1160
|
|
1111
|
-
System.out.println(PApplet.nfs(m00, digits, 4) + " "
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1161
|
+
System.out.println(PApplet.nfs(m00, digits, 4) + " "
|
1162
|
+
+ PApplet.nfs(m01, digits, 4) + " "
|
1163
|
+
+ PApplet.nfs(m02, digits, 4) + " "
|
1164
|
+
+ PApplet.nfs(m03, digits, 4));
|
1115
1165
|
|
1116
|
-
System.out.println(PApplet.nfs(m10, digits, 4) + " "
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1166
|
+
System.out.println(PApplet.nfs(m10, digits, 4) + " "
|
1167
|
+
+ PApplet.nfs(m11, digits, 4) + " "
|
1168
|
+
+ PApplet.nfs(m12, digits, 4) + " "
|
1169
|
+
+ PApplet.nfs(m13, digits, 4));
|
1120
1170
|
|
1121
|
-
System.out.println(PApplet.nfs(m20, digits, 4) + " "
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1171
|
+
System.out.println(PApplet.nfs(m20, digits, 4) + " "
|
1172
|
+
+ PApplet.nfs(m21, digits, 4) + " "
|
1173
|
+
+ PApplet.nfs(m22, digits, 4) + " "
|
1174
|
+
+ PApplet.nfs(m23, digits, 4));
|
1125
1175
|
|
1126
|
-
System.out.println(PApplet.nfs(m30, digits, 4) + " "
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1176
|
+
System.out.println(PApplet.nfs(m30, digits, 4) + " "
|
1177
|
+
+ PApplet.nfs(m31, digits, 4) + " "
|
1178
|
+
+ PApplet.nfs(m32, digits, 4) + " "
|
1179
|
+
+ PApplet.nfs(m33, digits, 4));
|
1130
1180
|
|
1131
1181
|
System.out.println();
|
1132
1182
|
}
|
1133
1183
|
|
1134
|
-
|
1135
1184
|
//////////////////////////////////////////////////////////////
|
1136
|
-
|
1137
|
-
|
1138
|
-
static private final float max(float a, float b) {
|
1185
|
+
private static float max(float a, float b) {
|
1139
1186
|
return (a > b) ? a : b;
|
1140
1187
|
}
|
1141
1188
|
|
1142
|
-
|
1189
|
+
private static float abs(float a) {
|
1143
1190
|
return (a < 0) ? -a : a;
|
1144
1191
|
}
|
1145
1192
|
|
1146
|
-
|
1193
|
+
private static float sin(float angle) {
|
1147
1194
|
return (float) Math.sin(angle);
|
1148
1195
|
}
|
1149
1196
|
|
1150
|
-
|
1197
|
+
private static float cos(float angle) {
|
1151
1198
|
return (float) Math.cos(angle);
|
1152
1199
|
}
|
1153
1200
|
}
|