Roi Atalla avatar Roi Atalla committed e76902d

Changed Matrix4 to use a backend float array instead of FloatBuffer. getBuffer() uses a private static FloatBuffer that is shared by all instances, so do not use for any other purposes than to send to OpenGL.

Comments (0)

Files changed (1)

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

 import org.lwjgl.BufferUtils;
 
 public class Matrix4 {
-	private FloatBuffer matrix;
+	private float[] matrix;
 	
 	public Matrix4() {
-		matrix = FloatBuffer.allocate(16);
+		matrix = new float[16];
 	}
 	
 	public Matrix4(float[] m) {
 	}
 	
 	public Matrix4 clear() {
-		for(int a = 0; a < 16; a++)
-			matrix.put(a,0);
+		for(int a = 0; a < matrix.length; a++)
+			put(a,0);
 		return this;
 	}
 	
 	}
 	
 	public float get(int index) {
-		return matrix.get(index);
+		return matrix[index];
 	}
 	
 	public Matrix4 put(int index, float f) {
-		matrix.put(index, f);
+		matrix[index] = f;
 		return this;
 	}
 	
 		if(m.length < 16)
 			throw new IllegalArgumentException("float array must have at least 16 values.");
 		
-		matrix.position(0);
-		matrix.put(m,0,16);
+		for(int a = 0; a < matrix.length; a++)
+			put(a,m[a]);
 		
 		return this;
 	}
 	
 	public Matrix4 put(Matrix4 m) {
-		FloatBuffer b = m.getBuffer();
-		while(b.hasRemaining())
-			matrix.put(b.get());
+		for(int a = 0; a < matrix.length; a++)
+			put(a,m.get(a));
 		
 		return this;
 	}
 	
 	public FloatBuffer getBuffer() {
 		direct.clear();
-		direct.put((FloatBuffer)matrix.position(16).flip());
+		direct.put(matrix);
 		direct.flip();
 		return direct;
 	}
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.