Commits

Roi Atalla  committed 831d356

Some spelling mistakes and formatting adjustments. Also, now it seems that the axis for the rotations are weird. What's even weirder is the code looks correct :S

  • Participants
  • Parent commits 03dca49

Comments (0)

Files changed (6)

File src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter7/example1/Example7_1.java

 		Matrix4 rotMat = new Matrix4().clearToIdentity();
 		rotMat.put(0,rightDir,0);
 		rotMat.put(1,perpUpDir,0);
-		rotMat.put(2,lookDir.mul(-1),0);
+		rotMat.put(2,lookDir.mult(-1),0);
 		
-		return rotMat.transpose().translate(new Vector3(cameraPoint).mul(-1));
+		return rotMat.transpose().translate(new Vector3(cameraPoint).mult(-1));
 	}
 	
 	private Vector3 resolveCamPosition() {
 		float cosPhi = (float)Math.cos(phi);
 		float sinPhi = (float)Math.sin(phi);
 		
-		return new Vector3(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi).mul(sphereCamRelPos.z()).add(camTarget);
+		return new Vector3(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi).mult(sphereCamRelPos.z()).add(camTarget);
 	}
 	
 	@Override

File src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter7/example2/Example7_2.java

 		Matrix4 rotMat = new Matrix4().clearToIdentity();
 		rotMat.put(0,rightDir,0);
 		rotMat.put(1,perpUpDir,0);
-		rotMat.put(2,lookDir.mul(-1),0);
+		rotMat.put(2,lookDir.mult(-1),0);
 		
-		return rotMat.transpose().translate(new Vector3(cameraPoint).mul(-1));
+		return rotMat.transpose().translate(new Vector3(cameraPoint).mult(-1));
 	}
 	
 	private Vector3 resolveCamPosition() {
 		float cosPhi = (float)Math.cos(phi);
 		float sinPhi = (float)Math.sin(phi);
 		
-		return new Vector3(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi).mul(sphereCamRelPos.z()).add(camTarget);
+		return new Vector3(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi).mult(sphereCamRelPos.z()).add(camTarget);
 	}
 	
 	@Override

File src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter8/example2/Example8_2.java

 	}
 	
 	private void offsetOrientation(Vector3 axis, float angle) {
+		System.out.println(axis.x() + " " + axis.y() + " " + axis.z());
+		
 		angle = angle * (float)Math.PI / 180;
 		
-		axis.normalize().mul((float)Math.sin(angle/2));
+		axis.normalize().mult((float)Math.sin(angle/2));
 		
 		Quaternion offset = new Quaternion(axis.x(), axis.y(), axis.z(), (float)Math.cos(angle/2));
 		
 		if(rightMultiply)
-			orientation = orientation.mult(offset);
+			orientation = orientation.mult(offset).normalize();
 		else
 			orientation = offset.mult(orientation);
 		

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

 	}
 	
 	public Matrix4 put(Matrix4 m) {
-		for(int a = 0; a < matrix.length; a++)
-			put(a,m.get(a));
-		
-		return this;
+		return put(m.matrix);
 	}
 	
 	public Matrix4 mult(float[] m) {
 		float[] newm = new float[16];
+		
 		for(int a = 0; a < 16; a += 4) {
 			newm[a+0] = get(0)*m[a] + get(4)*m[a+1] + get(8)*m[a+2] + get(12)*m[a+3];
 			newm[a+1] = get(1)*m[a] + get(5)*m[a+1] + get(9)*m[a+2] + get(13)*m[a+3];
 	}
 	
 	public Matrix4 mult(Matrix4 m) {
-		float[] newm = new float[16];
-		
-		for(int a = 0; a < 16; a += 4) {
-			newm[a+0] = get(0)*m.get(a) + get(4)*m.get(a+1) + get(8)*m.get(a+2) + get(12)*m.get(a+3);
-			newm[a+1] = get(1)*m.get(a) + get(5)*m.get(a+1) + get(9)*m.get(a+2) + get(13)*m.get(a+3);
-			newm[a+2] = get(2)*m.get(a) + get(6)*m.get(a+1) + get(10)*m.get(a+2) + get(14)*m.get(a+3);
-			newm[a+3] = get(3)*m.get(a) + get(7)*m.get(a+1) + get(11)*m.get(a+2) + get(15)*m.get(a+3);
-		}
-		
-		put(newm);
-		
-		return this;
+		return mult(m.matrix);
 	}
 	
 	public Matrix4 transpose() {

File src/main/java/com/ra4king/opengl/util/math/Quaternion.java

 	}
 	
 	public Quaternion mult(Quaternion q) {
-		float xx = w*q.x + x*q.w + y*q.z - z*q.y;
-		float yy = w*q.y + y*q.w + z*q.x - x*q.z;
-		float zz = w*q.z + z*q.w + x*q.y - y*q.x;
-		float ww = w*q.w - x*q.x - y*q.y - z*q.z;
+		float xx = (w*q.x) + (x*q.w) + (y*q.z) - (z*q.y);
+		float yy = (w*q.y) + (y*q.w) + (z*q.x) - (x*q.z);
+		float zz = (w*q.z) + (z*q.w) + (x*q.y) - (y*q.x);
+		float ww = (w*q.w) - (x*q.x) - (y*q.y) - (z*q.z);
 		
 		x = xx;
 		y = yy;
 	public Matrix4 getMatrix() {
 		float[] m = {
 				1 - 2*y*y - 2*z*z,     2*x*y - 2*w*z,     2*x*z + 2*w*y, 0,
-					2*x*y + 2*w*z, 1 - 2*x*x - 2*z*z,     2*y*z - 2*w*x, 0,
-					2*x*z - 2*w*y,     2*y*z + 2*w*x, 1 - 2*x*x - 2*y*y, 0,
-								0,				   0,				  0, 1
+				    2*x*y + 2*w*z, 1 - 2*x*x - 2*z*z,     2*y*z - 2*w*x, 0,
+				    2*x*z - 2*w*y,     2*y*z + 2*w*x, 1 - 2*x*x - 2*y*y, 0,
+				                0,                 0,                 0, 1,
 		};
 		
 		return new Matrix4(m);

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

 		return sub(vec.x(),vec.y(),vec.z());
 	}
 	
-	public Vector3 mul(float f) {
-		return mul(f,f,f);
+	public Vector3 mult(float f) {
+		return mult(f,f,f);
 	}
 	
-	public Vector3 mul(float x, float y, float z) {
+	public Vector3 mult(float x, float y, float z) {
 		this.x *= x;
 		this.y *= y;
 		this.z *= z;
 	}
 	
 	public Vector3 mul(Vector3 vec) {
-		return mul(vec.x(),vec.y(),vec.z());
+		return mult(vec.x(),vec.y(),vec.z());
 	}
 }