picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,347 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
3
|
+
/*
|
4
|
+
Part of the Processing project - http://processing.org
|
5
|
+
|
6
|
+
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
7
|
+
|
8
|
+
This library is free software; you can redistribute it and/or
|
9
|
+
modify it under the terms of the GNU Lesser General Public
|
10
|
+
License as published by the Free Software Foundation; either
|
11
|
+
version 2.1 of the License, or (at your option) any later version.
|
12
|
+
|
13
|
+
This library is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General
|
19
|
+
Public License along with this library; if not, write to the
|
20
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
21
|
+
Boston, MA 02111-1307 USA
|
22
|
+
*/
|
23
|
+
|
24
|
+
package processing.core;
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
28
|
+
* A matrix is used to define graphical transformations. PMatrix is the common
|
29
|
+
* interface for both the 2D and 3D matrix classes in Processing. A matrix is a
|
30
|
+
* grid of numbers, which can be multiplied by a vector to give another vector.
|
31
|
+
* Multiplying a point by a particular matrix might translate it, rotate it,
|
32
|
+
* or carry out a combination of transformations.
|
33
|
+
*
|
34
|
+
* Multiplying matrices by each other combines their effects; use the
|
35
|
+
* {@code apply} and {@code preApply} methods for this.
|
36
|
+
*/
|
37
|
+
public interface PMatrix {
|
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
|
+
* @return
|
47
|
+
*/
|
48
|
+
public PMatrix get();
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Copies the matrix contents into a float array.
|
52
|
+
* If target is null (or not the correct size), a new array will be created.
|
53
|
+
* @param target
|
54
|
+
* @return
|
55
|
+
*/
|
56
|
+
public float[] get(float[] target);
|
57
|
+
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Make this matrix become a copy of src.
|
61
|
+
* @param src
|
62
|
+
*/
|
63
|
+
public void set(PMatrix src);
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Set the contents of this matrix to the contents of source. Fills the
|
67
|
+
* matrix left-to-right, starting in the top row.
|
68
|
+
* @param source
|
69
|
+
*/
|
70
|
+
public void set(float[] source);
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Set the matrix content to this 2D matrix or its 3D equivalent.
|
74
|
+
* @param m00
|
75
|
+
* @param m01
|
76
|
+
* @param m10
|
77
|
+
* @param m02
|
78
|
+
* @param m12
|
79
|
+
* @param m11
|
80
|
+
*/
|
81
|
+
public void set(float m00, float m01, float m02,
|
82
|
+
float m10, float m11, float m12);
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Set the matrix content to the 3D matrix supplied, if this matrix is 3D.
|
86
|
+
* @param m00
|
87
|
+
* @param m01
|
88
|
+
* @param m20
|
89
|
+
* @param m02
|
90
|
+
* @param m03
|
91
|
+
* @param m10
|
92
|
+
* @param m12
|
93
|
+
* @param m11
|
94
|
+
* @param m22
|
95
|
+
* @param m33
|
96
|
+
* @param m13
|
97
|
+
* @param m23
|
98
|
+
* @param m30
|
99
|
+
* @param m31
|
100
|
+
* @param m21
|
101
|
+
* @param m32
|
102
|
+
*/
|
103
|
+
public void set(float m00, float m01, float m02, float m03,
|
104
|
+
float m10, float m11, float m12, float m13,
|
105
|
+
float m20, float m21, float m22, float m23,
|
106
|
+
float m30, float m31, float m32, float m33);
|
107
|
+
|
108
|
+
/**
|
109
|
+
*
|
110
|
+
* @param tx
|
111
|
+
* @param ty
|
112
|
+
*/
|
113
|
+
public void translate(float tx, float ty);
|
114
|
+
|
115
|
+
/**
|
116
|
+
*
|
117
|
+
* @param tx
|
118
|
+
* @param ty
|
119
|
+
* @param tz
|
120
|
+
*/
|
121
|
+
public void translate(float tx, float ty, float tz);
|
122
|
+
|
123
|
+
/**
|
124
|
+
*
|
125
|
+
* @param angle
|
126
|
+
*/
|
127
|
+
public void rotate(float angle);
|
128
|
+
|
129
|
+
/**
|
130
|
+
*
|
131
|
+
* @param angle
|
132
|
+
*/
|
133
|
+
public void rotateX(float angle);
|
134
|
+
|
135
|
+
/**
|
136
|
+
*
|
137
|
+
* @param angle
|
138
|
+
*/
|
139
|
+
public void rotateY(float angle);
|
140
|
+
|
141
|
+
/**
|
142
|
+
*
|
143
|
+
* @param angle
|
144
|
+
*/
|
145
|
+
public void rotateZ(float angle);
|
146
|
+
|
147
|
+
/**
|
148
|
+
*
|
149
|
+
* @param angle
|
150
|
+
* @param v0
|
151
|
+
* @param v1
|
152
|
+
* @param v2
|
153
|
+
*/
|
154
|
+
public void rotate(float angle, float v0, float v1, float v2);
|
155
|
+
|
156
|
+
/**
|
157
|
+
*
|
158
|
+
* @param s
|
159
|
+
*/
|
160
|
+
public void scale(float s);
|
161
|
+
|
162
|
+
/**
|
163
|
+
*
|
164
|
+
* @param sx
|
165
|
+
* @param sy
|
166
|
+
*/
|
167
|
+
public void scale(float sx, float sy);
|
168
|
+
|
169
|
+
/**
|
170
|
+
*
|
171
|
+
* @param x
|
172
|
+
* @param y
|
173
|
+
* @param z
|
174
|
+
*/
|
175
|
+
public void scale(float x, float y, float z);
|
176
|
+
|
177
|
+
/**
|
178
|
+
*
|
179
|
+
* @param angle
|
180
|
+
*/
|
181
|
+
public void shearX(float angle);
|
182
|
+
|
183
|
+
/**
|
184
|
+
*
|
185
|
+
* @param angle
|
186
|
+
*/
|
187
|
+
public void shearY(float angle);
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Multiply this matrix by another.
|
191
|
+
* @param source
|
192
|
+
*/
|
193
|
+
public void apply(PMatrix source);
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Multiply this matrix by another.
|
197
|
+
* @param source
|
198
|
+
*/
|
199
|
+
public void apply(PMatrix2D source);
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Multiply this matrix by another.
|
203
|
+
* @param source
|
204
|
+
*/
|
205
|
+
public void apply(PMatrix3D source);
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Multiply this matrix by another.
|
209
|
+
* @param n00
|
210
|
+
* @param n11
|
211
|
+
* @param n02
|
212
|
+
* @param n10
|
213
|
+
* @param n01
|
214
|
+
* @param n12
|
215
|
+
*/
|
216
|
+
public void apply(float n00, float n01, float n02,
|
217
|
+
float n10, float n11, float n12);
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Multiply this matrix by another.
|
221
|
+
* @param n00
|
222
|
+
* @param n32
|
223
|
+
* @param n02
|
224
|
+
* @param n01
|
225
|
+
* @param n21
|
226
|
+
* @param n10
|
227
|
+
* @param n03
|
228
|
+
* @param n11
|
229
|
+
* @param n13
|
230
|
+
* @param n23
|
231
|
+
* @param n22
|
232
|
+
* @param n20
|
233
|
+
* @param n12
|
234
|
+
* @param n31
|
235
|
+
* @param n30
|
236
|
+
* @param n33
|
237
|
+
*/
|
238
|
+
public void apply(float n00, float n01, float n02, float n03,
|
239
|
+
float n10, float n11, float n12, float n13,
|
240
|
+
float n20, float n21, float n22, float n23,
|
241
|
+
float n30, float n31, float n32, float n33);
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Apply another matrix to the left of this one.
|
245
|
+
* @param left
|
246
|
+
*/
|
247
|
+
public void preApply(PMatrix left);
|
248
|
+
|
249
|
+
/**
|
250
|
+
* Apply another matrix to the left of this one.
|
251
|
+
* @param left
|
252
|
+
*/
|
253
|
+
public void preApply(PMatrix2D left);
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Apply another matrix to the left of this one. 3D only.
|
257
|
+
* @param left
|
258
|
+
*/
|
259
|
+
public void preApply(PMatrix3D left);
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Apply another matrix to the left of this one.
|
263
|
+
* @param n00
|
264
|
+
* @param n12
|
265
|
+
* @param n02
|
266
|
+
* @param n10
|
267
|
+
* @param n01
|
268
|
+
* @param n11
|
269
|
+
*/
|
270
|
+
public void preApply(float n00, float n01, float n02,
|
271
|
+
float n10, float n11, float n12);
|
272
|
+
|
273
|
+
/**
|
274
|
+
* Apply another matrix to the left of this one. 3D only.
|
275
|
+
* @param n00
|
276
|
+
* @param n10
|
277
|
+
* @param n02
|
278
|
+
* @param n01
|
279
|
+
* @param n33
|
280
|
+
* @param n13
|
281
|
+
* @param n11
|
282
|
+
* @param n03
|
283
|
+
* @param n20
|
284
|
+
* @param n21
|
285
|
+
* @param n12
|
286
|
+
* @param n30
|
287
|
+
* @param n23
|
288
|
+
* @param n22
|
289
|
+
* @param n32
|
290
|
+
* @param n31
|
291
|
+
*/
|
292
|
+
public void preApply(float n00, float n01, float n02, float n03,
|
293
|
+
float n10, float n11, float n12, float n13,
|
294
|
+
float n20, float n21, float n22, float n23,
|
295
|
+
float n30, float n31, float n32, float n33);
|
296
|
+
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Multiply source by this matrix, and return the result.
|
300
|
+
* The result will be stored in target if target is non-null, and target
|
301
|
+
* will then be the matrix returned. This improves performance if you reuse
|
302
|
+
* target, so it's recommended if you call this many times in draw().
|
303
|
+
* @param source
|
304
|
+
* @param target
|
305
|
+
* @return
|
306
|
+
*/
|
307
|
+
public PVector mult(PVector source, PVector target);
|
308
|
+
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Multiply a multi-element vector against this matrix.
|
312
|
+
* Supplying and recycling a target array improves performance, so it's
|
313
|
+
* recommended if you call this many times in draw().
|
314
|
+
* @param source
|
315
|
+
* @param target
|
316
|
+
* @return
|
317
|
+
*/
|
318
|
+
public float[] mult(float[] source, float[] target);
|
319
|
+
|
320
|
+
|
321
|
+
// public float multX(float x, float y);
|
322
|
+
// public float multY(float x, float y);
|
323
|
+
|
324
|
+
// public float multX(float x, float y, float z);
|
325
|
+
// public float multY(float x, float y, float z);
|
326
|
+
// public float multZ(float x, float y, float z);
|
327
|
+
|
328
|
+
|
329
|
+
/**
|
330
|
+
* Transpose this matrix; rows become columns and columns rows.
|
331
|
+
*/
|
332
|
+
public void transpose();
|
333
|
+
|
334
|
+
|
335
|
+
/**
|
336
|
+
* Invert this matrix. Will not necessarily succeed, because some matrices
|
337
|
+
* map more than one point to the same image point, and so are irreversible.
|
338
|
+
* @return true if successful
|
339
|
+
*/
|
340
|
+
public boolean invert();
|
341
|
+
|
342
|
+
|
343
|
+
/**
|
344
|
+
* @return the determinant of the matrix
|
345
|
+
*/
|
346
|
+
public float determinant();
|
347
|
+
}
|
@@ -0,0 +1,694 @@
|
|
1
|
+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
|
+
|
3
|
+
/*
|
4
|
+
Part of the Processing project - http://processing.org
|
5
|
+
|
6
|
+
Copyright (c) 2005-08 Ben Fry and Casey Reas
|
7
|
+
|
8
|
+
This library is free software; you can redistribute it and/or
|
9
|
+
modify it under the terms of the GNU Lesser General Public
|
10
|
+
License as published by the Free Software Foundation; either
|
11
|
+
version 2.1 of the License, or (at your option) any later version.
|
12
|
+
|
13
|
+
This library is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General
|
19
|
+
Public License along with this library; if not, write to the
|
20
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
21
|
+
Boston, MA 02111-1307 USA
|
22
|
+
*/
|
23
|
+
|
24
|
+
package processing.core;
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
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()}.
|
32
|
+
* <pre>
|
33
|
+
* [m00 m01 m02][x] [m00*x + m01*y + m02*1] [x']
|
34
|
+
* [m10 m11 m12][y] = [m10*x + m11*y + m12*1] = [y']
|
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.
|
38
|
+
*/
|
39
|
+
public class PMatrix2D implements PMatrix {
|
40
|
+
|
41
|
+
/**
|
42
|
+
*
|
43
|
+
*/
|
44
|
+
public float m00,
|
45
|
+
|
46
|
+
/**
|
47
|
+
*
|
48
|
+
*/
|
49
|
+
m01,
|
50
|
+
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
*/
|
54
|
+
m02;
|
55
|
+
|
56
|
+
/**
|
57
|
+
*
|
58
|
+
*/
|
59
|
+
public float m10,
|
60
|
+
|
61
|
+
/**
|
62
|
+
*
|
63
|
+
*/
|
64
|
+
m11,
|
65
|
+
|
66
|
+
/**
|
67
|
+
*
|
68
|
+
*/
|
69
|
+
m12;
|
70
|
+
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Create a new matrix, set to the identity matrix.
|
74
|
+
*/
|
75
|
+
public PMatrix2D() {
|
76
|
+
reset();
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
*
|
81
|
+
* @param m00
|
82
|
+
* @param m01
|
83
|
+
* @param m02
|
84
|
+
* @param m10
|
85
|
+
* @param m11
|
86
|
+
* @param m12
|
87
|
+
*/
|
88
|
+
public PMatrix2D(float m00, float m01, float m02,
|
89
|
+
float m10, float m11, float m12) {
|
90
|
+
set(m00, m01, m02,
|
91
|
+
m10, m11, m12);
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
*
|
96
|
+
* @param matrix
|
97
|
+
*/
|
98
|
+
public PMatrix2D(PMatrix matrix) {
|
99
|
+
set(matrix);
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
public void reset() {
|
104
|
+
set(1, 0, 0,
|
105
|
+
0, 1, 0);
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Returns a copy of this PMatrix.
|
111
|
+
* @return
|
112
|
+
*/
|
113
|
+
public PMatrix2D get() {
|
114
|
+
PMatrix2D outgoing = new PMatrix2D();
|
115
|
+
outgoing.set(this);
|
116
|
+
return outgoing;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Copies the matrix contents into a 6 entry float array.
|
122
|
+
* If target is null (or not the correct size), a new array will be created.
|
123
|
+
* Returned in the order {@code {m00, m01, m02, m10, m11, m12}}.
|
124
|
+
* @param target
|
125
|
+
* @return
|
126
|
+
*/
|
127
|
+
public float[] get(float[] target) {
|
128
|
+
if ((target == null) || (target.length != 6)) {
|
129
|
+
target = new float[6];
|
130
|
+
}
|
131
|
+
target[0] = m00;
|
132
|
+
target[1] = m01;
|
133
|
+
target[2] = m02;
|
134
|
+
|
135
|
+
target[3] = m10;
|
136
|
+
target[4] = m11;
|
137
|
+
target[5] = m12;
|
138
|
+
|
139
|
+
return target;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/**
|
144
|
+
* If matrix is a PMatrix2D, sets this matrix to be a copy of it.
|
145
|
+
* @param matrix
|
146
|
+
* @throws IllegalArgumentException If <tt>matrix</tt> is not 2D.
|
147
|
+
*/
|
148
|
+
public void set(PMatrix matrix) {
|
149
|
+
if (matrix instanceof PMatrix2D) {
|
150
|
+
PMatrix2D src = (PMatrix2D) matrix;
|
151
|
+
set(src.m00, src.m01, src.m02,
|
152
|
+
src.m10, src.m11, src.m12);
|
153
|
+
} else {
|
154
|
+
throw new IllegalArgumentException("PMatrix2D.set() only accepts PMatrix2D objects.");
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Unavailable in 2D. Does nothing.
|
161
|
+
* @param src
|
162
|
+
*/
|
163
|
+
public void set(PMatrix3D src) {
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
public void set(float[] source) {
|
168
|
+
m00 = source[0];
|
169
|
+
m01 = source[1];
|
170
|
+
m02 = source[2];
|
171
|
+
|
172
|
+
m10 = source[3];
|
173
|
+
m11 = source[4];
|
174
|
+
m12 = source[5];
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Sets the matrix content.
|
180
|
+
* @param m00
|
181
|
+
* @param m01
|
182
|
+
* @param m02
|
183
|
+
* @param m11
|
184
|
+
* @param m10
|
185
|
+
* @param m12
|
186
|
+
*/
|
187
|
+
public void set(float m00, float m01, float m02,
|
188
|
+
float m10, float m11, float m12) {
|
189
|
+
this.m00 = m00; this.m01 = m01; this.m02 = m02;
|
190
|
+
this.m10 = m10; this.m11 = m11; this.m12 = m12;
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Unavailable in 2D. Does nothing.
|
196
|
+
* @param m00
|
197
|
+
* @param m23
|
198
|
+
* @param m02
|
199
|
+
* @param m01
|
200
|
+
* @param m10
|
201
|
+
* @param m12
|
202
|
+
* @param m03
|
203
|
+
* @param m11
|
204
|
+
* @param m20
|
205
|
+
* @param m21
|
206
|
+
* @param m13
|
207
|
+
* @param m31
|
208
|
+
* @param m33
|
209
|
+
* @param m22
|
210
|
+
* @param m30
|
211
|
+
* @param m32
|
212
|
+
*/
|
213
|
+
public void set(float m00, float m01, float m02, float m03,
|
214
|
+
float m10, float m11, float m12, float m13,
|
215
|
+
float m20, float m21, float m22, float m23,
|
216
|
+
float m30, float m31, float m32, float m33) {
|
217
|
+
|
218
|
+
}
|
219
|
+
|
220
|
+
/**
|
221
|
+
*
|
222
|
+
* @param tx
|
223
|
+
* @param ty
|
224
|
+
*/
|
225
|
+
public void translate(float tx, float ty) {
|
226
|
+
m02 = tx*m00 + ty*m01 + m02;
|
227
|
+
m12 = tx*m10 + ty*m11 + m12;
|
228
|
+
}
|
229
|
+
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Unavailable in 2D.
|
233
|
+
* @param x
|
234
|
+
* @param y
|
235
|
+
* @param z
|
236
|
+
* @throws IllegalArgumentException
|
237
|
+
*/
|
238
|
+
public void translate(float x, float y, float z) {
|
239
|
+
throw new IllegalArgumentException("Cannot use translate(x, y, z) on a PMatrix2D.");
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
// Implementation roughly based on AffineTransform.
|
244
|
+
|
245
|
+
/**
|
246
|
+
*
|
247
|
+
* @param angle
|
248
|
+
*/
|
249
|
+
public void rotate(float angle) {
|
250
|
+
float s = sin(angle);
|
251
|
+
float c = cos(angle);
|
252
|
+
|
253
|
+
float temp1 = m00;
|
254
|
+
float temp2 = m01;
|
255
|
+
m00 = c * temp1 + s * temp2;
|
256
|
+
m01 = -s * temp1 + c * temp2;
|
257
|
+
temp1 = m10;
|
258
|
+
temp2 = m11;
|
259
|
+
m10 = c * temp1 + s * temp2;
|
260
|
+
m11 = -s * temp1 + c * temp2;
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Unavailable in 2D.
|
266
|
+
* @param angle
|
267
|
+
* @throws IllegalArgumentException
|
268
|
+
*/
|
269
|
+
public void rotateX(float angle) {
|
270
|
+
throw new IllegalArgumentException("Cannot use rotateX() on a PMatrix2D.");
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
/**
|
275
|
+
* Unavailable in 2D.
|
276
|
+
* @param angle
|
277
|
+
* @throws IllegalArgumentException
|
278
|
+
*/
|
279
|
+
public void rotateY(float angle) {
|
280
|
+
throw new IllegalArgumentException("Cannot use rotateY() on a PMatrix2D.");
|
281
|
+
}
|
282
|
+
|
283
|
+
/**
|
284
|
+
*
|
285
|
+
* @param angle
|
286
|
+
*/
|
287
|
+
public void rotateZ(float angle) {
|
288
|
+
rotate(angle);
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
/**
|
293
|
+
* Unavailable in 2D.
|
294
|
+
* @param angle
|
295
|
+
* @param v0
|
296
|
+
* @param v1
|
297
|
+
* @param v2
|
298
|
+
* @throws IllegalArgumentException
|
299
|
+
*/
|
300
|
+
public void rotate(float angle, float v0, float v1, float v2) {
|
301
|
+
throw new IllegalArgumentException("Cannot use this version of rotate() on a PMatrix2D.");
|
302
|
+
}
|
303
|
+
|
304
|
+
/**
|
305
|
+
*
|
306
|
+
* @param s
|
307
|
+
*/
|
308
|
+
public void scale(float s) {
|
309
|
+
scale(s, s);
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
*
|
314
|
+
* @param sx
|
315
|
+
* @param sy
|
316
|
+
*/
|
317
|
+
public void scale(float sx, float sy) {
|
318
|
+
m00 *= sx; m01 *= sy;
|
319
|
+
m10 *= sx; m11 *= sy;
|
320
|
+
}
|
321
|
+
|
322
|
+
|
323
|
+
/**
|
324
|
+
* Unavailable in 2D.
|
325
|
+
* @param x
|
326
|
+
* @param y
|
327
|
+
* @param z
|
328
|
+
* @throws IllegalArgumentException
|
329
|
+
*/
|
330
|
+
public void scale(float x, float y, float z) {
|
331
|
+
throw new IllegalArgumentException("Cannot use this version of scale() on a PMatrix2D.");
|
332
|
+
}
|
333
|
+
|
334
|
+
/**
|
335
|
+
*
|
336
|
+
* @param angle
|
337
|
+
*/
|
338
|
+
public void shearX(float angle) {
|
339
|
+
apply(1, 0, 1, tan(angle), 0, 0);
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
*
|
344
|
+
* @param angle
|
345
|
+
*/
|
346
|
+
public void shearY(float angle) {
|
347
|
+
apply(1, 0, 1, 0, tan(angle), 0);
|
348
|
+
}
|
349
|
+
|
350
|
+
|
351
|
+
public void apply(PMatrix source) {
|
352
|
+
if (source instanceof PMatrix2D) {
|
353
|
+
apply((PMatrix2D) source);
|
354
|
+
} else if (source instanceof PMatrix3D) {
|
355
|
+
apply((PMatrix3D) source);
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
public void apply(PMatrix2D source) {
|
361
|
+
apply(source.m00, source.m01, source.m02,
|
362
|
+
source.m10, source.m11, source.m12);
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
/**
|
367
|
+
* Unavailable in 2D.
|
368
|
+
* @param source
|
369
|
+
* @throws IllegalArgumentException
|
370
|
+
*/
|
371
|
+
public void apply(PMatrix3D source) {
|
372
|
+
throw new IllegalArgumentException("Cannot use apply(PMatrix3D) on a PMatrix2D.");
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
public void apply(float n00, float n01, float n02,
|
377
|
+
float n10, float n11, float n12) {
|
378
|
+
float t0 = m00;
|
379
|
+
float t1 = m01;
|
380
|
+
m00 = n00 * t0 + n10 * t1;
|
381
|
+
m01 = n01 * t0 + n11 * t1;
|
382
|
+
m02 += n02 * t0 + n12 * t1;
|
383
|
+
|
384
|
+
t0 = m10;
|
385
|
+
t1 = m11;
|
386
|
+
m10 = n00 * t0 + n10 * t1;
|
387
|
+
m11 = n01 * t0 + n11 * t1;
|
388
|
+
m12 += n02 * t0 + n12 * t1;
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Unavailable in 2D.
|
394
|
+
* @param n00
|
395
|
+
* @param n21
|
396
|
+
* @param n02
|
397
|
+
* @param n01
|
398
|
+
* @param n03
|
399
|
+
* @param n11
|
400
|
+
* @param n10
|
401
|
+
* @param n30
|
402
|
+
* @param n23
|
403
|
+
* @param n13
|
404
|
+
* @param n12
|
405
|
+
* @param n22
|
406
|
+
* @param n32
|
407
|
+
* @param n20
|
408
|
+
* @param n31
|
409
|
+
* @param n33
|
410
|
+
* @throws IllegalArgumentException
|
411
|
+
*/
|
412
|
+
public void apply(float n00, float n01, float n02, float n03,
|
413
|
+
float n10, float n11, float n12, float n13,
|
414
|
+
float n20, float n21, float n22, float n23,
|
415
|
+
float n30, float n31, float n32, float n33) {
|
416
|
+
throw new IllegalArgumentException("Cannot use this version of apply() on a PMatrix2D.");
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
/**
|
421
|
+
* Apply another matrix to the left of this one.
|
422
|
+
* @param source
|
423
|
+
*/
|
424
|
+
public void preApply(PMatrix source) {
|
425
|
+
if (source instanceof PMatrix2D) {
|
426
|
+
preApply((PMatrix2D) source);
|
427
|
+
} else if (source instanceof PMatrix3D) {
|
428
|
+
preApply((PMatrix3D) source);
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
432
|
+
|
433
|
+
public void preApply(PMatrix2D left) {
|
434
|
+
preApply(left.m00, left.m01, left.m02,
|
435
|
+
left.m10, left.m11, left.m12);
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
/**
|
440
|
+
* Unavailable in 2D.
|
441
|
+
* @param left
|
442
|
+
* @throws IllegalArgumentException
|
443
|
+
*/
|
444
|
+
public void preApply(PMatrix3D left) {
|
445
|
+
throw new IllegalArgumentException("Cannot use preApply(PMatrix3D) on a PMatrix2D.");
|
446
|
+
}
|
447
|
+
|
448
|
+
|
449
|
+
public void preApply(float n00, float n01, float n02,
|
450
|
+
float n10, float n11, float n12) {
|
451
|
+
float t0 = m02;
|
452
|
+
float t1 = m12;
|
453
|
+
n02 += t0 * n00 + t1 * n01;
|
454
|
+
n12 += t0 * n10 + t1 * n11;
|
455
|
+
|
456
|
+
m02 = n02;
|
457
|
+
m12 = n12;
|
458
|
+
|
459
|
+
t0 = m00;
|
460
|
+
t1 = m10;
|
461
|
+
m00 = t0 * n00 + t1 * n01;
|
462
|
+
m10 = t0 * n10 + t1 * n11;
|
463
|
+
|
464
|
+
t0 = m01;
|
465
|
+
t1 = m11;
|
466
|
+
m01 = t0 * n00 + t1 * n01;
|
467
|
+
m11 = t0 * n10 + t1 * n11;
|
468
|
+
}
|
469
|
+
|
470
|
+
|
471
|
+
/**
|
472
|
+
* Unavailable in 2D.
|
473
|
+
* @param n00
|
474
|
+
* @param n01
|
475
|
+
* @param n03
|
476
|
+
* @param n02
|
477
|
+
* @param n10
|
478
|
+
* @param n12
|
479
|
+
* @param n21
|
480
|
+
* @param n13
|
481
|
+
* @param n11
|
482
|
+
* @param n30
|
483
|
+
* @param n23
|
484
|
+
* @param n20
|
485
|
+
* @param n32
|
486
|
+
* @param n22
|
487
|
+
* @param n31
|
488
|
+
* @param n33
|
489
|
+
* @throws IllegalArgumentException
|
490
|
+
*/
|
491
|
+
public void preApply(float n00, float n01, float n02, float n03,
|
492
|
+
float n10, float n11, float n12, float n13,
|
493
|
+
float n20, float n21, float n22, float n23,
|
494
|
+
float n30, float n31, float n32, float n33) {
|
495
|
+
throw new IllegalArgumentException("Cannot use this version of preApply() on a PMatrix2D.");
|
496
|
+
}
|
497
|
+
|
498
|
+
|
499
|
+
//////////////////////////////////////////////////////////////
|
500
|
+
|
501
|
+
|
502
|
+
/**
|
503
|
+
* {@inheritDoc}
|
504
|
+
* Ignores any z component.
|
505
|
+
*/
|
506
|
+
public PVector mult(PVector source, PVector target) {
|
507
|
+
if (target == null) {
|
508
|
+
target = new PVector();
|
509
|
+
}
|
510
|
+
target.x = m00*source.x + m01*source.y + m02;
|
511
|
+
target.y = m10*source.x + m11*source.y + m12;
|
512
|
+
return target;
|
513
|
+
}
|
514
|
+
|
515
|
+
|
516
|
+
/**
|
517
|
+
* Multiply a two element vector against this matrix.
|
518
|
+
* If out is null or not length four, a new float array will be returned.
|
519
|
+
* The values for vec and out can be the same (though that's less efficient).
|
520
|
+
* @param vec
|
521
|
+
* @param out
|
522
|
+
* @return
|
523
|
+
*/
|
524
|
+
public float[] mult(float vec[], float out[]) {
|
525
|
+
if (out == null || out.length != 2) {
|
526
|
+
out = new float[2];
|
527
|
+
}
|
528
|
+
|
529
|
+
if (vec == out) {
|
530
|
+
float tx = m00*vec[0] + m01*vec[1] + m02;
|
531
|
+
float ty = m10*vec[0] + m11*vec[1] + m12;
|
532
|
+
|
533
|
+
out[0] = tx;
|
534
|
+
out[1] = ty;
|
535
|
+
|
536
|
+
} else {
|
537
|
+
out[0] = m00*vec[0] + m01*vec[1] + m02;
|
538
|
+
out[1] = m10*vec[0] + m11*vec[1] + m12;
|
539
|
+
}
|
540
|
+
|
541
|
+
return out;
|
542
|
+
}
|
543
|
+
|
544
|
+
|
545
|
+
/**
|
546
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y)
|
547
|
+
* by this matrix.
|
548
|
+
* @param x
|
549
|
+
* @param y
|
550
|
+
* @return
|
551
|
+
*/
|
552
|
+
public float multX(float x, float y) {
|
553
|
+
return m00*x + m01*y + m02;
|
554
|
+
}
|
555
|
+
|
556
|
+
|
557
|
+
/**
|
558
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y)
|
559
|
+
* by this matrix.
|
560
|
+
* @param x
|
561
|
+
* @param y
|
562
|
+
* @return
|
563
|
+
*/
|
564
|
+
public float multY(float x, float y) {
|
565
|
+
return m10*x + m11*y + m12;
|
566
|
+
}
|
567
|
+
|
568
|
+
|
569
|
+
|
570
|
+
/**
|
571
|
+
* Unavailable in 2D. Does nothing.
|
572
|
+
*/
|
573
|
+
public void transpose() {
|
574
|
+
}
|
575
|
+
|
576
|
+
|
577
|
+
/*
|
578
|
+
* Implementation stolen from OpenJDK.
|
579
|
+
*/
|
580
|
+
public boolean invert() {
|
581
|
+
float determinant = determinant();
|
582
|
+
if (Math.abs(determinant) <= Float.MIN_VALUE) {
|
583
|
+
return false;
|
584
|
+
}
|
585
|
+
|
586
|
+
float t00 = m00;
|
587
|
+
float t01 = m01;
|
588
|
+
float t02 = m02;
|
589
|
+
float t10 = m10;
|
590
|
+
float t11 = m11;
|
591
|
+
float t12 = m12;
|
592
|
+
|
593
|
+
m00 = t11 / determinant;
|
594
|
+
m10 = -t10 / determinant;
|
595
|
+
m01 = -t01 / determinant;
|
596
|
+
m11 = t00 / determinant;
|
597
|
+
m02 = (t01 * t12 - t11 * t02) / determinant;
|
598
|
+
m12 = (t10 * t02 - t00 * t12) / determinant;
|
599
|
+
|
600
|
+
return true;
|
601
|
+
}
|
602
|
+
|
603
|
+
|
604
|
+
/**
|
605
|
+
* @return the determinant of the matrix
|
606
|
+
*/
|
607
|
+
public float determinant() {
|
608
|
+
return m00 * m11 - m01 * m10;
|
609
|
+
}
|
610
|
+
|
611
|
+
|
612
|
+
//////////////////////////////////////////////////////////////
|
613
|
+
|
614
|
+
/**
|
615
|
+
*
|
616
|
+
*/
|
617
|
+
|
618
|
+
|
619
|
+
public void print() {
|
620
|
+
int big = (int) abs(max(PApplet.max(abs(m00), abs(m01), abs(m02)),
|
621
|
+
PApplet.max(abs(m10), abs(m11), abs(m12))));
|
622
|
+
|
623
|
+
int digits = 1;
|
624
|
+
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
625
|
+
digits = 5;
|
626
|
+
} else {
|
627
|
+
while ((big /= 10) != 0) digits++; // cheap log()
|
628
|
+
}
|
629
|
+
|
630
|
+
System.out.println(PApplet.nfs(m00, digits, 4) + " " +
|
631
|
+
PApplet.nfs(m01, digits, 4) + " " +
|
632
|
+
PApplet.nfs(m02, digits, 4));
|
633
|
+
|
634
|
+
System.out.println(PApplet.nfs(m10, digits, 4) + " " +
|
635
|
+
PApplet.nfs(m11, digits, 4) + " " +
|
636
|
+
PApplet.nfs(m12, digits, 4));
|
637
|
+
|
638
|
+
System.out.println();
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
//////////////////////////////////////////////////////////////
|
643
|
+
|
644
|
+
// TODO these need to be added as regular API, but the naming and
|
645
|
+
// implementation needs to be improved first. (e.g. actually keeping track
|
646
|
+
// of whether the matrix is in fact identity internally.)
|
647
|
+
|
648
|
+
/**
|
649
|
+
*
|
650
|
+
* @return
|
651
|
+
*/
|
652
|
+
|
653
|
+
|
654
|
+
protected boolean isIdentity() {
|
655
|
+
return ((m00 == 1) && (m01 == 0) && (m02 == 0) &&
|
656
|
+
(m10 == 0) && (m11 == 1) && (m12 == 0));
|
657
|
+
}
|
658
|
+
|
659
|
+
|
660
|
+
// TODO make this more efficient, or move into PMatrix2D
|
661
|
+
|
662
|
+
/**
|
663
|
+
*
|
664
|
+
* @return
|
665
|
+
*/
|
666
|
+
protected boolean isWarped() {
|
667
|
+
return ((m00 != 1) || (m01 != 0) &&
|
668
|
+
(m10 != 0) || (m11 != 1));
|
669
|
+
}
|
670
|
+
|
671
|
+
|
672
|
+
//////////////////////////////////////////////////////////////
|
673
|
+
|
674
|
+
|
675
|
+
static private final float max(float a, float b) {
|
676
|
+
return (a > b) ? a : b;
|
677
|
+
}
|
678
|
+
|
679
|
+
static private final float abs(float a) {
|
680
|
+
return (a < 0) ? -a : a;
|
681
|
+
}
|
682
|
+
|
683
|
+
static private final float sin(float angle) {
|
684
|
+
return (float)Math.sin(angle);
|
685
|
+
}
|
686
|
+
|
687
|
+
static private final float cos(float angle) {
|
688
|
+
return (float)Math.cos(angle);
|
689
|
+
}
|
690
|
+
|
691
|
+
static private final float tan(float angle) {
|
692
|
+
return (float)Math.tan(angle);
|
693
|
+
}
|
694
|
+
}
|