propane 2.7.2-java → 2.8.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -0
  3. data/CHANGELOG.md +1 -1
  4. data/README.md +10 -8
  5. data/Rakefile +1 -1
  6. data/lib/propane/app.rb +3 -3
  7. data/lib/propane/version.rb +1 -1
  8. data/lib/{processing-core.jar → propane-2.8.0.jar} +0 -0
  9. data/library/control_panel/control_panel.rb +3 -2
  10. data/pom.rb +89 -88
  11. data/pom.xml +75 -46
  12. data/propane.gemspec +1 -2
  13. data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
  14. data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  15. data/src/{monkstone → main/java/monkstone}/ColorUtil.java +0 -0
  16. data/src/{monkstone → main/java/monkstone}/MathToolModule.java +0 -0
  17. data/src/{monkstone → main/java/monkstone}/PropaneLibrary.java +0 -0
  18. data/src/{monkstone → main/java/monkstone}/core/LibraryProxy.java +0 -0
  19. data/src/{monkstone → main/java/monkstone}/fastmath/Deglut.java +0 -0
  20. data/src/{monkstone → main/java/monkstone}/fastmath/package-info.java +0 -0
  21. data/src/{monkstone → main/java/monkstone}/filechooser/Chooser.java +0 -0
  22. data/src/{monkstone → main/java/monkstone}/noise/SimplexNoise.java +0 -0
  23. data/src/{monkstone → main/java/monkstone}/slider/CustomHorizontalSlider.java +0 -0
  24. data/src/{monkstone → main/java/monkstone}/slider/CustomVerticalSlider.java +0 -0
  25. data/src/{monkstone → main/java/monkstone}/slider/SimpleHorizontalSlider.java +0 -0
  26. data/src/{monkstone → main/java/monkstone}/slider/SimpleSlider.java +0 -0
  27. data/src/{monkstone → main/java/monkstone}/slider/SimpleVerticalSlider.java +0 -0
  28. data/src/{monkstone → main/java/monkstone}/slider/Slider.java +0 -0
  29. data/src/{monkstone → main/java/monkstone}/slider/SliderBar.java +0 -0
  30. data/src/{monkstone → main/java/monkstone}/slider/SliderGroup.java +0 -0
  31. data/src/{monkstone → main/java/monkstone}/slider/WheelHandler.java +0 -0
  32. data/src/{monkstone → main/java/monkstone}/vecmath/AppRender.java +0 -0
  33. data/src/{monkstone → main/java/monkstone}/vecmath/JRender.java +0 -0
  34. data/src/{monkstone → main/java/monkstone}/vecmath/ShapeRender.java +0 -0
  35. data/src/{monkstone → main/java/monkstone}/vecmath/package-info.java +0 -0
  36. data/src/{monkstone → main/java/monkstone}/vecmath/vec2/Vec2.java +0 -0
  37. data/src/{monkstone → main/java/monkstone}/vecmath/vec2/package-info.java +0 -0
  38. data/src/{monkstone → main/java/monkstone}/vecmath/vec3/Vec3.java +0 -0
  39. data/src/{monkstone → main/java/monkstone}/vecmath/vec3/package-info.java +0 -0
  40. data/src/{monkstone → main/java/monkstone}/videoevent/VideoInterface.java +0 -0
  41. data/src/{monkstone → main/java/monkstone}/videoevent/package-info.java +0 -0
  42. data/src/main/java/processing/awt/PGraphicsJava2D.java +3029 -0
  43. data/src/main/java/processing/awt/PShapeJava2D.java +377 -0
  44. data/src/main/java/processing/awt/PSurfaceAWT.java +1567 -0
  45. data/src/main/java/processing/core/PApplet.java +15709 -0
  46. data/src/main/java/processing/core/PConstants.java +527 -0
  47. data/src/main/java/processing/core/PFont.java +1098 -0
  48. data/src/main/java/processing/core/PGraphics.java +8467 -0
  49. data/src/main/java/processing/core/PImage.java +3438 -0
  50. data/src/main/java/processing/core/PMatrix.java +208 -0
  51. data/src/main/java/processing/core/PMatrix2D.java +534 -0
  52. data/src/main/java/processing/core/PMatrix3D.java +877 -0
  53. data/src/main/java/processing/core/PShape.java +3445 -0
  54. data/src/main/java/processing/core/PShapeOBJ.java +469 -0
  55. data/src/main/java/processing/core/PShapeSVG.java +1787 -0
  56. data/src/main/java/processing/core/PStyle.java +63 -0
  57. data/src/main/java/processing/core/PSurface.java +161 -0
  58. data/src/main/java/processing/core/PSurfaceNone.java +374 -0
  59. data/src/main/java/processing/core/PVector.java +1063 -0
  60. data/src/main/java/processing/data/FloatDict.java +829 -0
  61. data/src/main/java/processing/data/FloatList.java +912 -0
  62. data/src/main/java/processing/data/IntDict.java +796 -0
  63. data/src/main/java/processing/data/IntList.java +913 -0
  64. data/src/main/java/processing/data/JSONArray.java +1260 -0
  65. data/src/main/java/processing/data/JSONObject.java +2282 -0
  66. data/src/main/java/processing/data/JSONTokener.java +435 -0
  67. data/src/main/java/processing/data/Sort.java +46 -0
  68. data/src/main/java/processing/data/StringDict.java +601 -0
  69. data/src/main/java/processing/data/StringList.java +775 -0
  70. data/src/main/java/processing/data/Table.java +4923 -0
  71. data/src/main/java/processing/data/TableRow.java +198 -0
  72. data/src/main/java/processing/data/XML.java +1149 -0
  73. data/src/main/java/processing/event/Event.java +125 -0
  74. data/src/main/java/processing/event/KeyEvent.java +70 -0
  75. data/src/main/java/processing/event/MouseEvent.java +149 -0
  76. data/src/main/java/processing/event/TouchEvent.java +57 -0
  77. data/src/main/java/processing/opengl/FontTexture.java +379 -0
  78. data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
  79. data/src/main/java/processing/opengl/LinePath.java +623 -0
  80. data/src/main/java/processing/opengl/LineStroker.java +685 -0
  81. data/src/main/java/processing/opengl/PGL.java +3366 -0
  82. data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
  83. data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
  84. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
  85. data/src/main/java/processing/opengl/PJOGL.java +1966 -0
  86. data/src/main/java/processing/opengl/PShader.java +1478 -0
  87. data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
  88. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
  89. data/src/main/java/processing/opengl/Texture.java +1670 -0
  90. data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
  91. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  92. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  93. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  94. data/src/main/java/processing/opengl/cursors/license.txt +27 -0
  95. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  96. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  97. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  98. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  99. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  100. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  101. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
  102. data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
  103. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  104. data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
  105. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  106. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  107. data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
  108. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  109. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  110. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
  111. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  112. data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
  113. data/src/main/resources/icon/icon-1024.png +0 -0
  114. data/src/main/resources/icon/icon-128.png +0 -0
  115. data/src/main/resources/icon/icon-16.png +0 -0
  116. data/src/main/resources/icon/icon-256.png +0 -0
  117. data/src/main/resources/icon/icon-32.png +0 -0
  118. data/src/main/resources/icon/icon-48.png +0 -0
  119. data/src/main/resources/icon/icon-512.png +0 -0
  120. data/src/main/resources/icon/icon-64.png +0 -0
  121. data/src/main/resources/license.txt +508 -0
  122. data/vendors/Rakefile +5 -20
  123. metadata +115 -33
  124. data/lib/propane.jar +0 -0
@@ -0,0 +1,1063 @@
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) 2012-17 The Processing Foundation
7
+ Copyright (c) 2008-12 Ben Fry and Casey Reas
8
+ Copyright (c) 2008 Dan Shiffman
9
+
10
+ This library is free software; you can redistribute it and/or
11
+ modify it under the terms of the GNU Lesser General Public
12
+ License version 2.1 as published by the Free Software Foundation.
13
+
14
+ This library is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ Lesser General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Lesser General
20
+ Public License along with this library; if not, write to the
21
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
+ Boston, MA 02111-1307 USA
23
+ */
24
+
25
+ package processing.core;
26
+
27
+ import java.io.Serializable;
28
+
29
+ import processing.core.PApplet;
30
+ import processing.core.PConstants;
31
+
32
+ /**
33
+ * ( begin auto-generated from PVector.xml )
34
+ *
35
+ * A class to describe a two or three dimensional vector. This datatype
36
+ * stores two or three variables that are commonly used as a position,
37
+ * velocity, and/or acceleration. Technically, <em>position</em> is a point
38
+ * and <em>velocity</em> and <em>acceleration</em> are vectors, but this is
39
+ * often simplified to consider all three as vectors. For example, if you
40
+ * consider a rectangle moving across the screen, at any given instant it
41
+ * has a position (the object's location, expressed as a point.), a
42
+ * velocity (the rate at which the object's position changes per time unit,
43
+ * expressed as a vector), and acceleration (the rate at which the object's
44
+ * velocity changes per time unit, expressed as a vector). Since vectors
45
+ * represent groupings of values, we cannot simply use traditional
46
+ * addition/multiplication/etc. Instead, we'll need to do some "vector"
47
+ * math, which is made easy by the methods inside the <b>PVector</b>
48
+ * class.<br />
49
+ * <br />
50
+ * The methods for this class are extensive. For a complete list, visit the
51
+ * <a
52
+ * href="http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/">developer's reference.</a>
53
+ *
54
+ * ( end auto-generated )
55
+ *
56
+ * A class to describe a two or three dimensional vector.
57
+ * <p>
58
+ * The result of all functions are applied to the vector itself, with the
59
+ * exception of cross(), which returns a new PVector (or writes to a specified
60
+ * 'target' PVector). That is, add() will add the contents of one vector to
61
+ * this one. Using add() with additional parameters allows you to put the
62
+ * result into a new PVector. Functions that act on multiple vectors also
63
+ * include static versions. Because creating new objects can be computationally
64
+ * expensive, most functions include an optional 'target' PVector, so that a
65
+ * new PVector object is not created with each operation.
66
+ * <p>
67
+ * Initially based on the Vector3D class by <a href="http://www.shiffman.net">Dan Shiffman</a>.
68
+ *
69
+ * @webref math
70
+ */
71
+ public class PVector implements Serializable {
72
+ /**
73
+ * ( begin auto-generated from PVector_x.xml )
74
+ *
75
+ * The x component of the vector. This field (variable) can be used to both
76
+ * get and set the value (see above example.)
77
+ *
78
+ * ( end auto-generated )
79
+ *
80
+ * @webref pvector:field
81
+ * @usage web_application
82
+ * @brief The x component of the vector
83
+ */
84
+ public float x;
85
+
86
+ /**
87
+ * ( begin auto-generated from PVector_y.xml )
88
+ *
89
+ * The y component of the vector. This field (variable) can be used to both
90
+ * get and set the value (see above example.)
91
+ *
92
+ * ( end auto-generated )
93
+ *
94
+ * @webref pvector:field
95
+ * @usage web_application
96
+ * @brief The y component of the vector
97
+ */
98
+ public float y;
99
+
100
+ /**
101
+ * ( begin auto-generated from PVector_z.xml )
102
+ *
103
+ * The z component of the vector. This field (variable) can be used to both
104
+ * get and set the value (see above example.)
105
+ *
106
+ * ( end auto-generated )
107
+ *
108
+ * @webref pvector:field
109
+ * @usage web_application
110
+ * @brief The z component of the vector
111
+ */
112
+ public float z;
113
+
114
+ /** Array so that this can be temporarily used in an array context */
115
+ transient protected float[] array;
116
+
117
+
118
+ /**
119
+ * Constructor for an empty vector: x, y, and z are set to 0.
120
+ */
121
+ public PVector() {
122
+ }
123
+
124
+
125
+ /**
126
+ * Constructor for a 3D vector.
127
+ *
128
+ * @param x the x coordinate.
129
+ * @param y the y coordinate.
130
+ * @param z the z coordinate.
131
+ */
132
+ public PVector(float x, float y, float z) {
133
+ this.x = x;
134
+ this.y = y;
135
+ this.z = z;
136
+ }
137
+
138
+
139
+ /**
140
+ * Constructor for a 2D vector: z coordinate is set to 0.
141
+ */
142
+ public PVector(float x, float y) {
143
+ this.x = x;
144
+ this.y = y;
145
+ }
146
+
147
+
148
+ /**
149
+ * ( begin auto-generated from PVector_set.xml )
150
+ *
151
+ * Sets the x, y, and z component of the vector using two or three separate
152
+ * variables, the data from a PVector, or the values from a float array.
153
+ *
154
+ * ( end auto-generated )
155
+ *
156
+ * @webref pvector:method
157
+ * @param x the x component of the vector
158
+ * @param y the y component of the vector
159
+ * @param z the z component of the vector
160
+ * @brief Set the components of the vector
161
+ */
162
+ public PVector set(float x, float y, float z) {
163
+ this.x = x;
164
+ this.y = y;
165
+ this.z = z;
166
+ return this;
167
+ }
168
+
169
+
170
+ /**
171
+ * @param x the x component of the vector
172
+ * @param y the y component of the vector
173
+ */
174
+ public PVector set(float x, float y) {
175
+ this.x = x;
176
+ this.y = y;
177
+ this.z = 0;
178
+ return this;
179
+ }
180
+
181
+
182
+ /**
183
+ * @param v any variable of type PVector
184
+ */
185
+ public PVector set(PVector v) {
186
+ x = v.x;
187
+ y = v.y;
188
+ z = v.z;
189
+ return this;
190
+ }
191
+
192
+
193
+ /**
194
+ * Set the x, y (and maybe z) coordinates using a float[] array as the source.
195
+ * @param source array to copy from
196
+ */
197
+ public PVector set(float[] source) {
198
+ if (source.length >= 2) {
199
+ x = source[0];
200
+ y = source[1];
201
+ }
202
+ if (source.length >= 3) {
203
+ z = source[2];
204
+ } else {
205
+ z = 0;
206
+ }
207
+ return this;
208
+ }
209
+
210
+
211
+ /**
212
+ * ( begin auto-generated from PVector_random2D.xml )
213
+ *
214
+ * Make a new 2D unit vector with a random direction. If you pass in "this"
215
+ * as an argument, it will use the PApplet's random number generator. You can
216
+ * also pass in a target PVector to fill.
217
+ *
218
+ * @webref pvector:method
219
+ * @usage web_application
220
+ * @return the random PVector
221
+ * @brief Make a new 2D unit vector with a random direction.
222
+ * @see PVector#random3D()
223
+ */
224
+ static public PVector random2D() {
225
+ return random2D(null, null);
226
+ }
227
+
228
+
229
+ /**
230
+ * Make a new 2D unit vector with a random direction
231
+ * using Processing's current random number generator
232
+ * @param parent current PApplet instance
233
+ * @return the random PVector
234
+ */
235
+ static public PVector random2D(PApplet parent) {
236
+ return random2D(null, parent);
237
+ }
238
+
239
+ /**
240
+ * Set a 2D vector to a random unit vector with a random direction
241
+ * @param target the target vector (if null, a new vector will be created)
242
+ * @return the random PVector
243
+ */
244
+ static public PVector random2D(PVector target) {
245
+ return random2D(target, null);
246
+ }
247
+
248
+
249
+ /**
250
+ * Make a new 2D unit vector with a random direction. Pass in the parent
251
+ * PApplet if you want randomSeed() to work (and be predictable). Or leave
252
+ * it null and be... random.
253
+ * @return the random PVector
254
+ */
255
+ static public PVector random2D(PVector target, PApplet parent) {
256
+ return (parent == null) ?
257
+ fromAngle((float) (Math.random() * Math.PI*2), target) :
258
+ fromAngle(parent.random(PConstants.TAU), target);
259
+ }
260
+
261
+
262
+ /**
263
+ * ( begin auto-generated from PVector_random3D.xml )
264
+ *
265
+ * Make a new 3D unit vector with a random direction. If you pass in "this"
266
+ * as an argument, it will use the PApplet's random number generator. You can
267
+ * also pass in a target PVector to fill.
268
+ *
269
+ * @webref pvector:method
270
+ * @usage web_application
271
+ * @return the random PVector
272
+ * @brief Make a new 3D unit vector with a random direction.
273
+ * @see PVector#random2D()
274
+ */
275
+ static public PVector random3D() {
276
+ return random3D(null, null);
277
+ }
278
+
279
+
280
+ /**
281
+ * Make a new 3D unit vector with a random direction
282
+ * using Processing's current random number generator
283
+ * @param parent current PApplet instance
284
+ * @return the random PVector
285
+ */
286
+ static public PVector random3D(PApplet parent) {
287
+ return random3D(null, parent);
288
+ }
289
+
290
+
291
+ /**
292
+ * Set a 3D vector to a random unit vector with a random direction
293
+ * @param target the target vector (if null, a new vector will be created)
294
+ * @return the random PVector
295
+ */
296
+ static public PVector random3D(PVector target) {
297
+ return random3D(target, null);
298
+ }
299
+
300
+
301
+ /**
302
+ * Make a new 3D unit vector with a random direction
303
+ * @return the random PVector
304
+ */
305
+ static public PVector random3D(PVector target, PApplet parent) {
306
+ float angle;
307
+ float vz;
308
+ if (parent == null) {
309
+ angle = (float) (Math.random()*Math.PI*2);
310
+ vz = (float) (Math.random()*2-1);
311
+ } else {
312
+ angle = parent.random(PConstants.TWO_PI);
313
+ vz = parent.random(-1,1);
314
+ }
315
+ float vx = (float) (Math.sqrt(1-vz*vz)*Math.cos(angle));
316
+ float vy = (float) (Math.sqrt(1-vz*vz)*Math.sin(angle));
317
+ if (target == null) {
318
+ target = new PVector(vx, vy, vz);
319
+ //target.normalize(); // Should be unnecessary
320
+ } else {
321
+ target.set(vx,vy,vz);
322
+ }
323
+ return target;
324
+ }
325
+
326
+
327
+ /**
328
+ * ( begin auto-generated from PVector_sub.xml )
329
+ *
330
+ * Make a new 2D unit vector from an angle.
331
+ *
332
+ * ( end auto-generated )
333
+ *
334
+ * @webref pvector:method
335
+ * @usage web_application
336
+ * @brief Make a new 2D unit vector from an angle
337
+ * @param angle the angle in radians
338
+ * @return the new unit PVector
339
+ */
340
+ static public PVector fromAngle(float angle) {
341
+ return fromAngle(angle,null);
342
+ }
343
+
344
+
345
+ /**
346
+ * Make a new 2D unit vector from an angle
347
+ *
348
+ * @param target the target vector (if null, a new vector will be created)
349
+ * @return the PVector
350
+ */
351
+ static public PVector fromAngle(float angle, PVector target) {
352
+ if (target == null) {
353
+ target = new PVector((float)Math.cos(angle),(float)Math.sin(angle),0);
354
+ } else {
355
+ target.set((float)Math.cos(angle),(float)Math.sin(angle),0);
356
+ }
357
+ return target;
358
+ }
359
+
360
+
361
+ /**
362
+ * ( begin auto-generated from PVector_copy.xml )
363
+ *
364
+ * Gets a copy of the vector, returns a PVector object.
365
+ *
366
+ * ( end auto-generated )
367
+ *
368
+ * @webref pvector:method
369
+ * @usage web_application
370
+ * @brief Get a copy of the vector
371
+ */
372
+ public PVector copy() {
373
+ return new PVector(x, y, z);
374
+ }
375
+
376
+
377
+ @Deprecated
378
+ public PVector get() {
379
+ return copy();
380
+ }
381
+
382
+
383
+ /**
384
+ * @param target
385
+ */
386
+ public float[] get(float[] target) {
387
+ if (target == null) {
388
+ return new float[] { x, y, z };
389
+ }
390
+ if (target.length >= 2) {
391
+ target[0] = x;
392
+ target[1] = y;
393
+ }
394
+ if (target.length >= 3) {
395
+ target[2] = z;
396
+ }
397
+ return target;
398
+ }
399
+
400
+
401
+ /**
402
+ * ( begin auto-generated from PVector_mag.xml )
403
+ *
404
+ * Calculates the magnitude (length) of the vector and returns the result
405
+ * as a float (this is simply the equation <em>sqrt(x*x + y*y + z*z)</em>.)
406
+ *
407
+ * ( end auto-generated )
408
+ *
409
+ * @webref pvector:method
410
+ * @usage web_application
411
+ * @brief Calculate the magnitude of the vector
412
+ * @return magnitude (length) of the vector
413
+ * @see PVector#magSq()
414
+ */
415
+ public float mag() {
416
+ return (float) Math.sqrt(x*x + y*y + z*z);
417
+ }
418
+
419
+
420
+ /**
421
+ * ( begin auto-generated from PVector_mag.xml )
422
+ *
423
+ * Calculates the squared magnitude of the vector and returns the result
424
+ * as a float (this is simply the equation <em>(x*x + y*y + z*z)</em>.)
425
+ * Faster if the real length is not required in the
426
+ * case of comparing vectors, etc.
427
+ *
428
+ * ( end auto-generated )
429
+ *
430
+ * @webref pvector:method
431
+ * @usage web_application
432
+ * @brief Calculate the magnitude of the vector, squared
433
+ * @return squared magnitude of the vector
434
+ * @see PVector#mag()
435
+ */
436
+ public float magSq() {
437
+ return (x*x + y*y + z*z);
438
+ }
439
+
440
+
441
+ /**
442
+ * ( begin auto-generated from PVector_add.xml )
443
+ *
444
+ * Adds x, y, and z components to a vector, adds one vector to another, or
445
+ * adds two independent vectors together. The version of the method that
446
+ * adds two vectors together is a static method and returns a PVector, the
447
+ * others have no return value -- they act directly on the vector. See the
448
+ * examples for more context.
449
+ *
450
+ * ( end auto-generated )
451
+ *
452
+ * @webref pvector:method
453
+ * @usage web_application
454
+ * @param v the vector to be added
455
+ * @brief Adds x, y, and z components to a vector, one vector to another, or two independent vectors
456
+ */
457
+ public PVector add(PVector v) {
458
+ x += v.x;
459
+ y += v.y;
460
+ z += v.z;
461
+ return this;
462
+ }
463
+
464
+
465
+ /**
466
+ * @param x x component of the vector
467
+ * @param y y component of the vector
468
+ */
469
+ public PVector add(float x, float y) {
470
+ this.x += x;
471
+ this.y += y;
472
+ return this;
473
+ }
474
+
475
+
476
+ /**
477
+ * @param z z component of the vector
478
+ */
479
+ public PVector add(float x, float y, float z) {
480
+ this.x += x;
481
+ this.y += y;
482
+ this.z += z;
483
+ return this;
484
+ }
485
+
486
+
487
+ /**
488
+ * Add two vectors
489
+ * @param v1 a vector
490
+ * @param v2 another vector
491
+ */
492
+ static public PVector add(PVector v1, PVector v2) {
493
+ return add(v1, v2, null);
494
+ }
495
+
496
+
497
+ /**
498
+ * Add two vectors into a target vector
499
+ * @param target the target vector (if null, a new vector will be created)
500
+ */
501
+ static public PVector add(PVector v1, PVector v2, PVector target) {
502
+ if (target == null) {
503
+ target = new PVector(v1.x + v2.x,v1.y + v2.y, v1.z + v2.z);
504
+ } else {
505
+ target.set(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
506
+ }
507
+ return target;
508
+ }
509
+
510
+
511
+ /**
512
+ * ( begin auto-generated from PVector_sub.xml )
513
+ *
514
+ * Subtracts x, y, and z components from a vector, subtracts one vector
515
+ * from another, or subtracts two independent vectors. The version of the
516
+ * method that subtracts two vectors is a static method and returns a
517
+ * PVector, the others have no return value -- they act directly on the
518
+ * vector. See the examples for more context.
519
+ *
520
+ * ( end auto-generated )
521
+ *
522
+ * @webref pvector:method
523
+ * @usage web_application
524
+ * @param v any variable of type PVector
525
+ * @brief Subtract x, y, and z components from a vector, one vector from another, or two independent vectors
526
+ */
527
+ public PVector sub(PVector v) {
528
+ x -= v.x;
529
+ y -= v.y;
530
+ z -= v.z;
531
+ return this;
532
+ }
533
+
534
+
535
+ /**
536
+ * @param x the x component of the vector
537
+ * @param y the y component of the vector
538
+ */
539
+ public PVector sub(float x, float y) {
540
+ this.x -= x;
541
+ this.y -= y;
542
+ return this;
543
+ }
544
+
545
+
546
+ /**
547
+ * @param z the z component of the vector
548
+ */
549
+ public PVector sub(float x, float y, float z) {
550
+ this.x -= x;
551
+ this.y -= y;
552
+ this.z -= z;
553
+ return this;
554
+ }
555
+
556
+
557
+ /**
558
+ * Subtract one vector from another
559
+ * @param v1 the x, y, and z components of a PVector object
560
+ * @param v2 the x, y, and z components of a PVector object
561
+ */
562
+ static public PVector sub(PVector v1, PVector v2) {
563
+ return sub(v1, v2, null);
564
+ }
565
+
566
+
567
+ /**
568
+ * Subtract one vector from another and store in another vector
569
+ * @param target PVector in which to store the result
570
+ */
571
+ static public PVector sub(PVector v1, PVector v2, PVector target) {
572
+ if (target == null) {
573
+ target = new PVector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
574
+ } else {
575
+ target.set(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
576
+ }
577
+ return target;
578
+ }
579
+
580
+
581
+ /**
582
+ * ( begin auto-generated from PVector_mult.xml )
583
+ *
584
+ * Multiplies a vector by a scalar or multiplies one vector by another.
585
+ *
586
+ * ( end auto-generated )
587
+ *
588
+ * @webref pvector:method
589
+ * @usage web_application
590
+ * @brief Multiply a vector by a scalar
591
+ * @param n the number to multiply with the vector
592
+ */
593
+ public PVector mult(float n) {
594
+ x *= n;
595
+ y *= n;
596
+ z *= n;
597
+ return this;
598
+ }
599
+
600
+
601
+ /**
602
+ * @param v the vector to multiply by the scalar
603
+ */
604
+ static public PVector mult(PVector v, float n) {
605
+ return mult(v, n, null);
606
+ }
607
+
608
+
609
+ /**
610
+ * Multiply a vector by a scalar, and write the result into a target PVector.
611
+ * @param target PVector in which to store the result
612
+ */
613
+ static public PVector mult(PVector v, float n, PVector target) {
614
+ if (target == null) {
615
+ target = new PVector(v.x*n, v.y*n, v.z*n);
616
+ } else {
617
+ target.set(v.x*n, v.y*n, v.z*n);
618
+ }
619
+ return target;
620
+ }
621
+
622
+
623
+ /**
624
+ * ( begin auto-generated from PVector_div.xml )
625
+ *
626
+ * Divides a vector by a scalar or divides one vector by another.
627
+ *
628
+ * ( end auto-generated )
629
+ *
630
+ * @webref pvector:method
631
+ * @usage web_application
632
+ * @brief Divide a vector by a scalar
633
+ * @param n the number by which to divide the vector
634
+ */
635
+ public PVector div(float n) {
636
+ x /= n;
637
+ y /= n;
638
+ z /= n;
639
+ return this;
640
+ }
641
+
642
+
643
+ /**
644
+ * Divide a vector by a scalar and return the result in a new vector.
645
+ * @param v the vector to divide by the scalar
646
+ * @return a new vector that is v1 / n
647
+ */
648
+ static public PVector div(PVector v, float n) {
649
+ return div(v, n, null);
650
+ }
651
+
652
+
653
+ /**
654
+ * Divide a vector by a scalar and store the result in another vector.
655
+ * @param target PVector in which to store the result
656
+ */
657
+ static public PVector div(PVector v, float n, PVector target) {
658
+ if (target == null) {
659
+ target = new PVector(v.x/n, v.y/n, v.z/n);
660
+ } else {
661
+ target.set(v.x/n, v.y/n, v.z/n);
662
+ }
663
+ return target;
664
+ }
665
+
666
+
667
+ /**
668
+ * ( begin auto-generated from PVector_dist.xml )
669
+ *
670
+ * Calculates the Euclidean distance between two points (considering a
671
+ * point as a vector object).
672
+ *
673
+ * ( end auto-generated )
674
+ *
675
+ * @webref pvector:method
676
+ * @usage web_application
677
+ * @param v the x, y, and z coordinates of a PVector
678
+ * @brief Calculate the distance between two points
679
+ */
680
+ public float dist(PVector v) {
681
+ float dx = x - v.x;
682
+ float dy = y - v.y;
683
+ float dz = z - v.z;
684
+ return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
685
+ }
686
+
687
+
688
+ /**
689
+ * @param v1 any variable of type PVector
690
+ * @param v2 any variable of type PVector
691
+ * @return the Euclidean distance between v1 and v2
692
+ */
693
+ static public float dist(PVector v1, PVector v2) {
694
+ float dx = v1.x - v2.x;
695
+ float dy = v1.y - v2.y;
696
+ float dz = v1.z - v2.z;
697
+ return (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
698
+ }
699
+
700
+
701
+ /**
702
+ * ( begin auto-generated from PVector_dot.xml )
703
+ *
704
+ * Calculates the dot product of two vectors.
705
+ *
706
+ * ( end auto-generated )
707
+ *
708
+ * @webref pvector:method
709
+ * @usage web_application
710
+ * @param v any variable of type PVector
711
+ * @return the dot product
712
+ * @brief Calculate the dot product of two vectors
713
+ */
714
+ public float dot(PVector v) {
715
+ return x*v.x + y*v.y + z*v.z;
716
+ }
717
+
718
+
719
+ /**
720
+ * @param x x component of the vector
721
+ * @param y y component of the vector
722
+ * @param z z component of the vector
723
+ */
724
+ public float dot(float x, float y, float z) {
725
+ return this.x*x + this.y*y + this.z*z;
726
+ }
727
+
728
+
729
+ /**
730
+ * @param v1 any variable of type PVector
731
+ * @param v2 any variable of type PVector
732
+ */
733
+ static public float dot(PVector v1, PVector v2) {
734
+ return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
735
+ }
736
+
737
+
738
+ /**
739
+ * ( begin auto-generated from PVector_cross.xml )
740
+ *
741
+ * Calculates and returns a vector composed of the cross product between
742
+ * two vectors.
743
+ *
744
+ * ( end auto-generated )
745
+ *
746
+ * @webref pvector:method
747
+ * @param v the vector to calculate the cross product
748
+ * @brief Calculate and return the cross product
749
+ */
750
+ public PVector cross(PVector v) {
751
+ return cross(v, null);
752
+ }
753
+
754
+
755
+ /**
756
+ * @param v any variable of type PVector
757
+ * @param target PVector to store the result
758
+ */
759
+ public PVector cross(PVector v, PVector target) {
760
+ float crossX = y * v.z - v.y * z;
761
+ float crossY = z * v.x - v.z * x;
762
+ float crossZ = x * v.y - v.x * y;
763
+
764
+ if (target == null) {
765
+ target = new PVector(crossX, crossY, crossZ);
766
+ } else {
767
+ target.set(crossX, crossY, crossZ);
768
+ }
769
+ return target;
770
+ }
771
+
772
+
773
+ /**
774
+ * @param v1 any variable of type PVector
775
+ * @param v2 any variable of type PVector
776
+ * @param target PVector to store the result
777
+ */
778
+ static public PVector cross(PVector v1, PVector v2, PVector target) {
779
+ float crossX = v1.y * v2.z - v2.y * v1.z;
780
+ float crossY = v1.z * v2.x - v2.z * v1.x;
781
+ float crossZ = v1.x * v2.y - v2.x * v1.y;
782
+
783
+ if (target == null) {
784
+ target = new PVector(crossX, crossY, crossZ);
785
+ } else {
786
+ target.set(crossX, crossY, crossZ);
787
+ }
788
+ return target;
789
+ }
790
+
791
+
792
+ /**
793
+ * ( begin auto-generated from PVector_normalize.xml )
794
+ *
795
+ * Normalize the vector to length 1 (make it a unit vector).
796
+ *
797
+ * ( end auto-generated )
798
+ *
799
+ * @webref pvector:method
800
+ * @usage web_application
801
+ * @brief Normalize the vector to a length of 1
802
+ */
803
+ public PVector normalize() {
804
+ float m = mag();
805
+ if (m != 0 && m != 1) {
806
+ div(m);
807
+ }
808
+ return this;
809
+ }
810
+
811
+
812
+ /**
813
+ * @param target Set to null to create a new vector
814
+ * @return a new vector (if target was null), or target
815
+ */
816
+ public PVector normalize(PVector target) {
817
+ if (target == null) {
818
+ target = new PVector();
819
+ }
820
+ float m = mag();
821
+ if (m > 0) {
822
+ target.set(x/m, y/m, z/m);
823
+ } else {
824
+ target.set(x, y, z);
825
+ }
826
+ return target;
827
+ }
828
+
829
+
830
+ /**
831
+ * ( begin auto-generated from PVector_limit.xml )
832
+ *
833
+ * Limit the magnitude of this vector to the value used for the <b>max</b> parameter.
834
+ *
835
+ * ( end auto-generated )
836
+ *
837
+ * @webref pvector:method
838
+ * @usage web_application
839
+ * @param max the maximum magnitude for the vector
840
+ * @brief Limit the magnitude of the vector
841
+ */
842
+ public PVector limit(float max) {
843
+ if (magSq() > max*max) {
844
+ normalize();
845
+ mult(max);
846
+ }
847
+ return this;
848
+ }
849
+
850
+
851
+ /**
852
+ * ( begin auto-generated from PVector_setMag.xml )
853
+ *
854
+ * Set the magnitude of this vector to the value used for the <b>len</b> parameter.
855
+ *
856
+ * ( end auto-generated )
857
+ *
858
+ * @webref pvector:method
859
+ * @usage web_application
860
+ * @param len the new length for this vector
861
+ * @brief Set the magnitude of the vector
862
+ */
863
+ public PVector setMag(float len) {
864
+ normalize();
865
+ mult(len);
866
+ return this;
867
+ }
868
+
869
+
870
+ /**
871
+ * Sets the magnitude of this vector, storing the result in another vector.
872
+ * @param target Set to null to create a new vector
873
+ * @param len the new length for the new vector
874
+ * @return a new vector (if target was null), or target
875
+ */
876
+ public PVector setMag(PVector target, float len) {
877
+ target = normalize(target);
878
+ target.mult(len);
879
+ return target;
880
+ }
881
+
882
+
883
+ /**
884
+ * ( begin auto-generated from PVector_setMag.xml )
885
+ *
886
+ * Calculate the angle of rotation for this vector (only 2D vectors)
887
+ *
888
+ * ( end auto-generated )
889
+ *
890
+ * @webref pvector:method
891
+ * @usage web_application
892
+ * @return the angle of rotation
893
+ * @brief Calculate the angle of rotation for this vector
894
+ */
895
+ public float heading() {
896
+ float angle = (float) Math.atan2(y, x);
897
+ return angle;
898
+ }
899
+
900
+
901
+ @Deprecated
902
+ public float heading2D() {
903
+ return heading();
904
+ }
905
+
906
+
907
+ /**
908
+ * ( begin auto-generated from PVector_rotate.xml )
909
+ *
910
+ * Rotate the vector by an angle (only 2D vectors), magnitude remains the same
911
+ *
912
+ * ( end auto-generated )
913
+ *
914
+ * @webref pvector:method
915
+ * @usage web_application
916
+ * @brief Rotate the vector by an angle (2D only)
917
+ * @param theta the angle of rotation
918
+ */
919
+ public PVector rotate(float theta) {
920
+ float temp = x;
921
+ // Might need to check for rounding errors like with angleBetween function?
922
+ x = x*PApplet.cos(theta) - y*PApplet.sin(theta);
923
+ y = temp*PApplet.sin(theta) + y*PApplet.cos(theta);
924
+ return this;
925
+ }
926
+
927
+
928
+ /**
929
+ * ( begin auto-generated from PVector_rotate.xml )
930
+ *
931
+ * Linear interpolate the vector to another vector
932
+ *
933
+ * ( end auto-generated )
934
+ *
935
+ * @webref pvector:method
936
+ * @usage web_application
937
+ * @brief Linear interpolate the vector to another vector
938
+ * @param v the vector to lerp to
939
+ * @param amt The amount of interpolation; some value between 0.0 (old vector) and 1.0 (new vector). 0.1 is very near the old vector; 0.5 is halfway in between.
940
+ * @see PApplet#lerp(float, float, float)
941
+ */
942
+ public PVector lerp(PVector v, float amt) {
943
+ x = PApplet.lerp(x, v.x, amt);
944
+ y = PApplet.lerp(y, v.y, amt);
945
+ z = PApplet.lerp(z, v.z, amt);
946
+ return this;
947
+ }
948
+
949
+
950
+ /**
951
+ * Linear interpolate between two vectors (returns a new PVector object)
952
+ * @param v1 the vector to start from
953
+ * @param v2 the vector to lerp to
954
+ */
955
+ public static PVector lerp(PVector v1, PVector v2, float amt) {
956
+ PVector v = v1.copy();
957
+ v.lerp(v2, amt);
958
+ return v;
959
+ }
960
+
961
+
962
+ /**
963
+ * Linear interpolate the vector to x,y,z values
964
+ * @param x the x component to lerp to
965
+ * @param y the y component to lerp to
966
+ * @param z the z component to lerp to
967
+ */
968
+ public PVector lerp(float x, float y, float z, float amt) {
969
+ this.x = PApplet.lerp(this.x, x, amt);
970
+ this.y = PApplet.lerp(this.y, y, amt);
971
+ this.z = PApplet.lerp(this.z, z, amt);
972
+ return this;
973
+ }
974
+
975
+
976
+ /**
977
+ * ( begin auto-generated from PVector_angleBetween.xml )
978
+ *
979
+ * Calculates and returns the angle (in radians) between two vectors.
980
+ *
981
+ * ( end auto-generated )
982
+ *
983
+ * @webref pvector:method
984
+ * @usage web_application
985
+ * @param v1 the x, y, and z components of a PVector
986
+ * @param v2 the x, y, and z components of a PVector
987
+ * @brief Calculate and return the angle between two vectors
988
+ */
989
+ static public float angleBetween(PVector v1, PVector v2) {
990
+
991
+ // We get NaN if we pass in a zero vector which can cause problems
992
+ // Zero seems like a reasonable angle between a (0,0,0) vector and something else
993
+ if (v1.x == 0 && v1.y == 0 && v1.z == 0 ) return 0.0f;
994
+ if (v2.x == 0 && v2.y == 0 && v2.z == 0 ) return 0.0f;
995
+
996
+ double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
997
+ double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z);
998
+ double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z);
999
+ // This should be a number between -1 and 1, since it's "normalized"
1000
+ double amt = dot / (v1mag * v2mag);
1001
+ // But if it's not due to rounding error, then we need to fix it
1002
+ // http://code.google.com/p/processing/issues/detail?id=340
1003
+ // Otherwise if outside the range, acos() will return NaN
1004
+ // http://www.cppreference.com/wiki/c/math/acos
1005
+ if (amt <= -1) {
1006
+ return PConstants.PI;
1007
+ } else if (amt >= 1) {
1008
+ // http://code.google.com/p/processing/issues/detail?id=435
1009
+ return 0;
1010
+ }
1011
+ return (float) Math.acos(amt);
1012
+ }
1013
+
1014
+
1015
+ @Override
1016
+ public String toString() {
1017
+ return "[ " + x + ", " + y + ", " + z + " ]";
1018
+ }
1019
+
1020
+
1021
+ /**
1022
+ * ( begin auto-generated from PVector_array.xml )
1023
+ *
1024
+ * Return a representation of this vector as a float array. This is only
1025
+ * for temporary use. If used in any other fashion, the contents should be
1026
+ * copied by using the <b>PVector.get()</b> method to copy into your own array.
1027
+ *
1028
+ * ( end auto-generated )
1029
+ *
1030
+ * @webref pvector:method
1031
+ * @usage: web_application
1032
+ * @brief Return a representation of the vector as a float array
1033
+ */
1034
+ public float[] array() {
1035
+ if (array == null) {
1036
+ array = new float[3];
1037
+ }
1038
+ array[0] = x;
1039
+ array[1] = y;
1040
+ array[2] = z;
1041
+ return array;
1042
+ }
1043
+
1044
+
1045
+ @Override
1046
+ public boolean equals(Object obj) {
1047
+ if (!(obj instanceof PVector)) {
1048
+ return false;
1049
+ }
1050
+ final PVector p = (PVector) obj;
1051
+ return x == p.x && y == p.y && z == p.z;
1052
+ }
1053
+
1054
+
1055
+ @Override
1056
+ public int hashCode() {
1057
+ int result = 1;
1058
+ result = 31 * result + Float.floatToIntBits(x);
1059
+ result = 31 * result + Float.floatToIntBits(y);
1060
+ result = 31 * result + Float.floatToIntBits(z);
1061
+ return result;
1062
+ }
1063
+ }