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
|
|
@@ -16,471 +18,470 @@
|
|
16
18
|
Public License along with this library; if not, write to the
|
17
19
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
18
20
|
Boston, MA 02111-1307 USA
|
19
|
-
|
21
|
+
*/
|
22
|
+
|
20
23
|
package processing.core;
|
21
24
|
|
25
|
+
|
22
26
|
/**
|
23
|
-
* 4x4 matrix implementation.
|
24
|
-
* see {@link PMatrix} for a
|
25
|
-
*
|
27
|
+
* 4x4 matrix implementation.
|
28
|
+
* Matrices are used to describe a transformation; see {@link PMatrix} for a
|
29
|
+
* general description. This matrix looks like the following when multiplying
|
30
|
+
* a vector (x, y, z, w) in {@code mult()}.
|
26
31
|
* <pre>
|
27
32
|
* [m00 m01 m02 m03][x] [m00*x + m01*y + m02*z + m03*w] [x']
|
28
33
|
* [m10 m11 m12 m13][y] = [m10*x + m11*y + m12*z + m13*w] = [y']
|
29
34
|
* [m20 m21 m22 m23][z] [m20*x + m21*y + m22*z + m23*w] [z']
|
30
|
-
* [m30 m31 m32 m33][w] [m30*x + m31*y + m32*z + m33*w] [w']</pre>
|
31
|
-
* w') is returned. The values in the matrix determine the
|
32
|
-
* are modified by the various transformation functions.
|
35
|
+
* [m30 m31 m32 m33][w] [m30*x + m31*y + m32*z + m33*w] [w']</pre>
|
36
|
+
* (x', y', z', w') is returned. The values in the matrix determine the
|
37
|
+
* transformation. They are modified by the various transformation functions.
|
33
38
|
*
|
34
|
-
* To transform 3D coordinates, w is set to 1, amd w' is made to be 1 by
|
35
|
-
* the bottom row of the matrix to <code>[0 0 0 1]</code>. The
|
36
|
-
* is then (x', y', z').
|
39
|
+
* To transform 3D coordinates, w is set to 1, amd w' is made to be 1 by
|
40
|
+
* setting the bottom row of the matrix to <code>[0 0 0 1]</code>. The
|
41
|
+
* resulting point is then (x', y', z').
|
37
42
|
*/
|
38
43
|
public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
public float m00, m01, m02, m03;
|
46
|
+
public float m10, m11, m12, m13;
|
47
|
+
public float m20, m21, m22, m23;
|
48
|
+
public float m30, m31, m32, m33;
|
44
49
|
|
45
|
-
// locally allocated version to avoid creating new memory
|
46
|
-
protected PMatrix3D inverseCopy;
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
}
|
51
|
+
// locally allocated version to avoid creating new memory
|
52
|
+
protected PMatrix3D inverseCopy;
|
51
53
|
|
52
|
-
public PMatrix3D(float m00, float m01, float m02,
|
53
|
-
float m10, float m11, float m12) {
|
54
|
-
set(m00, m01, m02, 0,
|
55
|
-
m10, m11, m12, 0,
|
56
|
-
0, 0, 1, 0,
|
57
|
-
0, 0, 0, 1);
|
58
|
-
}
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
float m30, float m31, float m32, float m33) {
|
64
|
-
set(m00, m01, m02, m03,
|
65
|
-
m10, m11, m12, m13,
|
66
|
-
m20, m21, m22, m23,
|
67
|
-
m30, m31, m32, m33);
|
68
|
-
}
|
55
|
+
public PMatrix3D() {
|
56
|
+
reset();
|
57
|
+
}
|
69
58
|
|
70
|
-
public PMatrix3D(PMatrix matrix) {
|
71
|
-
set(matrix);
|
72
|
-
}
|
73
59
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
60
|
+
public PMatrix3D(float m00, float m01, float m02,
|
61
|
+
float m10, float m11, float m12) {
|
62
|
+
set(m00, m01, m02, 0,
|
63
|
+
m10, m11, m12, 0,
|
64
|
+
0, 0, 1, 0,
|
65
|
+
0, 0, 0, 1);
|
66
|
+
}
|
80
67
|
|
81
|
-
/**
|
82
|
-
* Returns a copy of this PMatrix.
|
83
|
-
*/
|
84
|
-
public PMatrix3D get() {
|
85
|
-
PMatrix3D outgoing = new PMatrix3D();
|
86
|
-
outgoing.set(this);
|
87
|
-
return outgoing;
|
88
|
-
}
|
89
68
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
target[1] = m01;
|
100
|
-
target[2] = m02;
|
101
|
-
target[3] = m03;
|
102
|
-
|
103
|
-
target[4] = m10;
|
104
|
-
target[5] = m11;
|
105
|
-
target[6] = m12;
|
106
|
-
target[7] = m13;
|
107
|
-
|
108
|
-
target[8] = m20;
|
109
|
-
target[9] = m21;
|
110
|
-
target[10] = m22;
|
111
|
-
target[11] = m23;
|
112
|
-
|
113
|
-
target[12] = m30;
|
114
|
-
target[13] = m31;
|
115
|
-
target[14] = m32;
|
116
|
-
target[15] = m33;
|
117
|
-
|
118
|
-
return target;
|
119
|
-
}
|
69
|
+
public PMatrix3D(float m00, float m01, float m02, float m03,
|
70
|
+
float m10, float m11, float m12, float m13,
|
71
|
+
float m20, float m21, float m22, float m23,
|
72
|
+
float m30, float m31, float m32, float m33) {
|
73
|
+
set(m00, m01, m02, m03,
|
74
|
+
m10, m11, m12, m13,
|
75
|
+
m20, m21, m22, m23,
|
76
|
+
m30, m31, m32, m33);
|
77
|
+
}
|
120
78
|
|
121
|
-
public void set(PMatrix matrix) {
|
122
|
-
if (matrix instanceof PMatrix3D) {
|
123
|
-
PMatrix3D src = (PMatrix3D) matrix;
|
124
|
-
set(src.m00, src.m01, src.m02, src.m03,
|
125
|
-
src.m10, src.m11, src.m12, src.m13,
|
126
|
-
src.m20, src.m21, src.m22, src.m23,
|
127
|
-
src.m30, src.m31, src.m32, src.m33);
|
128
|
-
} else {
|
129
|
-
PMatrix2D src = (PMatrix2D) matrix;
|
130
|
-
set(src.m00, src.m01, 0, src.m02,
|
131
|
-
src.m10, src.m11, 0, src.m12,
|
132
|
-
0, 0, 1, 0,
|
133
|
-
0, 0, 0, 1);
|
134
|
-
}
|
135
|
-
}
|
136
79
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
m11 = source[5];
|
150
|
-
m12 = source[6];
|
151
|
-
m13 = source[7];
|
152
|
-
|
153
|
-
m20 = source[8];
|
154
|
-
m21 = source[9];
|
155
|
-
m22 = source[10];
|
156
|
-
m23 = source[11];
|
157
|
-
|
158
|
-
m30 = source[12];
|
159
|
-
m31 = source[13];
|
160
|
-
m32 = source[14];
|
161
|
-
m33 = source[15];
|
162
|
-
}
|
163
|
-
}
|
80
|
+
public PMatrix3D(PMatrix matrix) {
|
81
|
+
set(matrix);
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
public void reset() {
|
86
|
+
set(1, 0, 0, 0,
|
87
|
+
0, 1, 0, 0,
|
88
|
+
0, 0, 1, 0,
|
89
|
+
0, 0, 0, 1);
|
90
|
+
}
|
91
|
+
|
164
92
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
93
|
+
/**
|
94
|
+
* Returns a copy of this PMatrix.
|
95
|
+
*/
|
96
|
+
@Override
|
97
|
+
public PMatrix3D get() {
|
98
|
+
PMatrix3D outgoing = new PMatrix3D();
|
99
|
+
outgoing.set(this);
|
100
|
+
return outgoing;
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Copies the matrix contents into a 16 entry float array.
|
106
|
+
* If target is null (or not the correct size), a new array will be created.
|
107
|
+
*/
|
108
|
+
public float[] get(float[] target) {
|
109
|
+
if ((target == null) || (target.length != 16)) {
|
110
|
+
target = new float[16];
|
171
111
|
}
|
112
|
+
target[0] = m00;
|
113
|
+
target[1] = m01;
|
114
|
+
target[2] = m02;
|
115
|
+
target[3] = m03;
|
116
|
+
|
117
|
+
target[4] = m10;
|
118
|
+
target[5] = m11;
|
119
|
+
target[6] = m12;
|
120
|
+
target[7] = m13;
|
121
|
+
|
122
|
+
target[8] = m20;
|
123
|
+
target[9] = m21;
|
124
|
+
target[10] = m22;
|
125
|
+
target[11] = m23;
|
126
|
+
|
127
|
+
target[12] = m30;
|
128
|
+
target[13] = m31;
|
129
|
+
target[14] = m32;
|
130
|
+
target[15] = m33;
|
172
131
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
this.m31 = m31;
|
191
|
-
this.m32 = m32;
|
192
|
-
this.m33 = m33;
|
132
|
+
return target;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
public void set(PMatrix matrix) {
|
137
|
+
if (matrix instanceof PMatrix3D) {
|
138
|
+
PMatrix3D src = (PMatrix3D) matrix;
|
139
|
+
set(src.m00, src.m01, src.m02, src.m03,
|
140
|
+
src.m10, src.m11, src.m12, src.m13,
|
141
|
+
src.m20, src.m21, src.m22, src.m23,
|
142
|
+
src.m30, src.m31, src.m32, src.m33);
|
143
|
+
} else {
|
144
|
+
PMatrix2D src = (PMatrix2D) matrix;
|
145
|
+
set(src.m00, src.m01, 0, src.m02,
|
146
|
+
src.m10, src.m11, 0, src.m12,
|
147
|
+
0, 0, 1, 0,
|
148
|
+
0, 0, 0, 1);
|
193
149
|
}
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
public void set(float[] source) {
|
154
|
+
if (source.length == 6) {
|
155
|
+
set(source[0], source[1], source[2],
|
156
|
+
source[3], source[4], source[5]);
|
194
157
|
|
195
|
-
|
196
|
-
|
158
|
+
} else if (source.length == 16) {
|
159
|
+
m00 = source[0];
|
160
|
+
m01 = source[1];
|
161
|
+
m02 = source[2];
|
162
|
+
m03 = source[3];
|
163
|
+
|
164
|
+
m10 = source[4];
|
165
|
+
m11 = source[5];
|
166
|
+
m12 = source[6];
|
167
|
+
m13 = source[7];
|
168
|
+
|
169
|
+
m20 = source[8];
|
170
|
+
m21 = source[9];
|
171
|
+
m22 = source[10];
|
172
|
+
m23 = source[11];
|
173
|
+
|
174
|
+
m30 = source[12];
|
175
|
+
m31 = source[13];
|
176
|
+
m32 = source[14];
|
177
|
+
m33 = source[15];
|
197
178
|
}
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
public void set(float m00, float m01, float m02,
|
183
|
+
float m10, float m11, float m12) {
|
184
|
+
set(m00, m01, 0, m02,
|
185
|
+
m10, m11, 0, m12,
|
186
|
+
0, 0, 1, 0,
|
187
|
+
0, 0, 0, 1);
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
public void set(float m00, float m01, float m02, float m03,
|
192
|
+
float m10, float m11, float m12, float m13,
|
193
|
+
float m20, float m21, float m22, float m23,
|
194
|
+
float m30, float m31, float m32, float m33) {
|
195
|
+
this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
|
196
|
+
this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
|
197
|
+
this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
|
198
|
+
this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
public void translate(float tx, float ty) {
|
203
|
+
translate(tx, ty, 0);
|
204
|
+
}
|
198
205
|
|
199
206
|
// public void invTranslate(float tx, float ty) {
|
200
207
|
// invTranslate(tx, ty, 0);
|
201
208
|
// }
|
202
|
-
public void translate(float tx, float ty, float tz) {
|
203
|
-
m03 += tx * m00 + ty * m01 + tz * m02;
|
204
|
-
m13 += tx * m10 + ty * m11 + tz * m12;
|
205
|
-
m23 += tx * m20 + ty * m21 + tz * m22;
|
206
|
-
m33 += tx * m30 + ty * m31 + tz * m32;
|
207
|
-
}
|
208
209
|
|
209
|
-
public void rotate(float angle) {
|
210
|
-
rotateZ(angle);
|
211
|
-
}
|
212
210
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
211
|
+
public void translate(float tx, float ty, float tz) {
|
212
|
+
m03 += tx*m00 + ty*m01 + tz*m02;
|
213
|
+
m13 += tx*m10 + ty*m11 + tz*m12;
|
214
|
+
m23 += tx*m20 + ty*m21 + tz*m22;
|
215
|
+
m33 += tx*m30 + ty*m31 + tz*m32;
|
216
|
+
}
|
218
217
|
|
219
|
-
public void rotateY(float angle) {
|
220
|
-
float c = cos(angle);
|
221
|
-
float s = sin(angle);
|
222
|
-
apply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
223
|
-
}
|
224
218
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
apply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
229
|
-
}
|
219
|
+
public void rotate(float angle) {
|
220
|
+
rotateZ(angle);
|
221
|
+
}
|
230
222
|
|
231
|
-
public void rotate(float angle, float v0, float v1, float v2) {
|
232
|
-
float norm2 = v0 * v0 + v1 * v1 + v2 * v2;
|
233
|
-
if (norm2 < PConstants.EPSILON) {
|
234
|
-
// The vector is zero, cannot apply rotation.
|
235
|
-
return;
|
236
|
-
}
|
237
|
-
|
238
|
-
if (Math.abs(norm2 - 1) > PConstants.EPSILON) {
|
239
|
-
// The rotation vector is not normalized.
|
240
|
-
float norm = PApplet.sqrt(norm2);
|
241
|
-
v0 /= norm;
|
242
|
-
v1 /= norm;
|
243
|
-
v2 /= norm;
|
244
|
-
}
|
245
|
-
|
246
|
-
float c = cos(angle);
|
247
|
-
float s = sin(angle);
|
248
|
-
float t = 1.0f - c;
|
249
|
-
|
250
|
-
apply((t * v0 * v0) + c, (t * v0 * v1) - (s * v2), (t * v0 * v2) + (s * v1), 0,
|
251
|
-
(t * v0 * v1) + (s * v2), (t * v1 * v1) + c, (t * v1 * v2) - (s * v0), 0,
|
252
|
-
(t * v0 * v2) - (s * v1), (t * v1 * v2) + (s * v0), (t * v2 * v2) + c, 0,
|
253
|
-
0, 0, 0, 1);
|
254
|
-
}
|
255
223
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
224
|
+
public void rotateX(float angle) {
|
225
|
+
float c = cos(angle);
|
226
|
+
float s = sin(angle);
|
227
|
+
apply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
228
|
+
}
|
260
229
|
|
261
|
-
public void scale(float sx, float sy) {
|
262
|
-
//apply(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
263
|
-
scale(sx, sy, 1);
|
264
|
-
}
|
265
230
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
m11 *= y;
|
273
|
-
m12 *= z;
|
274
|
-
m20 *= x;
|
275
|
-
m21 *= y;
|
276
|
-
m22 *= z;
|
277
|
-
m30 *= x;
|
278
|
-
m31 *= y;
|
279
|
-
m32 *= z;
|
280
|
-
}
|
231
|
+
@Override
|
232
|
+
public void rotateY(float angle) {
|
233
|
+
float c = cos(angle);
|
234
|
+
float s = sin(angle);
|
235
|
+
apply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
236
|
+
}
|
281
237
|
|
282
|
-
public void shearX(float angle) {
|
283
|
-
float t = (float) Math.tan(angle);
|
284
|
-
apply(1, t, 0, 0,
|
285
|
-
0, 1, 0, 0,
|
286
|
-
0, 0, 1, 0,
|
287
|
-
0, 0, 0, 1);
|
288
|
-
}
|
289
238
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
}
|
239
|
+
@Override
|
240
|
+
public void rotateZ(float angle) {
|
241
|
+
float c = cos(angle);
|
242
|
+
float s = sin(angle);
|
243
|
+
apply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
244
|
+
}
|
297
245
|
|
298
|
-
public void apply(PMatrix source) {
|
299
|
-
if (source instanceof PMatrix2D) {
|
300
|
-
apply((PMatrix2D) source);
|
301
|
-
} else if (source instanceof PMatrix3D) {
|
302
|
-
apply((PMatrix3D) source);
|
303
|
-
}
|
304
|
-
}
|
305
246
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
247
|
+
@Override
|
248
|
+
public void rotate(float angle, float v0, float v1, float v2) {
|
249
|
+
float norm2 = v0 * v0 + v1 * v1 + v2 * v2;
|
250
|
+
if (norm2 < PConstants.EPSILON) {
|
251
|
+
// The vector is zero, cannot apply rotation.
|
252
|
+
return;
|
311
253
|
}
|
312
254
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
255
|
+
if (Math.abs(norm2 - 1) > PConstants.EPSILON) {
|
256
|
+
// The rotation vector is not normalized.
|
257
|
+
float norm = PApplet.sqrt(norm2);
|
258
|
+
v0 /= norm;
|
259
|
+
v1 /= norm;
|
260
|
+
v2 /= norm;
|
318
261
|
}
|
319
262
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
n10, n11, 0, n12,
|
324
|
-
0, 0, 1, 0,
|
325
|
-
0, 0, 0, 1);
|
326
|
-
}
|
263
|
+
float c = cos(angle);
|
264
|
+
float s = sin(angle);
|
265
|
+
float t = 1.0f - c;
|
327
266
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
float r00 = m00 * n00 + m01 * n10 + m02 * n20 + m03 * n30;
|
334
|
-
float r01 = m00 * n01 + m01 * n11 + m02 * n21 + m03 * n31;
|
335
|
-
float r02 = m00 * n02 + m01 * n12 + m02 * n22 + m03 * n32;
|
336
|
-
float r03 = m00 * n03 + m01 * n13 + m02 * n23 + m03 * n33;
|
337
|
-
|
338
|
-
float r10 = m10 * n00 + m11 * n10 + m12 * n20 + m13 * n30;
|
339
|
-
float r11 = m10 * n01 + m11 * n11 + m12 * n21 + m13 * n31;
|
340
|
-
float r12 = m10 * n02 + m11 * n12 + m12 * n22 + m13 * n32;
|
341
|
-
float r13 = m10 * n03 + m11 * n13 + m12 * n23 + m13 * n33;
|
342
|
-
|
343
|
-
float r20 = m20 * n00 + m21 * n10 + m22 * n20 + m23 * n30;
|
344
|
-
float r21 = m20 * n01 + m21 * n11 + m22 * n21 + m23 * n31;
|
345
|
-
float r22 = m20 * n02 + m21 * n12 + m22 * n22 + m23 * n32;
|
346
|
-
float r23 = m20 * n03 + m21 * n13 + m22 * n23 + m23 * n33;
|
347
|
-
|
348
|
-
float r30 = m30 * n00 + m31 * n10 + m32 * n20 + m33 * n30;
|
349
|
-
float r31 = m30 * n01 + m31 * n11 + m32 * n21 + m33 * n31;
|
350
|
-
float r32 = m30 * n02 + m31 * n12 + m32 * n22 + m33 * n32;
|
351
|
-
float r33 = m30 * n03 + m31 * n13 + m32 * n23 + m33 * n33;
|
352
|
-
|
353
|
-
m00 = r00;
|
354
|
-
m01 = r01;
|
355
|
-
m02 = r02;
|
356
|
-
m03 = r03;
|
357
|
-
m10 = r10;
|
358
|
-
m11 = r11;
|
359
|
-
m12 = r12;
|
360
|
-
m13 = r13;
|
361
|
-
m20 = r20;
|
362
|
-
m21 = r21;
|
363
|
-
m22 = r22;
|
364
|
-
m23 = r23;
|
365
|
-
m30 = r30;
|
366
|
-
m31 = r31;
|
367
|
-
m32 = r32;
|
368
|
-
m33 = r33;
|
369
|
-
}
|
267
|
+
apply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
268
|
+
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
269
|
+
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
270
|
+
0, 0, 0, 1);
|
271
|
+
}
|
370
272
|
|
371
|
-
/**
|
372
|
-
* Apply the 3D equivalent of the 2D matrix supplied to the left of this
|
373
|
-
* one.
|
374
|
-
*/
|
375
|
-
public void preApply(PMatrix2D left) {
|
376
|
-
preApply(left.m00, left.m01, 0, left.m02,
|
377
|
-
left.m10, left.m11, 0, left.m12,
|
378
|
-
0, 0, 1, 0,
|
379
|
-
0, 0, 0, 1);
|
380
|
-
}
|
381
273
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
274
|
+
public void scale(float s) {
|
275
|
+
//apply(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
276
|
+
scale(s, s, s);
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
public void scale(float sx, float sy) {
|
281
|
+
//apply(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
282
|
+
scale(sx, sy, 1);
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
public void scale(float x, float y, float z) {
|
287
|
+
//apply(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
288
|
+
m00 *= x; m01 *= y; m02 *= z;
|
289
|
+
m10 *= x; m11 *= y; m12 *= z;
|
290
|
+
m20 *= x; m21 *= y; m22 *= z;
|
291
|
+
m30 *= x; m31 *= y; m32 *= z;
|
292
|
+
}
|
293
|
+
|
294
|
+
|
295
|
+
public void shearX(float angle) {
|
296
|
+
float t = (float) Math.tan(angle);
|
297
|
+
apply(1, t, 0, 0,
|
298
|
+
0, 1, 0, 0,
|
299
|
+
0, 0, 1, 0,
|
300
|
+
0, 0, 0, 1);
|
301
|
+
}
|
392
302
|
|
393
|
-
/**
|
394
|
-
* Apply another matrix to the left of this one.
|
395
|
-
*/
|
396
|
-
public void preApply(PMatrix3D left) {
|
397
|
-
preApply(left.m00, left.m01, left.m02, left.m03,
|
398
|
-
left.m10, left.m11, left.m12, left.m13,
|
399
|
-
left.m20, left.m21, left.m22, left.m23,
|
400
|
-
left.m30, left.m31, left.m32, left.m33);
|
401
|
-
}
|
402
303
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
304
|
+
public void shearY(float angle) {
|
305
|
+
float t = (float) Math.tan(angle);
|
306
|
+
apply(1, 0, 0, 0,
|
307
|
+
t, 1, 0, 0,
|
308
|
+
0, 0, 1, 0,
|
309
|
+
0, 0, 0, 1);
|
310
|
+
}
|
311
|
+
|
312
|
+
|
313
|
+
public void apply(PMatrix source) {
|
314
|
+
if (source instanceof PMatrix2D) {
|
315
|
+
apply((PMatrix2D) source);
|
316
|
+
} else if (source instanceof PMatrix3D) {
|
317
|
+
apply((PMatrix3D) source);
|
413
318
|
}
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
public void apply(PMatrix2D source) {
|
323
|
+
apply(source.m00, source.m01, 0, source.m02,
|
324
|
+
source.m10, source.m11, 0, source.m12,
|
325
|
+
0, 0, 1, 0,
|
326
|
+
0, 0, 0, 1);
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
public void apply(PMatrix3D source) {
|
331
|
+
apply(source.m00, source.m01, source.m02, source.m03,
|
332
|
+
source.m10, source.m11, source.m12, source.m13,
|
333
|
+
source.m20, source.m21, source.m22, source.m23,
|
334
|
+
source.m30, source.m31, source.m32, source.m33);
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
public void apply(float n00, float n01, float n02,
|
339
|
+
float n10, float n11, float n12) {
|
340
|
+
apply(n00, n01, 0, n02,
|
341
|
+
n10, n11, 0, n12,
|
342
|
+
0, 0, 1, 0,
|
343
|
+
0, 0, 0, 1);
|
344
|
+
}
|
414
345
|
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
346
|
+
|
347
|
+
public void apply(float n00, float n01, float n02, float n03,
|
348
|
+
float n10, float n11, float n12, float n13,
|
349
|
+
float n20, float n21, float n22, float n23,
|
350
|
+
float n30, float n31, float n32, float n33) {
|
351
|
+
|
352
|
+
float r00 = m00*n00 + m01*n10 + m02*n20 + m03*n30;
|
353
|
+
float r01 = m00*n01 + m01*n11 + m02*n21 + m03*n31;
|
354
|
+
float r02 = m00*n02 + m01*n12 + m02*n22 + m03*n32;
|
355
|
+
float r03 = m00*n03 + m01*n13 + m02*n23 + m03*n33;
|
356
|
+
|
357
|
+
float r10 = m10*n00 + m11*n10 + m12*n20 + m13*n30;
|
358
|
+
float r11 = m10*n01 + m11*n11 + m12*n21 + m13*n31;
|
359
|
+
float r12 = m10*n02 + m11*n12 + m12*n22 + m13*n32;
|
360
|
+
float r13 = m10*n03 + m11*n13 + m12*n23 + m13*n33;
|
361
|
+
|
362
|
+
float r20 = m20*n00 + m21*n10 + m22*n20 + m23*n30;
|
363
|
+
float r21 = m20*n01 + m21*n11 + m22*n21 + m23*n31;
|
364
|
+
float r22 = m20*n02 + m21*n12 + m22*n22 + m23*n32;
|
365
|
+
float r23 = m20*n03 + m21*n13 + m22*n23 + m23*n33;
|
366
|
+
|
367
|
+
float r30 = m30*n00 + m31*n10 + m32*n20 + m33*n30;
|
368
|
+
float r31 = m30*n01 + m31*n11 + m32*n21 + m33*n31;
|
369
|
+
float r32 = m30*n02 + m31*n12 + m32*n22 + m33*n32;
|
370
|
+
float r33 = m30*n03 + m31*n13 + m32*n23 + m33*n33;
|
371
|
+
|
372
|
+
m00 = r00; m01 = r01; m02 = r02; m03 = r03;
|
373
|
+
m10 = r10; m11 = r11; m12 = r12; m13 = r13;
|
374
|
+
m20 = r20; m21 = r21; m22 = r22; m23 = r23;
|
375
|
+
m30 = r30; m31 = r31; m32 = r32; m33 = r33;
|
376
|
+
}
|
377
|
+
|
378
|
+
|
379
|
+
/**
|
380
|
+
* Apply the 3D equivalent of the 2D matrix supplied to the left of this one.
|
381
|
+
*/
|
382
|
+
public void preApply(PMatrix2D left) {
|
383
|
+
preApply(left.m00, left.m01, 0, left.m02,
|
384
|
+
left.m10, left.m11, 0, left.m12,
|
385
|
+
0, 0, 1, 0,
|
386
|
+
0, 0, 0, 1);
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Apply another matrix to the left of this one.
|
392
|
+
*/
|
393
|
+
public void preApply(PMatrix source) {
|
394
|
+
if (source instanceof PMatrix2D) {
|
395
|
+
preApply((PMatrix2D) source);
|
396
|
+
} else if (source instanceof PMatrix3D) {
|
397
|
+
preApply((PMatrix3D) source);
|
459
398
|
}
|
399
|
+
}
|
460
400
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
401
|
+
|
402
|
+
/**
|
403
|
+
* Apply another matrix to the left of this one.
|
404
|
+
*/
|
405
|
+
public void preApply(PMatrix3D left) {
|
406
|
+
preApply(left.m00, left.m01, left.m02, left.m03,
|
407
|
+
left.m10, left.m11, left.m12, left.m13,
|
408
|
+
left.m20, left.m21, left.m22, left.m23,
|
409
|
+
left.m30, left.m31, left.m32, left.m33);
|
410
|
+
}
|
411
|
+
|
412
|
+
|
413
|
+
/**
|
414
|
+
* Apply the 3D equivalent of the 2D matrix supplied to the left of this one.
|
415
|
+
*/
|
416
|
+
public void preApply(float n00, float n01, float n02,
|
417
|
+
float n10, float n11, float n12) {
|
418
|
+
preApply(n00, n01, 0, n02,
|
419
|
+
n10, n11, 0, n12,
|
420
|
+
0, 0, 1, 0,
|
421
|
+
0, 0, 0, 1);
|
422
|
+
}
|
423
|
+
|
424
|
+
|
425
|
+
/**
|
426
|
+
* Apply another matrix to the left of this one.
|
427
|
+
*/
|
428
|
+
public void preApply(float n00, float n01, float n02, float n03,
|
429
|
+
float n10, float n11, float n12, float n13,
|
430
|
+
float n20, float n21, float n22, float n23,
|
431
|
+
float n30, float n31, float n32, float n33) {
|
432
|
+
|
433
|
+
float r00 = n00*m00 + n01*m10 + n02*m20 + n03*m30;
|
434
|
+
float r01 = n00*m01 + n01*m11 + n02*m21 + n03*m31;
|
435
|
+
float r02 = n00*m02 + n01*m12 + n02*m22 + n03*m32;
|
436
|
+
float r03 = n00*m03 + n01*m13 + n02*m23 + n03*m33;
|
437
|
+
|
438
|
+
float r10 = n10*m00 + n11*m10 + n12*m20 + n13*m30;
|
439
|
+
float r11 = n10*m01 + n11*m11 + n12*m21 + n13*m31;
|
440
|
+
float r12 = n10*m02 + n11*m12 + n12*m22 + n13*m32;
|
441
|
+
float r13 = n10*m03 + n11*m13 + n12*m23 + n13*m33;
|
442
|
+
|
443
|
+
float r20 = n20*m00 + n21*m10 + n22*m20 + n23*m30;
|
444
|
+
float r21 = n20*m01 + n21*m11 + n22*m21 + n23*m31;
|
445
|
+
float r22 = n20*m02 + n21*m12 + n22*m22 + n23*m32;
|
446
|
+
float r23 = n20*m03 + n21*m13 + n22*m23 + n23*m33;
|
447
|
+
|
448
|
+
float r30 = n30*m00 + n31*m10 + n32*m20 + n33*m30;
|
449
|
+
float r31 = n30*m01 + n31*m11 + n32*m21 + n33*m31;
|
450
|
+
float r32 = n30*m02 + n31*m12 + n32*m22 + n33*m32;
|
451
|
+
float r33 = n30*m03 + n31*m13 + n32*m23 + n33*m33;
|
452
|
+
|
453
|
+
m00 = r00; m01 = r01; m02 = r02; m03 = r03;
|
454
|
+
m10 = r10; m11 = r11; m12 = r12; m13 = r13;
|
455
|
+
m20 = r20; m21 = r21; m22 = r22; m23 = r23;
|
456
|
+
m30 = r30; m31 = r31; m32 = r32; m33 = r33;
|
457
|
+
}
|
458
|
+
|
459
|
+
|
460
|
+
//////////////////////////////////////////////////////////////
|
461
|
+
|
462
|
+
|
463
|
+
/**
|
464
|
+
* Multiply source by this matrix, and return the result.
|
465
|
+
* The result will be stored in target if target is non-null, and target
|
466
|
+
* will then be the matrix returned. This improves performance if you reuse
|
467
|
+
* target, so it's recommended if you call this many times in draw().
|
468
|
+
*/
|
469
|
+
public PVector mult(PVector source, PVector target) {
|
470
|
+
if (target == null) {
|
471
|
+
target = new PVector();
|
472
|
+
}
|
473
|
+
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
|
474
|
+
m10*source.x + m11*source.y + m12*source.z + m13,
|
475
|
+
m20*source.x + m21*source.y + m22*source.z + m23);
|
475
476
|
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
|
476
477
|
// if (tw != 0 && tw != 1) {
|
477
478
|
// target.div(tw);
|
478
479
|
// }
|
479
|
-
|
480
|
-
|
480
|
+
return target;
|
481
|
+
}
|
481
482
|
|
482
483
|
|
483
|
-
|
484
|
+
/*
|
484
485
|
public PVector cmult(PVector source, PVector target) {
|
485
486
|
if (target == null) {
|
486
487
|
target = new PVector();
|
@@ -494,370 +495,389 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
|
|
494
495
|
}
|
495
496
|
return target;
|
496
497
|
}
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
498
|
+
*/
|
499
|
+
|
500
|
+
|
501
|
+
/**
|
502
|
+
* Multiply a three or four element vector against this matrix. If out is
|
503
|
+
* null or not length 3 or 4, a new float array (length 3) will be returned.
|
504
|
+
* Supplying and recycling a target array improves performance, so it's
|
505
|
+
* recommended if you call this many times in draw.
|
506
|
+
*/
|
507
|
+
public float[] mult(float[] source, float[] target) {
|
508
|
+
if (target == null || target.length < 3) {
|
509
|
+
target = new float[3];
|
510
|
+
}
|
511
|
+
if (source == target) {
|
512
|
+
throw new RuntimeException("The source and target vectors used in " +
|
513
|
+
"PMatrix3D.mult() cannot be identical.");
|
514
|
+
}
|
515
|
+
if (target.length == 3) {
|
516
|
+
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03;
|
517
|
+
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13;
|
518
|
+
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23;
|
519
|
+
//float w = m30*source[0] + m31*source[1] + m32*source[2] + m33;
|
520
|
+
//if (w != 0 && w != 1) {
|
521
|
+
// target[0] /= w; target[1] /= w; target[2] /= w;
|
522
|
+
//}
|
523
|
+
} else if (target.length > 3) {
|
524
|
+
target[0] = m00*source[0] + m01*source[1] + m02*source[2] + m03*source[3];
|
525
|
+
target[1] = m10*source[0] + m11*source[1] + m12*source[2] + m13*source[3];
|
526
|
+
target[2] = m20*source[0] + m21*source[1] + m22*source[2] + m23*source[3];
|
527
|
+
target[3] = m30*source[0] + m31*source[1] + m32*source[2] + m33*source[3];
|
527
528
|
}
|
529
|
+
return target;
|
530
|
+
}
|
528
531
|
|
529
|
-
/**
|
530
|
-
* Returns the x-coordinate of the result of multiplying the point (x, y) by
|
531
|
-
* this matrix.
|
532
|
-
*/
|
533
|
-
public float multX(float x, float y) {
|
534
|
-
return m00 * x + m01 * y + m03;
|
535
|
-
}
|
536
532
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
533
|
+
/**
|
534
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y)
|
535
|
+
* by this matrix.
|
536
|
+
*/
|
537
|
+
public float multX(float x, float y) {
|
538
|
+
return m00*x + m01*y + m03;
|
539
|
+
}
|
544
540
|
|
545
|
-
/**
|
546
|
-
* Returns the x-coordinate of the result of multiplying the point (x, y, z)
|
547
|
-
* by this matrix.
|
548
|
-
*/
|
549
|
-
public float multX(float x, float y, float z) {
|
550
|
-
return m00 * x + m01 * y + m02 * z + m03;
|
551
|
-
}
|
552
541
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
542
|
+
/**
|
543
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y)
|
544
|
+
* by this matrix.
|
545
|
+
*/
|
546
|
+
public float multY(float x, float y) {
|
547
|
+
return m10*x + m11*y + m13;
|
548
|
+
}
|
560
549
|
|
561
|
-
/**
|
562
|
-
* Returns the z-coordinate of the result of multiplying the point (x, y, z)
|
563
|
-
* by this matrix.
|
564
|
-
*/
|
565
|
-
public float multZ(float x, float y, float z) {
|
566
|
-
return m20 * x + m21 * y + m22 * z + m23;
|
567
|
-
}
|
568
550
|
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
551
|
+
/**
|
552
|
+
* Returns the x-coordinate of the result of multiplying the point (x, y, z)
|
553
|
+
* by this matrix.
|
554
|
+
*/
|
555
|
+
public float multX(float x, float y, float z) {
|
556
|
+
return m00*x + m01*y + m02*z + m03;
|
557
|
+
}
|
576
558
|
|
577
|
-
/**
|
578
|
-
* Returns the x-coordinate of the result of multiplying the vector (x, y,
|
579
|
-
* z, w) by this matrix.
|
580
|
-
*/
|
581
|
-
public float multX(float x, float y, float z, float w) {
|
582
|
-
return m00 * x + m01 * y + m02 * z + m03 * w;
|
583
|
-
}
|
584
559
|
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
560
|
+
/**
|
561
|
+
* Returns the y-coordinate of the result of multiplying the point (x, y, z)
|
562
|
+
* by this matrix.
|
563
|
+
*/
|
564
|
+
public float multY(float x, float y, float z) {
|
565
|
+
return m10*x + m11*y + m12*z + m13;
|
566
|
+
}
|
592
567
|
|
593
|
-
/**
|
594
|
-
* Returns the z-coordinate of the result of multiplying the vector (x, y,
|
595
|
-
* z, w) by this matrix.
|
596
|
-
*/
|
597
|
-
public float multZ(float x, float y, float z, float w) {
|
598
|
-
return m20 * x + m21 * y + m22 * z + m23 * w;
|
599
|
-
}
|
600
568
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
569
|
+
/**
|
570
|
+
* Returns the z-coordinate of the result of multiplying the point (x, y, z)
|
571
|
+
* by this matrix.
|
572
|
+
*/
|
573
|
+
public float multZ(float x, float y, float z) {
|
574
|
+
return m20*x + m21*y + m22*z + m23;
|
575
|
+
}
|
608
576
|
|
609
|
-
/**
|
610
|
-
* Transpose this matrix; rows become columns and columns rows.
|
611
|
-
*/
|
612
|
-
public void transpose() {
|
613
|
-
float temp;
|
614
|
-
temp = m01;
|
615
|
-
m01 = m10;
|
616
|
-
m10 = temp;
|
617
|
-
temp = m02;
|
618
|
-
m02 = m20;
|
619
|
-
m20 = temp;
|
620
|
-
temp = m03;
|
621
|
-
m03 = m30;
|
622
|
-
m30 = temp;
|
623
|
-
temp = m12;
|
624
|
-
m12 = m21;
|
625
|
-
m21 = temp;
|
626
|
-
temp = m13;
|
627
|
-
m13 = m31;
|
628
|
-
m31 = temp;
|
629
|
-
temp = m23;
|
630
|
-
m23 = m32;
|
631
|
-
m32 = temp;
|
632
|
-
}
|
633
577
|
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
float determinant = determinant();
|
642
|
-
if (determinant == 0) {
|
643
|
-
return false;
|
644
|
-
}
|
645
|
-
|
646
|
-
// first row
|
647
|
-
float t00 = determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
648
|
-
float t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33);
|
649
|
-
float t02 = determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33);
|
650
|
-
float t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32);
|
651
|
-
|
652
|
-
// second row
|
653
|
-
float t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33);
|
654
|
-
float t11 = determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33);
|
655
|
-
float t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33);
|
656
|
-
float t13 = determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32);
|
657
|
-
|
658
|
-
// third row
|
659
|
-
float t20 = determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33);
|
660
|
-
float t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33);
|
661
|
-
float t22 = determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33);
|
662
|
-
float t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32);
|
663
|
-
|
664
|
-
// fourth row
|
665
|
-
float t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23);
|
666
|
-
float t31 = determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23);
|
667
|
-
float t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23);
|
668
|
-
float t33 = determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
669
|
-
|
670
|
-
// transpose and divide by the determinant
|
671
|
-
m00 = t00 / determinant;
|
672
|
-
m01 = t10 / determinant;
|
673
|
-
m02 = t20 / determinant;
|
674
|
-
m03 = t30 / determinant;
|
675
|
-
|
676
|
-
m10 = t01 / determinant;
|
677
|
-
m11 = t11 / determinant;
|
678
|
-
m12 = t21 / determinant;
|
679
|
-
m13 = t31 / determinant;
|
680
|
-
|
681
|
-
m20 = t02 / determinant;
|
682
|
-
m21 = t12 / determinant;
|
683
|
-
m22 = t22 / determinant;
|
684
|
-
m23 = t32 / determinant;
|
685
|
-
|
686
|
-
m30 = t03 / determinant;
|
687
|
-
m31 = t13 / determinant;
|
688
|
-
m32 = t23 / determinant;
|
689
|
-
m33 = t33 / determinant;
|
690
|
-
|
691
|
-
return true;
|
692
|
-
}
|
578
|
+
/**
|
579
|
+
* Returns the fourth element of the result of multiplying the vector
|
580
|
+
* (x, y, z) by this matrix. (Acts as if w = 1 was supplied.)
|
581
|
+
*/
|
582
|
+
public float multW(float x, float y, float z) {
|
583
|
+
return m30*x + m31*y + m32*z + m33;
|
584
|
+
}
|
693
585
|
|
694
|
-
/**
|
695
|
-
* Calculate the determinant of a 3x3 matrix.
|
696
|
-
*
|
697
|
-
* @return result
|
698
|
-
*/
|
699
|
-
private float determinant3x3(float t00, float t01, float t02,
|
700
|
-
float t10, float t11, float t12,
|
701
|
-
float t20, float t21, float t22) {
|
702
|
-
return (t00 * (t11 * t22 - t12 * t21)
|
703
|
-
+ t01 * (t12 * t20 - t10 * t22)
|
704
|
-
+ t02 * (t10 * t21 - t11 * t20));
|
705
|
-
}
|
706
586
|
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
- m13 * m22 * m31
|
715
|
-
- m11 * m23 * m32
|
716
|
-
- m12 * m21 * m33);
|
717
|
-
f -= m01
|
718
|
-
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
|
719
|
-
- m13 * m22 * m30
|
720
|
-
- m10 * m23 * m32
|
721
|
-
- m12 * m20 * m33);
|
722
|
-
f += m02
|
723
|
-
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
|
724
|
-
- m13 * m21 * m30
|
725
|
-
- m10 * m23 * m31
|
726
|
-
- m11 * m20 * m33);
|
727
|
-
f -= m03
|
728
|
-
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
|
729
|
-
- m12 * m21 * m30
|
730
|
-
- m10 * m22 * m31
|
731
|
-
- m11 * m20 * m32);
|
732
|
-
return f;
|
733
|
-
}
|
587
|
+
/**
|
588
|
+
* Returns the x-coordinate of the result of multiplying the vector
|
589
|
+
* (x, y, z, w) by this matrix.
|
590
|
+
*/
|
591
|
+
public float multX(float x, float y, float z, float w) {
|
592
|
+
return m00*x + m01*y + m02*z + m03*w;
|
593
|
+
}
|
734
594
|
|
735
|
-
//////////////////////////////////////////////////////////////
|
736
|
-
// REVERSE VERSIONS OF MATRIX OPERATIONS
|
737
|
-
// These functions should not be used, as they will be removed in the future.
|
738
|
-
protected void invTranslate(float tx, float ty, float tz) {
|
739
|
-
preApply(1, 0, 0, -tx,
|
740
|
-
0, 1, 0, -ty,
|
741
|
-
0, 0, 1, -tz,
|
742
|
-
0, 0, 0, 1);
|
743
|
-
}
|
744
595
|
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
596
|
+
/**
|
597
|
+
* Returns the y-coordinate of the result of multiplying the vector
|
598
|
+
* (x, y, z, w) by this matrix.
|
599
|
+
*/
|
600
|
+
public float multY(float x, float y, float z, float w) {
|
601
|
+
return m10*x + m11*y + m12*z + m13*w;
|
602
|
+
}
|
750
603
|
|
751
|
-
protected void invRotateY(float angle) {
|
752
|
-
float c = cos(-angle);
|
753
|
-
float s = sin(-angle);
|
754
|
-
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
755
|
-
}
|
756
604
|
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
605
|
+
/**
|
606
|
+
* Returns the z-coordinate of the result of multiplying the vector
|
607
|
+
* (x, y, z, w) by this matrix.
|
608
|
+
*/
|
609
|
+
public float multZ(float x, float y, float z, float w) {
|
610
|
+
return m20*x + m21*y + m22*z + m23*w;
|
611
|
+
}
|
762
612
|
|
763
|
-
protected void invRotate(float angle, float v0, float v1, float v2) {
|
764
|
-
//TODO should make sure this vector is normalized
|
765
613
|
|
766
|
-
|
767
|
-
|
768
|
-
|
614
|
+
/**
|
615
|
+
* Returns the w-coordinate of the result of multiplying the vector
|
616
|
+
* (x, y, z, w) by this matrix.
|
617
|
+
*/
|
618
|
+
public float multW(float x, float y, float z, float w) {
|
619
|
+
return m30*x + m31*y + m32*z + m33*w;
|
620
|
+
}
|
769
621
|
|
770
|
-
preApply((t * v0 * v0) + c, (t * v0 * v1) - (s * v2), (t * v0 * v2) + (s * v1), 0,
|
771
|
-
(t * v0 * v1) + (s * v2), (t * v1 * v1) + c, (t * v1 * v2) - (s * v0), 0,
|
772
|
-
(t * v0 * v2) - (s * v1), (t * v1 * v2) + (s * v0), (t * v2 * v2) + c, 0,
|
773
|
-
0, 0, 0, 1);
|
774
|
-
}
|
775
622
|
|
776
|
-
|
777
|
-
|
778
|
-
|
623
|
+
/**
|
624
|
+
* Transpose this matrix; rows become columns and columns rows.
|
625
|
+
*/
|
626
|
+
public void transpose() {
|
627
|
+
float temp;
|
628
|
+
temp = m01; m01 = m10; m10 = temp;
|
629
|
+
temp = m02; m02 = m20; m20 = temp;
|
630
|
+
temp = m03; m03 = m30; m30 = temp;
|
631
|
+
temp = m12; m12 = m21; m21 = temp;
|
632
|
+
temp = m13; m13 = m31; m31 = temp;
|
633
|
+
temp = m23; m23 = m32; m32 = temp;
|
634
|
+
}
|
635
|
+
|
779
636
|
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
637
|
+
/**
|
638
|
+
* Invert this matrix. Will not necessarily succeed, because some matrices
|
639
|
+
* map more than one point to the same image point, and so are irreversible.
|
640
|
+
* @return true if successful
|
641
|
+
*/
|
642
|
+
@Override
|
643
|
+
public boolean invert() {
|
644
|
+
float determinant = determinant();
|
645
|
+
if (determinant == 0) {
|
646
|
+
return false;
|
647
|
+
}
|
648
|
+
|
649
|
+
// first row
|
650
|
+
float t00 = determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
|
651
|
+
float t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33);
|
652
|
+
float t02 = determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33);
|
653
|
+
float t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32);
|
654
|
+
|
655
|
+
// second row
|
656
|
+
float t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33);
|
657
|
+
float t11 = determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33);
|
658
|
+
float t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33);
|
659
|
+
float t13 = determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32);
|
660
|
+
|
661
|
+
// third row
|
662
|
+
float t20 = determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33);
|
663
|
+
float t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33);
|
664
|
+
float t22 = determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33);
|
665
|
+
float t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32);
|
666
|
+
|
667
|
+
// fourth row
|
668
|
+
float t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23);
|
669
|
+
float t31 = determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23);
|
670
|
+
float t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23);
|
671
|
+
float t33 = determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
|
672
|
+
|
673
|
+
// transpose and divide by the determinant
|
674
|
+
m00 = t00 / determinant;
|
675
|
+
m01 = t10 / determinant;
|
676
|
+
m02 = t20 / determinant;
|
677
|
+
m03 = t30 / determinant;
|
678
|
+
|
679
|
+
m10 = t01 / determinant;
|
680
|
+
m11 = t11 / determinant;
|
681
|
+
m12 = t21 / determinant;
|
682
|
+
m13 = t31 / determinant;
|
683
|
+
|
684
|
+
m20 = t02 / determinant;
|
685
|
+
m21 = t12 / determinant;
|
686
|
+
m22 = t22 / determinant;
|
687
|
+
m23 = t32 / determinant;
|
688
|
+
|
689
|
+
m30 = t03 / determinant;
|
690
|
+
m31 = t13 / determinant;
|
691
|
+
m32 = t23 / determinant;
|
692
|
+
m33 = t33 / determinant;
|
693
|
+
|
694
|
+
return true;
|
695
|
+
}
|
696
|
+
|
697
|
+
|
698
|
+
/**
|
699
|
+
* Calculate the determinant of a 3x3 matrix.
|
700
|
+
* @return result
|
701
|
+
*/
|
702
|
+
private float determinant3x3(float t00, float t01, float t02,
|
703
|
+
float t10, float t11, float t12,
|
704
|
+
float t20, float t21, float t22) {
|
705
|
+
return (t00 * (t11 * t22 - t12 * t21) +
|
706
|
+
t01 * (t12 * t20 - t10 * t22) +
|
707
|
+
t02 * (t10 * t21 - t11 * t20));
|
708
|
+
}
|
709
|
+
|
710
|
+
|
711
|
+
/**
|
712
|
+
* @return the determinant of the matrix
|
713
|
+
*/
|
714
|
+
@Override
|
715
|
+
public float determinant() {
|
716
|
+
float f =
|
717
|
+
m00
|
718
|
+
* ((m11 * m22 * m33 + m12 * m23 * m31 + m13 * m21 * m32)
|
719
|
+
- m13 * m22 * m31
|
720
|
+
- m11 * m23 * m32
|
721
|
+
- m12 * m21 * m33);
|
722
|
+
f -= m01
|
723
|
+
* ((m10 * m22 * m33 + m12 * m23 * m30 + m13 * m20 * m32)
|
724
|
+
- m13 * m22 * m30
|
725
|
+
- m10 * m23 * m32
|
726
|
+
- m12 * m20 * m33);
|
727
|
+
f += m02
|
728
|
+
* ((m10 * m21 * m33 + m11 * m23 * m30 + m13 * m20 * m31)
|
729
|
+
- m13 * m21 * m30
|
730
|
+
- m10 * m23 * m31
|
731
|
+
- m11 * m20 * m33);
|
732
|
+
f -= m03
|
733
|
+
* ((m10 * m21 * m32 + m11 * m22 * m30 + m12 * m20 * m31)
|
734
|
+
- m12 * m21 * m30
|
735
|
+
- m10 * m22 * m31
|
736
|
+
- m11 * m20 * m32);
|
737
|
+
return f;
|
738
|
+
}
|
739
|
+
|
740
|
+
|
741
|
+
//////////////////////////////////////////////////////////////
|
742
|
+
|
743
|
+
// REVERSE VERSIONS OF MATRIX OPERATIONS
|
744
|
+
|
745
|
+
// These functions should not be used, as they will be removed in the future.
|
746
|
+
|
747
|
+
|
748
|
+
protected void invTranslate(float tx, float ty, float tz) {
|
749
|
+
preApply(1, 0, 0, -tx,
|
750
|
+
0, 1, 0, -ty,
|
751
|
+
0, 0, 1, -tz,
|
752
|
+
0, 0, 0, 1);
|
753
|
+
}
|
754
|
+
|
755
|
+
|
756
|
+
protected void invRotateX(float angle) {
|
757
|
+
float c = cos(-angle);
|
758
|
+
float s = sin(-angle);
|
759
|
+
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
760
|
+
}
|
761
|
+
|
762
|
+
|
763
|
+
protected void invRotateY(float angle) {
|
764
|
+
float c = cos(-angle);
|
765
|
+
float s = sin(-angle);
|
766
|
+
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
767
|
+
}
|
768
|
+
|
769
|
+
|
770
|
+
protected void invRotateZ(float angle) {
|
771
|
+
float c = cos(-angle);
|
772
|
+
float s = sin(-angle);
|
773
|
+
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
774
|
+
}
|
775
|
+
|
776
|
+
|
777
|
+
protected void invRotate(float angle, float v0, float v1, float v2) {
|
778
|
+
//TODO should make sure this vector is normalized
|
779
|
+
|
780
|
+
float c = cos(-angle);
|
781
|
+
float s = sin(-angle);
|
782
|
+
float t = 1.0f - c;
|
783
|
+
|
784
|
+
preApply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
785
|
+
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
786
|
+
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
787
|
+
0, 0, 0, 1);
|
788
|
+
}
|
789
|
+
|
790
|
+
|
791
|
+
protected void invScale(float x, float y, float z) {
|
792
|
+
preApply(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
|
793
|
+
}
|
794
|
+
|
795
|
+
|
796
|
+
protected boolean invApply(float n00, float n01, float n02, float n03,
|
797
|
+
float n10, float n11, float n12, float n13,
|
798
|
+
float n20, float n21, float n22, float n23,
|
799
|
+
float n30, float n31, float n32, float n33) {
|
800
|
+
if (inverseCopy == null) {
|
801
|
+
inverseCopy = new PMatrix3D();
|
796
802
|
}
|
803
|
+
inverseCopy.set(n00, n01, n02, n03,
|
804
|
+
n10, n11, n12, n13,
|
805
|
+
n20, n21, n22, n23,
|
806
|
+
n30, n31, n32, n33);
|
807
|
+
if (!inverseCopy.invert()) {
|
808
|
+
return false;
|
809
|
+
}
|
810
|
+
preApply(inverseCopy);
|
811
|
+
return true;
|
812
|
+
}
|
813
|
+
|
797
814
|
|
798
|
-
|
799
|
-
|
800
|
-
|
815
|
+
//////////////////////////////////////////////////////////////
|
816
|
+
|
817
|
+
|
818
|
+
public void print() {
|
819
|
+
/*
|
801
820
|
System.out.println(m00 + " " + m01 + " " + m02 + " " + m03 + "\n" +
|
802
821
|
m10 + " " + m11 + " " + m12 + " " + m13 + "\n" +
|
803
822
|
m20 + " " + m21 + " " + m22 + " " + m23 + "\n" +
|
804
823
|
m30 + " " + m31 + " " + m32 + " " + m33 + "\n");
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
System.out.println();
|
845
|
-
}
|
824
|
+
*/
|
825
|
+
int big = (int) Math.abs(max(max(max(max(abs(m00), abs(m01)),
|
826
|
+
max(abs(m02), abs(m03))),
|
827
|
+
max(max(abs(m10), abs(m11)),
|
828
|
+
max(abs(m12), abs(m13)))),
|
829
|
+
max(max(max(abs(m20), abs(m21)),
|
830
|
+
max(abs(m22), abs(m23))),
|
831
|
+
max(max(abs(m30), abs(m31)),
|
832
|
+
max(abs(m32), abs(m33))))));
|
833
|
+
|
834
|
+
int digits = 1;
|
835
|
+
if (Float.isNaN(big) || Float.isInfinite(big)) { // avoid infinite loop
|
836
|
+
digits = 5;
|
837
|
+
} else {
|
838
|
+
while ((big /= 10) != 0) digits++; // cheap log()
|
839
|
+
}
|
840
|
+
|
841
|
+
System.out.println(PApplet.nfs(m00, digits, 4) + " " +
|
842
|
+
PApplet.nfs(m01, digits, 4) + " " +
|
843
|
+
PApplet.nfs(m02, digits, 4) + " " +
|
844
|
+
PApplet.nfs(m03, digits, 4));
|
845
|
+
|
846
|
+
System.out.println(PApplet.nfs(m10, digits, 4) + " " +
|
847
|
+
PApplet.nfs(m11, digits, 4) + " " +
|
848
|
+
PApplet.nfs(m12, digits, 4) + " " +
|
849
|
+
PApplet.nfs(m13, digits, 4));
|
850
|
+
|
851
|
+
System.out.println(PApplet.nfs(m20, digits, 4) + " " +
|
852
|
+
PApplet.nfs(m21, digits, 4) + " " +
|
853
|
+
PApplet.nfs(m22, digits, 4) + " " +
|
854
|
+
PApplet.nfs(m23, digits, 4));
|
855
|
+
|
856
|
+
System.out.println(PApplet.nfs(m30, digits, 4) + " " +
|
857
|
+
PApplet.nfs(m31, digits, 4) + " " +
|
858
|
+
PApplet.nfs(m32, digits, 4) + " " +
|
859
|
+
PApplet.nfs(m33, digits, 4));
|
860
|
+
|
861
|
+
System.out.println();
|
862
|
+
}
|
846
863
|
|
847
|
-
//////////////////////////////////////////////////////////////
|
848
|
-
static private final float max(float a, float b) {
|
849
|
-
return (a > b) ? a : b;
|
850
|
-
}
|
851
864
|
|
852
|
-
|
853
|
-
return (a < 0) ? -a : a;
|
854
|
-
}
|
865
|
+
//////////////////////////////////////////////////////////////
|
855
866
|
|
856
|
-
static private final float sin(float angle) {
|
857
|
-
return (float) Math.sin(angle);
|
858
|
-
}
|
859
867
|
|
860
|
-
|
861
|
-
|
862
|
-
|
868
|
+
static private final float max(float a, float b) {
|
869
|
+
return (a > b) ? a : b;
|
870
|
+
}
|
871
|
+
|
872
|
+
static private final float abs(float a) {
|
873
|
+
return (a < 0) ? -a : a;
|
874
|
+
}
|
875
|
+
|
876
|
+
static private final float sin(float angle) {
|
877
|
+
return (float) Math.sin(angle);
|
878
|
+
}
|
879
|
+
|
880
|
+
static private final float cos(float angle) {
|
881
|
+
return (float) Math.cos(angle);
|
882
|
+
}
|
863
883
|
}
|