propane 3.4.2-java → 3.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +2 -0
- data/README.md +15 -3
- data/Rakefile +9 -10
- data/bin/propane +3 -1
- data/lib/propane.rb +2 -1
- data/lib/propane/app.rb +2 -1
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +22 -22
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +11 -5
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +2 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +2 -0
- data/pom.rb +46 -45
- data/pom.xml +4 -4
- data/propane.gemspec +8 -7
- data/src/main/java/monkstone/ColorUtil.java +1 -3
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
- data/src/main/java/processing/awt/PImageAWT.java +260 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
- data/src/main/java/processing/awt/ShimAWT.java +580 -0
- data/src/main/java/processing/core/PApplet.java +2877 -2098
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +930 -884
- data/src/main/java/processing/core/PGraphics.java +337 -309
- data/src/main/java/processing/core/PImage.java +1689 -1689
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +456 -410
- data/src/main/java/processing/core/PMatrix3D.java +755 -735
- data/src/main/java/processing/core/PShape.java +2910 -2656
- data/src/main/java/processing/core/PShapeOBJ.java +97 -94
- data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +134 -97
- data/src/main/java/processing/core/PSurfaceNone.java +292 -218
- data/src/main/java/processing/core/PVector.java +991 -966
- data/src/main/java/processing/core/ThinkDifferent.java +12 -8
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3693 -3513
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +954 -880
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +87 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
- data/src/main/java/processing/net/Client.java +20 -20
- data/src/main/java/processing/net/Server.java +9 -9
- data/src/main/java/processing/opengl/FontTexture.java +286 -266
- data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
- data/src/main/java/processing/opengl/LinePath.java +130 -91
- data/src/main/java/processing/opengl/LineStroker.java +593 -582
- data/src/main/java/processing/opengl/PGL.java +645 -579
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
- data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
- data/src/main/java/processing/opengl/PShader.java +345 -416
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
- data/src/main/java/processing/opengl/Texture.java +1489 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +28 -22
- metadata +13 -13
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
1
3
|
/*
|
2
4
|
Part of the Processing project - http://processing.org
|
3
5
|
|
@@ -17,179 +19,190 @@
|
|
17
19
|
Public License along with this library; if not, write to the
|
18
20
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
19
21
|
Boston, MA 02111-1307 USA
|
20
|
-
|
22
|
+
*/
|
23
|
+
|
21
24
|
package processing.core;
|
22
25
|
|
26
|
+
|
23
27
|
/**
|
24
28
|
* A matrix is used to define graphical transformations. PMatrix is the common
|
25
29
|
* interface for both the 2D and 3D matrix classes in Processing. A matrix is a
|
26
30
|
* grid of numbers, which can be multiplied by a vector to give another vector.
|
27
|
-
* Multiplying a point by a particular matrix might translate it, rotate it,
|
28
|
-
* carry out a combination of transformations.
|
31
|
+
* Multiplying a point by a particular matrix might translate it, rotate it,
|
32
|
+
* or carry out a combination of transformations.
|
29
33
|
*
|
30
34
|
* Multiplying matrices by each other combines their effects; use the
|
31
35
|
* {@code apply} and {@code preApply} methods for this.
|
32
36
|
*/
|
33
37
|
public interface PMatrix {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Make this an identity matrix. Multiplying by it will have no effect.
|
41
|
+
*/
|
42
|
+
public void reset();
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Returns a copy of this PMatrix.
|
46
|
+
*/
|
47
|
+
public PMatrix get();
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Copies the matrix contents into a float array.
|
51
|
+
* If target is null (or not the correct size), a new array will be created.
|
52
|
+
*/
|
53
|
+
public float[] get(float[] target);
|
54
|
+
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Make this matrix become a copy of src.
|
58
|
+
*/
|
59
|
+
public void set(PMatrix src);
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Set the contents of this matrix to the contents of source. Fills the
|
63
|
+
* matrix left-to-right, starting in the top row.
|
64
|
+
*/
|
65
|
+
public void set(float[] source);
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Set the matrix content to this 2D matrix or its 3D equivalent.
|
69
|
+
*/
|
70
|
+
public void set(float m00, float m01, float m02,
|
71
|
+
float m10, float m11, float m12);
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Set the matrix content to the 3D matrix supplied, if this matrix is 3D.
|
75
|
+
*/
|
76
|
+
public void set(float m00, float m01, float m02, float m03,
|
77
|
+
float m10, float m11, float m12, float m13,
|
78
|
+
float m20, float m21, float m22, float m23,
|
79
|
+
float m30, float m31, float m32, float m33);
|
80
|
+
|
81
|
+
|
82
|
+
public void translate(float tx, float ty);
|
83
|
+
|
84
|
+
public void translate(float tx, float ty, float tz);
|
85
|
+
|
86
|
+
public void rotate(float angle);
|
87
|
+
|
88
|
+
public void rotateX(float angle);
|
89
|
+
|
90
|
+
public void rotateY(float angle);
|
91
|
+
|
92
|
+
public void rotateZ(float angle);
|
93
|
+
|
94
|
+
public void rotate(float angle, float v0, float v1, float v2);
|
95
|
+
|
96
|
+
public void scale(float s);
|
97
|
+
|
98
|
+
public void scale(float sx, float sy);
|
99
|
+
|
100
|
+
public void scale(float x, float y, float z);
|
101
|
+
|
102
|
+
public void shearX(float angle);
|
103
|
+
|
104
|
+
public void shearY(float angle);
|
105
|
+
|
106
|
+
/**
|
107
|
+
* Multiply this matrix by another.
|
108
|
+
*/
|
109
|
+
public void apply(PMatrix source);
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Multiply this matrix by another.
|
113
|
+
*/
|
114
|
+
public void apply(PMatrix2D source);
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Multiply this matrix by another.
|
118
|
+
*/
|
119
|
+
public void apply(PMatrix3D source);
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Multiply this matrix by another.
|
123
|
+
*/
|
124
|
+
public void apply(float n00, float n01, float n02,
|
125
|
+
float n10, float n11, float n12);
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Multiply this matrix by another.
|
129
|
+
*/
|
130
|
+
public void apply(float n00, float n01, float n02, float n03,
|
131
|
+
float n10, float n11, float n12, float n13,
|
132
|
+
float n20, float n21, float n22, float n23,
|
133
|
+
float n30, float n31, float n32, float n33);
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Apply another matrix to the left of this one.
|
137
|
+
*/
|
138
|
+
public void preApply(PMatrix left);
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Apply another matrix to the left of this one.
|
142
|
+
*/
|
143
|
+
public void preApply(PMatrix2D left);
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Apply another matrix to the left of this one. 3D only.
|
147
|
+
*/
|
148
|
+
public void preApply(PMatrix3D left);
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Apply another matrix to the left of this one.
|
152
|
+
*/
|
153
|
+
public void preApply(float n00, float n01, float n02,
|
154
|
+
float n10, float n11, float n12);
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Apply another matrix to the left of this one. 3D only.
|
158
|
+
*/
|
159
|
+
public void preApply(float n00, float n01, float n02, float n03,
|
160
|
+
float n10, float n11, float n12, float n13,
|
161
|
+
float n20, float n21, float n22, float n23,
|
162
|
+
float n30, float n31, float n32, float n33);
|
163
|
+
|
164
|
+
|
165
|
+
/**
|
166
|
+
* Multiply source by this matrix, and return the result.
|
167
|
+
* The result will be stored in target if target is non-null, and target
|
168
|
+
* will then be the matrix returned. This improves performance if you reuse
|
169
|
+
* target, so it's recommended if you call this many times in draw().
|
170
|
+
*/
|
171
|
+
public PVector mult(PVector source, PVector target);
|
172
|
+
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Multiply a multi-element vector against this matrix.
|
176
|
+
* Supplying and recycling a target array improves performance, so it's
|
177
|
+
* recommended if you call this many times in draw().
|
178
|
+
*/
|
179
|
+
public float[] mult(float[] source, float[] target);
|
180
|
+
|
181
|
+
|
173
182
|
// public float multX(float x, float y);
|
174
183
|
// public float multY(float x, float y);
|
184
|
+
|
175
185
|
// public float multX(float x, float y, float z);
|
176
186
|
// public float multY(float x, float y, float z);
|
177
187
|
// public float multZ(float x, float y, float z);
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
188
|
+
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Transpose this matrix; rows become columns and columns rows.
|
192
|
+
*/
|
193
|
+
public void transpose();
|
194
|
+
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Invert this matrix. Will not necessarily succeed, because some matrices
|
198
|
+
* map more than one point to the same image point, and so are irreversible.
|
199
|
+
* @return true if successful
|
200
|
+
*/
|
201
|
+
public boolean invert();
|
202
|
+
|
203
|
+
|
204
|
+
/**
|
205
|
+
* @return the determinant of the matrix
|
206
|
+
*/
|
207
|
+
public float determinant();
|
195
208
|
}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
1
3
|
/*
|
2
4
|
Part of the Processing project - http://processing.org
|
3
5
|
|
@@ -17,483 +19,527 @@
|
|
17
19
|
Public License along with this library; if not, write to the
|
18
20
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
19
21
|
Boston, MA 02111-1307 USA
|
20
|
-
|
22
|
+
*/
|
23
|
+
|
21
24
|
package processing.core;
|
22
25
|
|
26
|
+
|
23
27
|
/**
|
24
|
-
* 3x2 affine matrix implementation.
|
25
|
-
* transformation; see {@link PMatrix} for a
|
26
|
-
* looks like the following when multiplying
|
28
|
+
* 3x2 affine matrix implementation.
|
29
|
+
* Matrices are used to describe a transformation; see {@link PMatrix} for a
|
30
|
+
* general description. This matrix looks like the following when multiplying
|
31
|
+
* a vector (x, y) in {@code mult()}.
|
27
32
|
* <pre>
|
28
33
|
* [m00 m01 m02][x] [m00*x + m01*y + m02*1] [x']
|
29
34
|
* [m10 m11 m12][y] = [m10*x + m11*y + m12*1] = [y']
|
30
|
-
* [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre>
|
31
|
-
* in the matrix determine the transformation.
|
32
|
-
* transformation functions.
|
35
|
+
* [ 0 0 1 ][1] [ 0*x + 0*y + 1*1 ] [ 1]</pre>
|
36
|
+
* (x', y') is returned. The values in the matrix determine the transformation.
|
37
|
+
* They are modified by the various transformation functions.
|
33
38
|
*/
|
34
39
|
public class PMatrix2D implements PMatrix {
|
35
40
|
|
36
|
-
|
37
|
-
|
41
|
+
public float m00, m01, m02;
|
42
|
+
public float m10, m11, m12;
|
38
43
|
|
39
|
-
/**
|
40
|
-
* Create a new matrix, set to the identity matrix.
|
41
|
-
*/
|
42
|
-
public PMatrix2D() {
|
43
|
-
reset();
|
44
|
-
}
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
/**
|
46
|
+
* Create a new matrix, set to the identity matrix.
|
47
|
+
*/
|
48
|
+
public PMatrix2D() {
|
49
|
+
reset();
|
50
|
+
}
|
51
51
|
|
52
|
-
public PMatrix2D(PMatrix matrix) {
|
53
|
-
set(matrix);
|
54
|
-
}
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
public PMatrix2D(float m00, float m01, float m02,
|
54
|
+
float m10, float m11, float m12) {
|
55
|
+
set(m00, m01, m02,
|
56
|
+
m10, m11, m12);
|
57
|
+
}
|
60
58
|
|
61
|
-
/**
|
62
|
-
* Returns a copy of this PMatrix.
|
63
|
-
*/
|
64
|
-
public PMatrix2D get() {
|
65
|
-
PMatrix2D outgoing = new PMatrix2D();
|
66
|
-
outgoing.set(this);
|
67
|
-
return outgoing;
|
68
|
-
}
|
69
59
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
* order {@code {m00, m01, m02, m10, m11, m12}}.
|
74
|
-
*/
|
75
|
-
public float[] get(float[] target) {
|
76
|
-
if ((target == null) || (target.length != 6)) {
|
77
|
-
target = new float[6];
|
78
|
-
}
|
79
|
-
target[0] = m00;
|
80
|
-
target[1] = m01;
|
81
|
-
target[2] = m02;
|
82
|
-
|
83
|
-
target[3] = m10;
|
84
|
-
target[4] = m11;
|
85
|
-
target[5] = m12;
|
86
|
-
|
87
|
-
return target;
|
88
|
-
}
|
60
|
+
public PMatrix2D(PMatrix matrix) {
|
61
|
+
set(matrix);
|
62
|
+
}
|
89
63
|
|
90
|
-
/**
|
91
|
-
* If matrix is a PMatrix2D, sets this matrix to be a copy of it.
|
92
|
-
*
|
93
|
-
* @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
|
94
|
-
*/
|
95
|
-
public void set(PMatrix matrix) {
|
96
|
-
if (matrix instanceof PMatrix2D) {
|
97
|
-
PMatrix2D src = (PMatrix2D) matrix;
|
98
|
-
set(src.m00, src.m01, src.m02,
|
99
|
-
src.m10, src.m11, src.m12);
|
100
|
-
} else {
|
101
|
-
throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
|
102
|
-
}
|
103
|
-
}
|
104
64
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
65
|
+
public void reset() {
|
66
|
+
set(1, 0, 0,
|
67
|
+
0, 1, 0);
|
68
|
+
}
|
110
69
|
|
111
|
-
public void set(float[] source) {
|
112
|
-
m00 = source[0];
|
113
|
-
m01 = source[1];
|
114
|
-
m02 = source[2];
|
115
70
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
71
|
+
/**
|
72
|
+
* Returns a copy of this PMatrix.
|
73
|
+
*/
|
74
|
+
public PMatrix2D get() {
|
75
|
+
PMatrix2D outgoing = new PMatrix2D();
|
76
|
+
outgoing.set(this);
|
77
|
+
return outgoing;
|
78
|
+
}
|
79
|
+
|
120
80
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
this.m10 = m10;
|
130
|
-
this.m11 = m11;
|
131
|
-
this.m12 = m12;
|
81
|
+
/**
|
82
|
+
* Copies the matrix contents into a 6 entry float array.
|
83
|
+
* If target is null (or not the correct size), a new array will be created.
|
84
|
+
* Returned in the order {@code {m00, m01, m02, m10, m11, m12}}.
|
85
|
+
*/
|
86
|
+
public float[] get(float[] target) {
|
87
|
+
if ((target == null) || (target.length != 6)) {
|
88
|
+
target = new float[6];
|
132
89
|
}
|
90
|
+
target[0] = m00;
|
91
|
+
target[1] = m01;
|
92
|
+
target[2] = m02;
|
133
93
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
public void set(float m00, float m01, float m02, float m03,
|
138
|
-
float m10, float m11, float m12, float m13,
|
139
|
-
float m20, float m21, float m22, float m23,
|
140
|
-
float m30, float m31, float m32, float m33) {
|
94
|
+
target[3] = m10;
|
95
|
+
target[4] = m11;
|
96
|
+
target[5] = m12;
|
141
97
|
|
142
|
-
|
98
|
+
return target;
|
99
|
+
}
|
143
100
|
|
144
|
-
public void translate(float tx, float ty) {
|
145
|
-
m02 = tx * m00 + ty * m01 + m02;
|
146
|
-
m12 = tx * m10 + ty * m11 + m12;
|
147
|
-
}
|
148
101
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
102
|
+
/**
|
103
|
+
* If matrix is a PMatrix2D, sets this matrix to be a copy of it.
|
104
|
+
* @throws IllegalArgumentException If <code>matrix</code> is not 2D.
|
105
|
+
*/
|
106
|
+
public void set(PMatrix matrix) {
|
107
|
+
if (matrix instanceof PMatrix2D) {
|
108
|
+
PMatrix2D src = (PMatrix2D) matrix;
|
109
|
+
set(src.m00, src.m01, src.m02,
|
110
|
+
src.m10, src.m11, src.m12);
|
111
|
+
} else {
|
112
|
+
throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
|
157
113
|
}
|
114
|
+
}
|
158
115
|
|
159
|
-
// Implementation roughly based on AffineTransform.
|
160
|
-
@Override
|
161
|
-
public void rotate(float angle) {
|
162
|
-
float s = sin(angle);
|
163
|
-
float c = cos(angle);
|
164
|
-
|
165
|
-
float temp1 = m00;
|
166
|
-
float temp2 = m01;
|
167
|
-
m00 = c * temp1 + s * temp2;
|
168
|
-
m01 = -s * temp1 + c * temp2;
|
169
|
-
temp1 = m10;
|
170
|
-
temp2 = m11;
|
171
|
-
m10 = c * temp1 + s * temp2;
|
172
|
-
m11 = -s * temp1 + c * temp2;
|
173
|
-
}
|
174
116
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
@Override
|
181
|
-
public void rotateX(float angle) {
|
182
|
-
throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
|
183
|
-
}
|
117
|
+
/**
|
118
|
+
* Unavailable in 2D. Does nothing.
|
119
|
+
*/
|
120
|
+
public void set(PMatrix3D src) {
|
121
|
+
}
|
184
122
|
|
185
|
-
/**
|
186
|
-
* Unavailable in 2D.
|
187
|
-
*
|
188
|
-
* @throws IllegalArgumentException
|
189
|
-
*/
|
190
|
-
public void rotateY(float angle) {
|
191
|
-
throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
|
192
|
-
}
|
193
123
|
|
194
|
-
|
195
|
-
|
196
|
-
|
124
|
+
public void set(float[] source) {
|
125
|
+
m00 = source[0];
|
126
|
+
m01 = source[1];
|
127
|
+
m02 = source[2];
|
197
128
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
*/
|
203
|
-
@Override
|
204
|
-
public void rotate(float angle, float v0, float v1, float v2) {
|
205
|
-
throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
|
206
|
-
}
|
129
|
+
m10 = source[3];
|
130
|
+
m11 = source[4];
|
131
|
+
m12 = source[5];
|
132
|
+
}
|
207
133
|
|
208
|
-
@Override
|
209
|
-
public void scale(float s) {
|
210
|
-
scale(s, s);
|
211
|
-
}
|
212
134
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
135
|
+
/**
|
136
|
+
* Sets the matrix content.
|
137
|
+
*/
|
138
|
+
public void set(float m00, float m01, float m02,
|
139
|
+
float m10, float m11, float m12) {
|
140
|
+
this.m00 = m00; this.m01 = m01; this.m02 = m02;
|
141
|
+
this.m10 = m10; this.m11 = m11; this.m12 = m12;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Unavailable in 2D. Does nothing.
|
147
|
+
*/
|
148
|
+
public void set(float m00, float m01, float m02, float m03,
|
149
|
+
float m10, float m11, float m12, float m13,
|
150
|
+
float m20, float m21, float m22, float m23,
|
151
|
+
float m30, float m31, float m32, float m33) {
|
220
152
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
public void translate(float tx, float ty) {
|
157
|
+
m02 = tx*m00 + ty*m01 + m02;
|
158
|
+
m12 = tx*m10 + ty*m11 + m12;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Unavailable in 2D.
|
164
|
+
* @throws IllegalArgumentException
|
165
|
+
*/
|
166
|
+
public void translate(float x, float y, float z) {
|
167
|
+
throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
|
168
|
+
}
|
229
169
|
|
230
|
-
public void shearX(float angle) {
|
231
|
-
apply(1, 0, 1, tan(angle), 0, 0);
|
232
|
-
}
|
233
170
|
|
234
|
-
|
235
|
-
|
236
|
-
|
171
|
+
// Implementation roughly based on AffineTransform.
|
172
|
+
public void rotate(float angle) {
|
173
|
+
float s = sin(angle);
|
174
|
+
float c = cos(angle);
|
175
|
+
|
176
|
+
float temp1 = m00;
|
177
|
+
float temp2 = m01;
|
178
|
+
m00 = c * temp1 + s * temp2;
|
179
|
+
m01 = -s * temp1 + c * temp2;
|
180
|
+
temp1 = m10;
|
181
|
+
temp2 = m11;
|
182
|
+
m10 = c * temp1 + s * temp2;
|
183
|
+
m11 = -s * temp1 + c * temp2;
|
184
|
+
}
|
237
185
|
|
238
|
-
public void apply(PMatrix source) {
|
239
|
-
if (source instanceof PMatrix2D) {
|
240
|
-
apply((PMatrix2D) source);
|
241
|
-
} else if (source instanceof PMatrix3D) {
|
242
|
-
apply((PMatrix3D) source);
|
243
|
-
}
|
244
|
-
}
|
245
186
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
187
|
+
/**
|
188
|
+
* Unavailable in 2D.
|
189
|
+
* @throws IllegalArgumentException
|
190
|
+
*/
|
191
|
+
public void rotateX(float angle) {
|
192
|
+
throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Unavailable in 2D.
|
198
|
+
* @param angle
|
199
|
+
* @throws IllegalArgumentException
|
200
|
+
*/
|
201
|
+
@Override
|
202
|
+
public void rotateY(float angle) {
|
203
|
+
throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
@Override
|
208
|
+
public void rotateZ(float angle) {
|
209
|
+
rotate(angle);
|
210
|
+
}
|
250
211
|
|
251
|
-
/**
|
252
|
-
* Unavailable in 2D.
|
253
|
-
*
|
254
|
-
* @throws IllegalArgumentException
|
255
|
-
*/
|
256
|
-
public void apply(PMatrix3D source) {
|
257
|
-
throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
|
258
|
-
}
|
259
212
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
213
|
+
/**
|
214
|
+
* Unavailable in 2D.
|
215
|
+
* @throws IllegalArgumentException
|
216
|
+
*/
|
217
|
+
@Override
|
218
|
+
public void rotate(float angle, float v0, float v1, float v2) {
|
219
|
+
throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
@Override
|
224
|
+
public void scale(float s) {
|
225
|
+
scale(s, s);
|
226
|
+
}
|
274
227
|
|
275
|
-
/**
|
276
|
-
* Unavailable in 2D.
|
277
|
-
*
|
278
|
-
* @throws IllegalArgumentException
|
279
|
-
*/
|
280
|
-
public void apply(float n00, float n01, float n02, float n03,
|
281
|
-
float n10, float n11, float n12, float n13,
|
282
|
-
float n20, float n21, float n22, float n23,
|
283
|
-
float n30, float n31, float n32, float n33) {
|
284
|
-
throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
|
285
|
-
}
|
286
228
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
229
|
+
@Override
|
230
|
+
public void scale(float sx, float sy) {
|
231
|
+
m00 *= sx; m01 *= sy;
|
232
|
+
m10 *= sx; m11 *= sy;
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Unavailable in 2D.
|
238
|
+
* @throws IllegalArgumentException
|
239
|
+
*/
|
240
|
+
@Override
|
241
|
+
public void scale(float x, float y, float z) {
|
242
|
+
throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
@Override
|
247
|
+
public void shearX(float angle) {
|
248
|
+
apply(1, 0, 1, tan(angle), 0, 0);
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
@Override
|
253
|
+
public void shearY(float angle) {
|
254
|
+
apply(1, 0, 1, 0, tan(angle), 0);
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
@Override
|
259
|
+
public void apply(PMatrix source) {
|
260
|
+
if (source instanceof PMatrix2D) {
|
261
|
+
apply((PMatrix2D) source);
|
262
|
+
} else if (source instanceof PMatrix3D) {
|
263
|
+
apply((PMatrix3D) source);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
public void apply(PMatrix2D source) {
|
269
|
+
apply(source.m00, source.m01, source.m02,
|
270
|
+
source.m10, source.m11, source.m12);
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Unavailable in 2D.
|
276
|
+
* @throws IllegalArgumentException
|
277
|
+
*/
|
278
|
+
public void apply(PMatrix3D source) {
|
279
|
+
throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
|
280
|
+
}
|
281
|
+
|
282
|
+
|
283
|
+
public void apply(float n00, float n01, float n02,
|
284
|
+
float n10, float n11, float n12) {
|
285
|
+
float t0 = m00;
|
286
|
+
float t1 = m01;
|
287
|
+
m00 = n00 * t0 + n10 * t1;
|
288
|
+
m01 = n01 * t0 + n11 * t1;
|
289
|
+
m02 += n02 * t0 + n12 * t1;
|
290
|
+
|
291
|
+
t0 = m10;
|
292
|
+
t1 = m11;
|
293
|
+
m10 = n00 * t0 + n10 * t1;
|
294
|
+
m11 = n01 * t0 + n11 * t1;
|
295
|
+
m12 += n02 * t0 + n12 * t1;
|
296
|
+
}
|
297
|
+
|
298
|
+
|
299
|
+
/**
|
300
|
+
* Unavailable in 2D.
|
301
|
+
* @throws IllegalArgumentException
|
302
|
+
*/
|
303
|
+
public void apply(float n00, float n01, float n02, float n03,
|
304
|
+
float n10, float n11, float n12, float n13,
|
305
|
+
float n20, float n21, float n22, float n23,
|
306
|
+
float n30, float n31, float n32, float n33) {
|
307
|
+
throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
|
308
|
+
}
|
297
309
|
|
298
|
-
public void preApply(PMatrix2D left) {
|
299
|
-
preApply(left.m00, left.m01, left.m02,
|
300
|
-
left.m10, left.m11, left.m12);
|
301
|
-
}
|
302
310
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
311
|
+
/**
|
312
|
+
* Apply another matrix to the left of this one.
|
313
|
+
*/
|
314
|
+
public void preApply(PMatrix source) {
|
315
|
+
if (source instanceof PMatrix2D) {
|
316
|
+
preApply((PMatrix2D) source);
|
317
|
+
} else if (source instanceof PMatrix3D) {
|
318
|
+
preApply((PMatrix3D) source);
|
310
319
|
}
|
320
|
+
}
|
311
321
|
|
312
|
-
public void preApply(float n00, float n01, float n02,
|
313
|
-
float n10, float n11, float n12) {
|
314
|
-
float t0 = m02;
|
315
|
-
float t1 = m12;
|
316
|
-
n02 += t0 * n00 + t1 * n01;
|
317
|
-
n12 += t0 * n10 + t1 * n11;
|
318
|
-
|
319
|
-
m02 = n02;
|
320
|
-
m12 = n12;
|
321
|
-
|
322
|
-
t0 = m00;
|
323
|
-
t1 = m10;
|
324
|
-
m00 = t0 * n00 + t1 * n01;
|
325
|
-
m10 = t0 * n10 + t1 * n11;
|
326
|
-
|
327
|
-
t0 = m01;
|
328
|
-
t1 = m11;
|
329
|
-
m01 = t0 * n00 + t1 * n01;
|
330
|
-
m11 = t0 * n10 + t1 * n11;
|
331
|
-
}
|
332
322
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
*/
|
338
|
-
public void preApply(float n00, float n01, float n02, float n03,
|
339
|
-
float n10, float n11, float n12, float n13,
|
340
|
-
float n20, float n21, float n22, float n23,
|
341
|
-
float n30, float n31, float n32, float n33) {
|
342
|
-
throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
|
343
|
-
}
|
323
|
+
public void preApply(PMatrix2D left) {
|
324
|
+
preApply(left.m00, left.m01, left.m02,
|
325
|
+
left.m10, left.m11, left.m12);
|
326
|
+
}
|
344
327
|
|
345
|
-
//////////////////////////////////////////////////////////////
|
346
|
-
/**
|
347
|
-
* {@inheritDoc} Ignores any z component.
|
348
|
-
*/
|
349
|
-
public PVector mult(PVector source, PVector target) {
|
350
|
-
if (target == null) {
|
351
|
-
target = new PVector();
|
352
|
-
}
|
353
|
-
target.x = m00 * source.x + m01 * source.y + m02;
|
354
|
-
target.y = m10 * source.x + m11 * source.y + m12;
|
355
|
-
return target;
|
356
|
-
}
|
357
328
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
329
|
+
/**
|
330
|
+
* Unavailable in 2D.
|
331
|
+
* @throws IllegalArgumentException
|
332
|
+
*/
|
333
|
+
public void preApply(PMatrix3D left) {
|
334
|
+
throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
public void preApply(float n00, float n01, float n02,
|
339
|
+
float n10, float n11, float n12) {
|
340
|
+
float t0 = m02;
|
341
|
+
float t1 = m12;
|
342
|
+
n02 += t0 * n00 + t1 * n01;
|
343
|
+
n12 += t0 * n10 + t1 * n11;
|
344
|
+
|
345
|
+
m02 = n02;
|
346
|
+
m12 = n12;
|
347
|
+
|
348
|
+
t0 = m00;
|
349
|
+
t1 = m10;
|
350
|
+
m00 = t0 * n00 + t1 * n01;
|
351
|
+
m10 = t0 * n10 + t1 * n11;
|
352
|
+
|
353
|
+
t0 = m01;
|
354
|
+
t1 = m11;
|
355
|
+
m01 = t0 * n00 + t1 * n01;
|
356
|
+
m11 = t0 * n10 + t1 * n11;
|
357
|
+
}
|
382
358
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Unavailable in 2D.
|
362
|
+
* @throws IllegalArgumentException
|
363
|
+
*/
|
364
|
+
public void preApply(float n00, float n01, float n02, float n03,
|
365
|
+
float n10, float n11, float n12, float n13,
|
366
|
+
float n20, float n21, float n22, float n23,
|
367
|
+
float n30, float n31, float n32, float n33) {
|
368
|
+
throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
//////////////////////////////////////////////////////////////
|
373
|
+
|
374
|
+
|
375
|
+
/**
|
376
|
+
* {@inheritDoc}
|
377
|
+
* Ignores any z component.
|
378
|
+
*/
|
379
|
+
public PVector mult(PVector source, PVector target) {
|
380
|
+
if (target == null) {
|
381
|
+
target = new PVector();
|
389
382
|
}
|
383
|
+
target.x = m00*source.x + m01*source.y + m02;
|
384
|
+
target.y = m10*source.x + m11*source.y + m12;
|
385
|
+
return target;
|
386
|
+
}
|
387
|
+
|
390
388
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
389
|
+
/**
|
390
|
+
* Multiply a two element vector against this matrix.
|
391
|
+
* If out is null or not length four, a new float array will be returned.
|
392
|
+
* The values for vec and out can be the same (though that's less efficient).
|
393
|
+
*/
|
394
|
+
public float[] mult(float[] vec, float[] out) {
|
395
|
+
if (out == null || out.length != 2) {
|
396
|
+
out = new float[2];
|
397
397
|
}
|
398
398
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
399
|
+
if (vec == out) {
|
400
|
+
float tx = m00*vec[0] + m01*vec[1] + m02;
|
401
|
+
float ty = m10*vec[0] + m11*vec[1] + m12;
|
402
|
+
|
403
|
+
out[0] = tx;
|
404
|
+
out[1] = ty;
|
405
|
+
|
406
|
+
} else {
|
407
|
+
out[0] = m00*vec[0] + m01*vec[1] + m02;
|
408
|
+
out[1] = m10*vec[0] + m11*vec[1] + m12;
|
403
409
|
}
|
404
410
|
|
411
|
+
return out;
|
412
|
+
}
|
413
|
+
|
414
|
+
|
415
|
+
/**
|
416
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y)
|
417
|
+
* by this matrix.
|
418
|
+
*/
|
419
|
+
public float multX(float x, float y) {
|
420
|
+
return m00*x + m01*y + m02;
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
/**
|
425
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y)
|
426
|
+
* by this matrix.
|
427
|
+
*/
|
428
|
+
public float multY(float x, float y) {
|
429
|
+
return m10*x + m11*y + m12;
|
430
|
+
}
|
405
431
|
|
406
|
-
|
432
|
+
|
433
|
+
|
434
|
+
/**
|
435
|
+
* Unavailable in 2D. Does nothing.
|
436
|
+
*/
|
437
|
+
public void transpose() {
|
438
|
+
}
|
439
|
+
|
440
|
+
|
441
|
+
/*
|
407
442
|
* Implementation stolen from OpenJDK.
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
float t00 = m00;
|
416
|
-
float t01 = m01;
|
417
|
-
float t02 = m02;
|
418
|
-
float t10 = m10;
|
419
|
-
float t11 = m11;
|
420
|
-
float t12 = m12;
|
421
|
-
|
422
|
-
m00 = t11 / determinant;
|
423
|
-
m10 = -t10 / determinant;
|
424
|
-
m01 = -t01 / determinant;
|
425
|
-
m11 = t00 / determinant;
|
426
|
-
m02 = (t01 * t12 - t11 * t02) / determinant;
|
427
|
-
m12 = (t10 * t02 - t00 * t12) / determinant;
|
428
|
-
|
429
|
-
return true;
|
443
|
+
*/
|
444
|
+
public boolean invert() {
|
445
|
+
float determinant = determinant();
|
446
|
+
if (Math.abs(determinant) <= Float.MIN_VALUE) {
|
447
|
+
return false;
|
430
448
|
}
|
431
449
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
450
|
+
float t00 = m00;
|
451
|
+
float t01 = m01;
|
452
|
+
float t02 = m02;
|
453
|
+
float t10 = m10;
|
454
|
+
float t11 = m11;
|
455
|
+
float t12 = m12;
|
438
456
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
446
|
-
digits = 5;
|
447
|
-
} else {
|
448
|
-
while ((big /= 10) != 0) {
|
449
|
-
digits++; // cheap log()
|
450
|
-
}
|
451
|
-
}
|
452
|
-
|
453
|
-
System.out.println(PApplet.nfs(m00, digits, 4) + " "
|
454
|
-
+ PApplet.nfs(m01, digits, 4) + " "
|
455
|
-
+ PApplet.nfs(m02, digits, 4));
|
456
|
-
|
457
|
-
System.out.println(PApplet.nfs(m10, digits, 4) + " "
|
458
|
-
+ PApplet.nfs(m11, digits, 4) + " "
|
459
|
-
+ PApplet.nfs(m12, digits, 4));
|
460
|
-
|
461
|
-
System.out.println();
|
462
|
-
}
|
457
|
+
m00 = t11 / determinant;
|
458
|
+
m10 = -t10 / determinant;
|
459
|
+
m01 = -t01 / determinant;
|
460
|
+
m11 = t00 / determinant;
|
461
|
+
m02 = (t01 * t12 - t11 * t02) / determinant;
|
462
|
+
m12 = (t10 * t02 - t00 * t12) / determinant;
|
463
463
|
|
464
|
-
|
465
|
-
|
466
|
-
// implementation needs to be improved first. (e.g. actually keeping track
|
467
|
-
// of whether the matrix is in fact identity internally.)
|
468
|
-
protected boolean isIdentity() {
|
469
|
-
return ((m00 == 1) && (m01 == 0) && (m02 == 0)
|
470
|
-
&& (m10 == 0) && (m11 == 1) && (m12 == 0));
|
471
|
-
}
|
464
|
+
return true;
|
465
|
+
}
|
472
466
|
|
473
|
-
// TODO make this more efficient, or move into PMatrix2D
|
474
|
-
protected boolean isWarped() {
|
475
|
-
return ((m00 != 1) || (m01 != 0)
|
476
|
-
&& (m10 != 0) || (m11 != 1));
|
477
|
-
}
|
478
467
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
468
|
+
/**
|
469
|
+
* @return the determinant of the matrix
|
470
|
+
*/
|
471
|
+
@Override
|
472
|
+
public float determinant() {
|
473
|
+
return m00 * m11 - m01 * m10;
|
474
|
+
}
|
483
475
|
|
484
|
-
static private final float abs(float a) {
|
485
|
-
return (a < 0) ? -a : a;
|
486
|
-
}
|
487
476
|
|
488
|
-
|
489
|
-
return (float) Math.sin(angle);
|
490
|
-
}
|
477
|
+
//////////////////////////////////////////////////////////////
|
491
478
|
|
492
|
-
static private final float cos(float angle) {
|
493
|
-
return (float) Math.cos(angle);
|
494
|
-
}
|
495
479
|
|
496
|
-
|
497
|
-
|
480
|
+
public void print() {
|
481
|
+
int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
|
482
|
+
PApplet.max(abs(m10), abs(m11), abs(m12))));
|
483
|
+
|
484
|
+
int digits = 1;
|
485
|
+
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
486
|
+
digits = 5;
|
487
|
+
} else {
|
488
|
+
while ((big /= 10) != 0) digits++; // cheap log()
|
498
489
|
}
|
490
|
+
|
491
|
+
System.out.println(PApplet.nfs(m00, digits, 4) + " " +
|
492
|
+
PApplet.nfs(m01, digits, 4) + " " +
|
493
|
+
PApplet.nfs(m02, digits, 4));
|
494
|
+
|
495
|
+
System.out.println(PApplet.nfs(m10, digits, 4) + " " +
|
496
|
+
PApplet.nfs(m11, digits, 4) + " " +
|
497
|
+
PApplet.nfs(m12, digits, 4));
|
498
|
+
|
499
|
+
System.out.println();
|
500
|
+
}
|
501
|
+
|
502
|
+
|
503
|
+
//////////////////////////////////////////////////////////////
|
504
|
+
|
505
|
+
// TODO these need to be added as regular API, but the naming and
|
506
|
+
// implementation needs to be improved first. (e.g. actually keeping track
|
507
|
+
// of whether the matrix is in fact identity internally.)
|
508
|
+
|
509
|
+
|
510
|
+
protected boolean isIdentity() {
|
511
|
+
return ((m00 == 1) && (m01 == 0) && (m02 == 0) &&
|
512
|
+
(m10 == 0) && (m11 == 1) && (m12 == 0));
|
513
|
+
}
|
514
|
+
|
515
|
+
|
516
|
+
// TODO make this more efficient, or move into PMatrix2D
|
517
|
+
protected boolean isWarped() {
|
518
|
+
return ((m00 != 1) || (m01 != 0) &&
|
519
|
+
(m10 != 0) || (m11 != 1));
|
520
|
+
}
|
521
|
+
|
522
|
+
|
523
|
+
//////////////////////////////////////////////////////////////
|
524
|
+
|
525
|
+
|
526
|
+
static private final float max(float a, float b) {
|
527
|
+
return (a > b) ? a : b;
|
528
|
+
}
|
529
|
+
|
530
|
+
static private final float abs(float a) {
|
531
|
+
return (a < 0) ? -a : a;
|
532
|
+
}
|
533
|
+
|
534
|
+
static private final float sin(float angle) {
|
535
|
+
return (float)Math.sin(angle);
|
536
|
+
}
|
537
|
+
|
538
|
+
static private final float cos(float angle) {
|
539
|
+
return (float)Math.cos(angle);
|
540
|
+
}
|
541
|
+
|
542
|
+
static private final float tan(float angle) {
|
543
|
+
return (float)Math.tan(angle);
|
544
|
+
}
|
499
545
|
}
|