toxiclibs 0.9.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,29 @@
1
1
  /*
2
- * __ .__ .__ ._____.
2
+ * __ .__ .__ ._____.
3
3
  * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4
4
  * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5
- * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
5
+ * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6
6
  * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7
- * \/ \/ \/ \/
7
+ * \/ \/ \/ \/
8
8
  *
9
9
  * Copyright (c) 2006-2011 Karsten Schmidt
10
- *
10
+ *
11
11
  * This library is free software; you can redistribute it and/or
12
12
  * modify it under the terms of the GNU Lesser General Public
13
13
  * License as published by the Free Software Foundation; either
14
14
  * version 2.1 of the License, or (at your option) any later version.
15
- *
15
+ *
16
16
  * http://creativecommons.org/licenses/LGPL/2.1/
17
- *
17
+ *
18
18
  * This library is distributed in the hope that it will be useful,
19
19
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
21
  * Lesser General Public License for more details.
22
- *
22
+ *
23
23
  * You should have received a copy of the GNU Lesser General Public
24
24
  * License along with this library; if not, write to the Free Software
25
25
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26
26
  */
27
-
28
27
  package toxi.geom;
29
28
 
30
29
  import toxi.math.MathUtils;
@@ -46,13 +45,13 @@ public class Matrix4x4 {
46
45
  * the row permutations resulting from partial pivoting. The output
47
46
  * parameter "even_row_xchg" is 1 when the number of row exchanges is even,
48
47
  * or -1 otherwise. Assumes data type is always double.
49
- *
48
+ *
50
49
  * This function is similar to luDecomposition, except that it is tuned
51
50
  * specifically for 4x4 matrices.
52
- *
51
+ *
53
52
  * Reference: Press, Flannery, Teukolsky, Vetterling,
54
53
  * _Numerical_Recipes_in_C_, Cambridge University Press, 1988, pp 40-45.
55
- *
54
+ *
56
55
  * @param matrix0
57
56
  * @param row_perm
58
57
  * @param width
@@ -253,7 +252,7 @@ public class Matrix4x4 {
253
252
  /**
254
253
  * Initialising constructor from a 1d array. Assumes row-major ordering
255
254
  * (column index increases faster).
256
- *
255
+ *
257
256
  * @param array
258
257
  */
259
258
  public Matrix4x4(double[] array) {
@@ -346,7 +345,7 @@ public class Matrix4x4 {
346
345
 
347
346
  /**
348
347
  * Creates a copy of the given vector, transformed by this matrix.
349
- *
348
+ *
350
349
  * @param v
351
350
  * @return transformed vector
352
351
  */
@@ -452,8 +451,8 @@ public class Matrix4x4 {
452
451
  }
453
452
 
454
453
  private void init() {
455
- matrix = new double[][] {
456
- new double[4], new double[4], new double[4], new double[4]
454
+ matrix = new double[][]{
455
+ new double[4], new double[4], new double[4], new double[4]
457
456
  };
458
457
  }
459
458
 
@@ -461,7 +460,7 @@ public class Matrix4x4 {
461
460
  * Matrix Inversion using Cramer's Method Computes Adjoint matrix divided by
462
461
  * determinant Code modified from
463
462
  * http://www.intel.com/design/pentiumiii/sml/24504301.pdf
464
- *
463
+ *
465
464
  * @return itself
466
465
  */
467
466
  public Matrix4x4 invert() {
@@ -585,20 +584,19 @@ public class Matrix4x4 {
585
584
  return set(s.x, s.y, s.z, -s.dot(eye), t.x, t.y, t.z, -t.dot(eye), f.x,
586
585
  f.y, f.z, -f.dot(eye), 0, 0, 0, 1);
587
586
  }
588
-
587
+
589
588
  /**
590
- *
589
+ *
591
590
  * @param factor
592
- * @return
591
+ * @return
593
592
  */
594
-
595
593
  public Matrix4x4 multiply(double factor) {
596
594
  return new Matrix4x4(this).multiplySelf(factor);
597
595
  }
598
596
 
599
597
  /**
600
598
  * Matrix-Matrix Right-multiplication.
601
- *
599
+ *
602
600
  * @param mat
603
601
  * @return product as new matrix
604
602
  */
@@ -608,7 +606,7 @@ public class Matrix4x4 {
608
606
 
609
607
  /**
610
608
  * In-place matrix-scalar multiplication.
611
- *
609
+ *
612
610
  * @param factor
613
611
  * @return product applied to this matrix.
614
612
  */
@@ -649,7 +647,7 @@ public class Matrix4x4 {
649
647
 
650
648
  /**
651
649
  * Applies rotation about arbitrary axis to matrix
652
- *
650
+ *
653
651
  * @param axis
654
652
  * @param theta
655
653
  * @return rotation applied to this matrix
@@ -672,9 +670,8 @@ public class Matrix4x4 {
672
670
 
673
671
  /**
674
672
  * Applies rotation about X to this matrix.
675
- *
676
- * @param theta
677
- * rotation angle in radians
673
+ *
674
+ * @param theta rotation angle in radians
678
675
  * @return itself
679
676
  */
680
677
  public Matrix4x4 rotateX(double theta) {
@@ -687,9 +684,8 @@ public class Matrix4x4 {
687
684
 
688
685
  /**
689
686
  * Applies rotation about Y to this matrix.
690
- *
691
- * @param theta
692
- * rotation angle in radians
687
+ *
688
+ * @param theta rotation angle in radians
693
689
  * @return itself
694
690
  */
695
691
  public Matrix4x4 rotateY(double theta) {
@@ -701,13 +697,12 @@ public class Matrix4x4 {
701
697
  }
702
698
 
703
699
  // Apply Rotation about Z to Matrix
704
-
705
700
  /**
706
701
  *
707
702
  * @param theta
708
703
  * @return
709
704
  */
710
- public Matrix4x4 rotateZ(double theta) {
705
+ public Matrix4x4 rotateZ(double theta) {
711
706
  TEMP.identity();
712
707
  TEMP.matrix[0][0] = TEMP.matrix[1][1] = Math.cos(theta);
713
708
  TEMP.matrix[1][0] = Math.sin(theta);
@@ -853,7 +848,7 @@ public class Matrix4x4 {
853
848
  return set((2.0 * near) / (right - left), 0, (left + right)
854
849
  / (right - left), 0, 0, (2.0 * near) / (top - bottom),
855
850
  (top + bottom) / (top - bottom), 0, 0, 0, -(near + far)
856
- / (far - near), (-2 * near * far) / (far - near), 0, 0,
851
+ / (far - near), (-2 * near * far) / (far - near), 0, 0,
857
852
  -1, 0);
858
853
  }
859
854
 
@@ -945,9 +940,8 @@ public class Matrix4x4 {
945
940
 
946
941
  /**
947
942
  * Copies all matrix elements into an linear array.
948
- *
949
- * @param result
950
- * array (or null to create a new one)
943
+ *
944
+ * @param result array (or null to create a new one)
951
945
  * @return matrix as 16 element array
952
946
  */
953
947
  public double[] toArray(double[] result) {
@@ -981,24 +975,25 @@ public class Matrix4x4 {
981
975
 
982
976
  /*
983
977
  * (non-Javadoc)
984
- *
978
+ *
985
979
  * @see java.lang.Object#toString()
986
980
  */
987
-
988
981
  /**
989
982
  *
990
983
  * @return
991
984
  */
992
-
993
985
  @Override
994
986
  public String toString() {
995
- return "| " + matrix[0][0] + " " + matrix[0][1] + " " + matrix[0][2]
996
- + " " + matrix[0][3] + " |\n" + "| " + matrix[1][0] + " "
997
- + matrix[1][1] + " " + matrix[1][2] + " " + matrix[1][3]
998
- + " |\n" + "| " + matrix[2][0] + " " + matrix[2][1] + " "
999
- + matrix[2][2] + " " + matrix[2][3] + " |\n" + "| "
1000
- + matrix[3][0] + " " + matrix[3][1] + " " + matrix[3][2] + " "
1001
- + matrix[3][3] + " |";
987
+ return String.join("\n",
988
+ String.format("| %f %f %f %f |",
989
+ matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3]),
990
+ String.format("| %f %f %f %f |",
991
+ matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3]),
992
+ String.format("| %f %f %f %f |",
993
+ matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]),
994
+ String.format("| %f %f %f %f |",
995
+ matrix[3][0], matrix[3][1], matrix[3][2], matrix[3][3])
996
+ );
1002
997
  }
1003
998
 
1004
999
  /**
@@ -1064,7 +1059,7 @@ public class Matrix4x4 {
1064
1059
  /**
1065
1060
  * Converts the matrix (in-place) between column-major to row-major order
1066
1061
  * (and vice versa).
1067
- *
1062
+ *
1068
1063
  * @return itself
1069
1064
  */
1070
1065
  public Matrix4x4 transpose() {
@@ -1073,4 +1068,4 @@ public class Matrix4x4 {
1073
1068
  matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],
1074
1069
  matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]);
1075
1070
  }
1076
- }
1071
+ }
@@ -1,30 +1,29 @@
1
1
  /*
2
- * __ .__ .__ ._____.
2
+ * __ .__ .__ ._____.
3
3
  * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4
4
  * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5
- * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
5
+ * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6
6
  * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7
- * \/ \/ \/ \/
7
+ * \/ \/ \/ \/
8
8
  *
9
9
  * Copyright (c) 2006-2011 Karsten Schmidt
10
- *
10
+ *
11
11
  * This library is free software; you can redistribute it and/or
12
12
  * modify it under the terms of the GNU Lesser General Public
13
13
  * License as published by the Free Software Foundation; either
14
14
  * version 2.1 of the License, or (at your option) any later version.
15
- *
15
+ *
16
16
  * http://creativecommons.org/licenses/LGPL/2.1/
17
- *
17
+ *
18
18
  * This library is distributed in the hope that it will be useful,
19
19
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
21
  * Lesser General Public License for more details.
22
- *
22
+ *
23
23
  * You should have received a copy of the GNU Lesser General Public
24
24
  * License along with this library; if not, write to the Free Software
25
25
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26
26
  */
27
-
28
27
  package toxi.geom;
29
28
 
30
29
  import javax.xml.bind.annotation.XmlAccessType;
@@ -47,12 +46,10 @@ public class Quaternion {
47
46
 
48
47
  /**
49
48
  * Creates a Quaternion from a axis and a angle.
50
- *
51
- * @param axis
52
- * axis vector (will be normalized)
53
- * @param angle
54
- * angle in radians.
55
- *
49
+ *
50
+ * @param axis axis vector (will be normalized)
51
+ * @param angle angle in radians.
52
+ *
56
53
  * @return new quaternion
57
54
  */
58
55
  public static Quaternion createFromAxisAngle(ReadonlyVec3D axis, float angle) {
@@ -65,14 +62,11 @@ public class Quaternion {
65
62
 
66
63
  /**
67
64
  * Creates a Quaternion from Euler angles.
68
- *
69
- * @param pitch
70
- * X-angle in radians.
71
- * @param yaw
72
- * Y-angle in radians.
73
- * @param roll
74
- * Z-angle in radians.
75
- *
65
+ *
66
+ * @param pitch X-angle in radians.
67
+ * @param yaw Y-angle in radians.
68
+ * @param roll Z-angle in radians.
69
+ *
76
70
  * @return new quaternion
77
71
  */
78
72
  public static Quaternion createFromEuler(float pitch, float yaw, float roll) {
@@ -110,7 +104,6 @@ public class Quaternion {
110
104
  // x =c1c2*s3 + s1s2*c3;
111
105
  // y =s1*c2*c3 + c1*s2*s3;
112
106
  // z =c1*s2*c3 - s1*c2*s3;
113
-
114
107
  return q;
115
108
  }
116
109
 
@@ -118,9 +111,8 @@ public class Quaternion {
118
111
  * Creates a quaternion from a rotation matrix. The algorithm used is from
119
112
  * Allan and Mark Watt's "Advanced Animation and Rendering Techniques" (ACM
120
113
  * Press 1992).
121
- *
122
- * @param m
123
- * rotation matrix
114
+ *
115
+ * @param m rotation matrix
124
116
  * @return quaternion
125
117
  */
126
118
  public static Quaternion createFromMatrix(Matrix4x4 m) {
@@ -135,8 +127,8 @@ public class Quaternion {
135
127
  q[2] = (m.matrix[1][0] - m.matrix[0][1]) * s;
136
128
  q[3] = 0.25 / s;
137
129
  } else {
138
- int[] nxt = new int[] {
139
- 1, 2, 0
130
+ int[] nxt = new int[]{
131
+ 1, 2, 0
140
132
  };
141
133
  int i = 0, j = 0, k = 0;
142
134
 
@@ -167,7 +159,7 @@ public class Quaternion {
167
159
  /**
168
160
  * Constructs a quaternion that rotates the vector given by the "forward"
169
161
  * param into the direction given by the "dir" param.
170
- *
162
+ *
171
163
  * @param dir
172
164
  * @param forward
173
165
  * @return quaternion
@@ -183,25 +175,21 @@ public class Quaternion {
183
175
 
184
176
  @XmlAttribute(required = true)
185
177
  public float x,
186
-
187
- /**
188
- *
189
- */
190
-
191
- /**
192
- *
193
- */
194
- y,
195
-
196
- /**
197
- *
198
- */
199
- z,
200
-
201
- /**
202
- *
203
- */
204
- w;
178
+ /**
179
+ *
180
+ */
181
+ /**
182
+ *
183
+ */
184
+ y,
185
+ /**
186
+ *
187
+ */
188
+ z,
189
+ /**
190
+ *
191
+ */
192
+ w;
205
193
 
206
194
  /**
207
195
  *
@@ -296,7 +284,7 @@ public class Quaternion {
296
284
 
297
285
  /**
298
286
  * Computes the dot product with the given quaternion.
299
- *
287
+ *
300
288
  * @param q
301
289
  * @return dot product
302
290
  */
@@ -307,7 +295,7 @@ public class Quaternion {
307
295
  /**
308
296
  * Computes this quaternion's conjugate, defined as the same w around the
309
297
  * inverted axis.
310
- *
298
+ *
311
299
  * @return new conjugate quaternion
312
300
  */
313
301
  public Quaternion getConjugate() {
@@ -330,7 +318,7 @@ public class Quaternion {
330
318
 
331
319
  /**
332
320
  * Computes normalized version of this quaternion.
333
- *
321
+ *
334
322
  * @return new normalized quaternion
335
323
  */
336
324
  public Quaternion getNormalized() {
@@ -341,7 +329,7 @@ public class Quaternion {
341
329
  *
342
330
  * @return
343
331
  */
344
- public Quaternion identity() {
332
+ public final Quaternion identity() {
345
333
  w = 1.0f;
346
334
  x = 0.0f;
347
335
  y = 0.0f;
@@ -353,11 +341,9 @@ public class Quaternion {
353
341
  * Spherical interpolation to target quaternion (code ported from <a href=
354
342
  * "http://www.gamasutra.com/view/feature/3278/rotating_objects_using_quaternions.php"
355
343
  * >GamaSutra</a>)
356
- *
357
- * @param target
358
- * quaternion
359
- * @param t
360
- * interpolation factor (0..1)
344
+ *
345
+ * @param target quaternion
346
+ * @param t interpolation factor (0..1)
361
347
  * @return new interpolated quat
362
348
  */
363
349
  public Quaternion interpolateTo(Quaternion target, float t) {
@@ -379,11 +365,9 @@ public class Quaternion {
379
365
  * Spherical interpolation to target quaternion (code ported from <a href=
380
366
  * "http://www.gamasutra.com/view/feature/3278/rotating_objects_using_quaternions.php"
381
367
  * >GamaSutra</a>)
382
- *
383
- * @param target
384
- * quaternion
385
- * @param t
386
- * interpolation factor (0..1)
368
+ *
369
+ * @param target quaternion
370
+ * @param t interpolation factor (0..1)
387
371
  * @return new interpolated quat
388
372
  */
389
373
  public Quaternion interpolateToSelf(Quaternion target, double t) {
@@ -417,7 +401,7 @@ public class Quaternion {
417
401
  * Uses spherical interpolation to approach the target quaternion. The
418
402
  * interpolation factor is manipulated by the chosen
419
403
  * {@link InterpolateStrategy} first.
420
- *
404
+ *
421
405
  * @param target
422
406
  * @param t
423
407
  * @param is
@@ -559,15 +543,15 @@ public class Quaternion {
559
543
  * @return
560
544
  */
561
545
  public float[] toArray() {
562
- return new float[] {
563
- w, x, y, z
546
+ return new float[]{
547
+ w, x, y, z
564
548
  };
565
549
  }
566
550
 
567
551
  /**
568
552
  * Converts the quaternion into a float array consisting of: rotation angle
569
553
  * in radians, rotation axis x,y,z
570
- *
554
+ *
571
555
  * @return 4-element float array
572
556
  */
573
557
  public float[] toAxisAngle() {
@@ -589,7 +573,7 @@ public class Quaternion {
589
573
  * Converts the quat to a 4x4 rotation matrix (in row-major format). Assumes
590
574
  * the quat is currently normalized (if not, you'll need to call
591
575
  * {@link #normalize()} first).
592
- *
576
+ *
593
577
  * @return result matrix
594
578
  */
595
579
  public Matrix4x4 toMatrix4x4() {
@@ -633,9 +617,6 @@ public class Quaternion {
633
617
  */
634
618
  @Override
635
619
  public String toString() {
636
- StringBuilder sb = new StringBuilder(48);
637
- sb.append("{axis: [").append(x).append(",").append(y).append(",")
638
- .append(z).append("], w: ").append(w).append("}");
639
- return sb.toString();
620
+ return String.format("{axis: [%f, %f, %f], w: %f}", x, y, z, w);
640
621
  }
641
622
  }