Commits

Roi Atalla committed c268d79

HAHA! I fixed the problem! After hours of going through all my code, it ended up being my error in the cross product method of Vector3 XD

  • Participants
  • Parent commits 85a2f0a

Comments (0)

Files changed (6)

files/tutorials.jar

Binary file added.

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

 	private boolean drawLookAtPoint = true;
 	
 	public Example7_1() {
-		super("Example 7.1", 500, 500, false);
+		super("Example 7.1", 500, 500, true);
 	}
 	
 	@Override
 		rotMat.put(1,perpUpDir,0);
 		rotMat.put(2,lookDir.mul(-1),0);
 		
-		return rotMat.transpose().translate(cameraPoint.mul(-1));
+		return rotMat.transpose().translate(new Vector3(cameraPoint).mul(-1));
 	}
 	
 	private Vector3 resolveCamPosition() {
 		Vector3 camPos = resolveCamPosition();
 		
 		MatrixStack camMatrix = new MatrixStack();
-		camMatrix.getTop().put(calcLookAtMatrix(camPos, camTarget, new Vector3(0,1,0)));
+		camMatrix.setTop(calcLookAtMatrix(camPos, camTarget, new Vector3(0,1,0)));
 		
 		uniformColor.program.begin();
 		glUniformMatrix4(uniformColor.worldToCameraMatrixUniform,false,camMatrix.getTop().getBuffer());
 		
 		modelMatrix.pushMatrix();
 		
-		modelMatrix.getTop().translate(0,trunkHeight,0);
+		modelMatrix.getTop().translate(0,trunkHeight,0).scale(3,coneHeight,3);
 		
 		uniformColorTint.program.begin();
 		glUniformMatrix4(uniformColorTint.modelToWorldMatrixUniform, false, modelMatrix.getTop().getBuffer());

src/main/java/com/ra4king/opengl/util/Mesh.java

 		attributeData.flip();
 		indexData.flip();
 		
+		FloatBuffer a = attributeData.asFloatBuffer();
+		ShortBuffer i = indexData.asShortBuffer();
+		
+		System.out.print("attribs: ");
+		while(a.hasRemaining())
+			System.out.print(a.get() + " ");
+		
+		System.out.print("\nindices: ");
+		while(i.hasRemaining())
+			System.out.print(i.get() + " ");
+		
+		System.out.println();
+		
 		int vbo1 = glGenBuffers();
 		glBindBuffer(GL_ARRAY_BUFFER, vbo1);
 		glBufferData(GL_ARRAY_BUFFER, (ByteBuffer)BufferUtils.createByteBuffer(attributeData.capacity()).put(attributeData).flip(),GL_STATIC_DRAW);

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

 		return this;
 	}
 	
+	public Matrix4 put(int index, Vector3 v) {
+		put(index*4+0,v.x());
+		put(index*4+1,v.y());
+		put(index*4+2,v.z());
+		return this;
+	}
+	
 	public Matrix4 put(int index, Vector3 v, float w) {
 		put(index*4+0,v.x());
 		put(index*4+1,v.y());

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

 		return current;
 	}
 	
+	public void setTop(Matrix4 m) {
+		current = m;
+	}
+	
 	public void pushMatrix() {
 		stack.push(current);
 		current = new Matrix4(current);

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

 	}
 	
 	public Vector3 cross(Vector3 vec) {
-		return new Vector3(y()*vec.z() - vec.y()*z(), vec.z()*x() - z()*vec.x(), x()*vec.y() - vec.x()*y());
+		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) {