Roi Atalla avatar Roi Atalla committed 5625630

Added equals method to Vector4.

Comments (0)

Files changed (2)

src/main/java/com/ra4king/opengl/util/math/Vector3.java

-package com.ra4king.opengl.util.math;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-
-public class Vector3 {
-	private float x, y, z;
-	
-	public Vector3() {
-		set(0, 0, 0);
-	}
-	
-	public Vector3(float v) {
-		this(v, v, v);
-	}
-	
-	public Vector3(float x, float y, float z) {
-		set(x, y, z);
-	}
-	
-	public Vector3(Vector3 vec) {
-		set(vec);
-	}
-	
-	public Vector3(Vector4 vec) {
-		set(vec);
-	}
-	
-	public float x() {
-		return x;
-	}
-	
-	public Vector3 x(float x) {
-		this.x = x;
-		return this;
-	}
-	
-	public float y() {
-		return y;
-	}
-	
-	public Vector3 y(float y) {
-		this.y = y;
-		return this;
-	}
-	
-	public float z() {
-		return z;
-	}
-	
-	public Vector3 z(float z) {
-		this.z = z;
-		return this;
-	}
-	
-	public Vector3 set(float x, float y, float z) {
-		this.x = x;
-		this.y = y;
-		this.z = z;
-		return this;
-	}
-	
-	public Vector3 set(Vector3 vec) {
-		return set(vec.x, vec.y, vec.z);
-	}
-	
-	public Vector3 set(Vector4 vec) {
-		return set(vec.x(), vec.y(), vec.z());
-	}
-	
-	public Vector3 reset() {
-		x = y = z = 0;
-		return this;
-	}
-	
-	public float length() {
-		return (float)Math.sqrt(x * x + y * y + z * z);
-	}
-	
-	public Vector3 normalize() {
-		float length = length();
-		x /= length;
-		y /= length;
-		z /= length;
-		return this;
-	}
-	
-	public float dot(Vector3 vec) {
-		return x * vec.x + y * vec.y + z * vec.z;
-	}
-	
-	public Vector3 cross(Vector3 vec) {
-		return new Vector3(y * vec.z - vec.y * z, z * vec.x - vec.z * x, x * vec.y - vec.x * y);
-	}
-	
-	public Vector3 add(float x, float y, float z) {
-		this.x += x;
-		this.y += y;
-		this.z += z;
-		return this;
-	}
-	
-	public Vector3 add(Vector3 vec) {
-		return add(vec.x, vec.y, vec.z);
-	}
-	
-	public Vector3 sub(float x, float y, float z) {
-		this.x -= x;
-		this.y -= y;
-		this.z -= z;
-		return this;
-	}
-	
-	public Vector3 sub(Vector3 vec) {
-		return sub(vec.x, vec.y, vec.z);
-	}
-	
-	public Vector3 mult(float f) {
-		return mult(f, f, f);
-	}
-	
-	public Vector3 mult(float x, float y, float z) {
-		this.x *= x;
-		this.y *= y;
-		this.z *= z;
-		return this;
-	}
-	
-	public Vector3 mult(Vector3 vec) {
-		return mult(vec.x, vec.y, vec.z);
-	}
-	
-	private final static FloatBuffer direct = BufferUtils.createFloatBuffer(3);
-	
-	public FloatBuffer toBuffer() {
-		direct.clear();
-		direct.put(x).put(y).put(z);
-		direct.flip();
-		return direct;
-	}
-}

src/main/java/com/ra4king/opengl/util/math/Vector4.java

 		return this;
 	}
 	
+	@Override
+	public boolean equals(Object o) {
+		if(o instanceof Vector4) {
+			Vector4 v = (Vector4)o;
+			return x == v.x && y == v.y && z == v.z && w == v.w;
+		}
+		
+		return false;
+	}
+	
 	public Vector4 set(float x, float y, float z, float w) {
 		this.x = x;
 		this.y = y;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.