Created
February 3, 2014 05:17
-
-
Save jordanorelli/8779187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java | |
index ca25eb1..67c8bfe 100644 | |
--- a/core/src/processing/core/PVector.java | |
+++ b/core/src/processing/core/PVector.java | |
@@ -432,10 +432,11 @@ public class PVector implements Serializable { | |
* @param v the vector to be added | |
* @brief Adds x, y, and z components to a vector, one vector to another, or two independent vectors | |
*/ | |
- public void add(PVector v) { | |
+ public PVector add(PVector v) { | |
x += v.x; | |
y += v.y; | |
z += v.z; | |
+ return this; | |
} | |
/** | |
@@ -443,10 +444,11 @@ public class PVector implements Serializable { | |
* @param y y component of the vector | |
* @param z z component of the vector | |
*/ | |
- public void add(float x, float y, float z) { | |
+ public PVector add(float x, float y, float z) { | |
this.x += x; | |
this.y += y; | |
this.z += z; | |
+ return this; | |
} | |
@@ -490,10 +492,11 @@ public class PVector implements Serializable { | |
* @param v any variable of type PVector | |
* @brief Subtract x, y, and z components from a vector, one vector from another, or two independent vectors | |
*/ | |
- public void sub(PVector v) { | |
+ public PVector sub(PVector v) { | |
x -= v.x; | |
y -= v.y; | |
z -= v.z; | |
+ return this; | |
} | |
/** | |
@@ -501,10 +504,11 @@ public class PVector implements Serializable { | |
* @param y the y component of the vector | |
* @param z the z component of the vector | |
*/ | |
- public void sub(float x, float y, float z) { | |
+ public PVector sub(float x, float y, float z) { | |
this.x -= x; | |
this.y -= y; | |
this.z -= z; | |
+ return this; | |
} | |
@@ -545,10 +549,11 @@ public class PVector implements Serializable { | |
* @brief Multiply a vector by a scalar | |
* @param n the number to multiply with the vector | |
*/ | |
- public void mult(float n) { | |
+ public PVector mult(float n) { | |
x *= n; | |
y *= n; | |
z *= n; | |
+ return this; | |
} | |
@@ -587,10 +592,11 @@ public class PVector implements Serializable { | |
* @brief Divide a vector by a scalar | |
* @param n the number by which to divide the vector | |
*/ | |
- public void div(float n) { | |
+ public PVector div(float n) { | |
x /= n; | |
y /= n; | |
z /= n; | |
+ return this; | |
} | |
@@ -750,11 +756,12 @@ public class PVector implements Serializable { | |
* @usage web_application | |
* @brief Normalize the vector to a length of 1 | |
*/ | |
- public void normalize() { | |
+ public PVector normalize() { | |
float m = mag(); | |
if (m != 0 && m != 1) { | |
div(m); | |
} | |
+ return this; | |
} | |
@@ -788,11 +795,12 @@ public class PVector implements Serializable { | |
* @param max the maximum magnitude for the vector | |
* @brief Limit the magnitude of the vector | |
*/ | |
- public void limit(float max) { | |
+ public PVector limit(float max) { | |
if (magSq() > max*max) { | |
normalize(); | |
mult(max); | |
} | |
+ return this; | |
} | |
/** | |
@@ -807,9 +815,10 @@ public class PVector implements Serializable { | |
* @param len the new length for this vector | |
* @brief Set the magnitude of the vector | |
*/ | |
- public void setMag(float len) { | |
+ public PVector setMag(float len) { | |
normalize(); | |
mult(len); | |
+ return this; | |
} | |
/** | |
@@ -860,11 +869,12 @@ public class PVector implements Serializable { | |
* @brief Rotate the vector by an angle (2D only) | |
* @param theta the angle of rotation | |
*/ | |
- public void rotate(float theta) { | |
+ public PVector rotate(float theta) { | |
float xTemp = x; | |
// Might need to check for rounding errors like with angleBetween function? | |
x = x*PApplet.cos(theta) - y*PApplet.sin(theta); | |
y = xTemp*PApplet.sin(theta) + y*PApplet.cos(theta); | |
+ return this; | |
} | |
@@ -881,10 +891,11 @@ public class PVector implements Serializable { | |
* @param v the vector to lerp to | |
* @param amt The amount of interpolation; some value between 0.0 (old vector) and 1.0 (new vector). 0.1 is very near the new vector. 0.5 is halfway in between. | |
*/ | |
- public void lerp(PVector v, float amt) { | |
+ public PVector lerp(PVector v, float amt) { | |
x = PApplet.lerp(x,v.x,amt); | |
y = PApplet.lerp(y,v.y,amt); | |
z = PApplet.lerp(z,v.z,amt); | |
+ return this; | |
} | |
/** | |
@@ -904,10 +915,11 @@ public class PVector implements Serializable { | |
* @param y the y component to lerp to | |
* @param z the z component to lerp to | |
*/ | |
- public void lerp(float x, float y, float z, float amt) { | |
+ public PVector lerp(float x, float y, float z, float amt) { | |
this.x = PApplet.lerp(this.x,x,amt); | |
this.y = PApplet.lerp(this.y,y,amt); | |
this.z = PApplet.lerp(this.z,z,amt); | |
+ return this; | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment