Roi Atalla avatar Roi Atalla committed 3453581

Added "inverse" and "determinant" methods to Matrix3. Also completed Example9.2.

Comments (0)

Files changed (8)

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/Example9_2.java

 package com.ra4king.opengl.arcsynthesis.gl33.chapter9.example2;
 
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.GL20.*;
+import static org.lwjgl.opengl.GL30.*;
+import static org.lwjgl.opengl.GL31.*;
+import static org.lwjgl.opengl.GL32.*;
+
+import org.lwjgl.input.Keyboard;
+
 import com.ra4king.opengl.GLProgram;
+import com.ra4king.opengl.util.Mesh;
+import com.ra4king.opengl.util.MousePoles.MouseButton;
+import com.ra4king.opengl.util.MousePoles.ObjectData;
+import com.ra4king.opengl.util.MousePoles.ObjectPole;
+import com.ra4king.opengl.util.MousePoles.ViewData;
+import com.ra4king.opengl.util.MousePoles.ViewPole;
+import com.ra4king.opengl.util.MousePoles.ViewScale;
+import com.ra4king.opengl.util.ShaderProgram;
+import com.ra4king.opengl.util.Utils;
+import com.ra4king.opengl.util.math.Matrix3;
+import com.ra4king.opengl.util.math.Matrix4;
+import com.ra4king.opengl.util.math.MatrixStack;
+import com.ra4king.opengl.util.math.Quaternion;
+import com.ra4king.opengl.util.math.Vector3;
+import com.ra4king.opengl.util.math.Vector4;
 
 public class Example9_2 extends GLProgram {
 	public static void main(String[] args) {
 		new Example9_2().run(true);
 	}
 	
+	private ProgramData whiteDiffuseColor;
+	private ProgramData vertexDiffuseColor;
+	
+	private int projectionUniformBuffer;
+	private final int projectionBlockIndex = 2;
+	
+	private Mesh cylinderMesh;
+	private Mesh planeMesh;
+	
+	private ViewPole viewPole;
+	private ObjectPole objectPole;
+	
+	private Vector4 lightDirection = new Vector4(0.866f, 0.5f, 0, 0);
+	
+	private boolean scaleCyl, doInvTranspose = true;
+	
 	public Example9_2() {
 		super("Example 9.2", 500, 500, false);
 	}
 	
 	@Override
 	public void init() {
+		glClearColor(0, 0, 0, 0);
+		glClearDepth(1);
 		
+		ViewData initialViewData = new ViewData(new Vector3(0, 0.5f, 0), new Quaternion(0.3826834f, 0, 0, 0.92387953f), 5, 0);
+		ViewScale viewScale = new ViewScale(3, 20, 1.5f, 0.5f, 0, 0, 90f/250f);
+		ObjectData initialObjectData = new ObjectData(new Vector3(0, 0.5f, 0), new Quaternion());
+		
+		viewPole = new ViewPole(initialViewData, viewScale, MouseButton.LEFT_BUTTON, false);
+		objectPole = new ObjectPole(initialObjectData, 90f/250f, MouseButton.RIGHT_BUTTON, viewPole);
+		
+		whiteDiffuseColor = loadShader("example9.2.VertexLighting_PN.vert", "example9.2.frag");
+		vertexDiffuseColor = loadShader("example9.2.VertexLighting_PCN.vert", "example9.2.frag");
+		
+		try {
+			cylinderMesh = new Mesh(getClass().getResource("example9.2.UnitCylinder.xml"));
+			planeMesh = new Mesh(getClass().getResource("example9.2.LargePlane.xml"));
+		}
+		catch(Exception exc) {
+			exc.printStackTrace();
+			destroy();
+		}
+		
+		glEnable(GL_CULL_FACE);
+		glCullFace(GL_BACK);
+		glFrontFace(GL_CW);
+		
+		glEnable(GL_DEPTH_TEST);
+		glDepthMask(true);
+		glDepthFunc(GL_LEQUAL);
+		glDepthRange(0, 1);
+		glEnable(GL_DEPTH_CLAMP);
+		
+		projectionUniformBuffer = glGenBuffers();
+		glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
+		glBufferData(GL_UNIFORM_BUFFER, 16*4, GL_DYNAMIC_DRAW);
+		glBindBufferRange(GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, 16*4);
+		glBindBuffer(GL_UNIFORM_BUFFER, 0);
+	}
+	
+	private ProgramData loadShader(String vertFile, String fragFile) {
+		ProgramData data = new ProgramData(new ShaderProgram(readFromFile(vertFile), readFromFile(fragFile)));
+		data.modelToCameraMatrixUniform = glGetUniformLocation(data.program.getProgram(), "modelToCameraMatrix");
+		data.normalModelToCameraMatrixUniform = glGetUniformLocation(data.program.getProgram(), "normalModelToCameraMatrix");
+		data.dirTolightUniform = glGetUniformLocation(data.program.getProgram(), "dirToLight");
+		data.lightIntensityUniform = glGetUniformLocation(data.program.getProgram(), "lightIntensity");
+		
+		int projectionBlock = glGetUniformBlockIndex(data.program.getProgram(), "Projection");
+		glUniformBlockBinding(data.program.getProgram(), projectionBlock, projectionBlockIndex);
+		
+		return data;
+	}
+	
+	@Override
+	public void resized() {
+		super.resized();
+		
+		glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
+		glBufferSubData(GL_UNIFORM_BUFFER, 0, new Matrix4().clearToPerspectiveDeg(45, getWidth(), getHeight(), 1, 1000).toBuffer());
+		glBindBuffer(GL_UNIFORM_BUFFER, 0);
+	}
+	
+	@Override
+	public void update(long deltaTime) {
+		Utils.updateMousePoles(viewPole, objectPole);
+	}
+	
+	@Override
+	public void keyPressed(int key, char c, long nanos) {
+		if(key == Keyboard.KEY_SPACE)
+			scaleCyl = !scaleCyl;
+		else if(key == Keyboard.KEY_T) {
+			doInvTranspose = !doInvTranspose;
+			if(doInvTranspose)
+				System.out.println("Doing inverse transpose.");
+			else
+				System.out.println("Bad lighting.");
+		}
 	}
 	
 	@Override
 	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		
+		MatrixStack modelMatrix = new MatrixStack();
+		modelMatrix.setTop(viewPole.calcMatrix());
+		
+		Vector4 lightDirCameraSpace = modelMatrix.getTop().mult(lightDirection);
+		
+		whiteDiffuseColor.program.begin();
+		glUniform3(whiteDiffuseColor.dirTolightUniform, lightDirCameraSpace.toBuffer());
+		vertexDiffuseColor.program.begin();
+		glUniform3(vertexDiffuseColor.dirTolightUniform, lightDirCameraSpace.toBuffer());
+		vertexDiffuseColor.program.end();
+		
+		{
+			modelMatrix.pushMatrix();
+			
+			{
+				modelMatrix.pushMatrix();
+				
+				whiteDiffuseColor.program.begin();
+				glUniformMatrix4(whiteDiffuseColor.modelToCameraMatrixUniform, false, modelMatrix.getTop().toBuffer());
+				glUniformMatrix3(whiteDiffuseColor.normalModelToCameraMatrixUniform, false, new Matrix3(modelMatrix.getTop()).toBuffer());
+				glUniform4f(whiteDiffuseColor.lightIntensityUniform, 1, 1, 1, 1);
+				planeMesh.render();
+				whiteDiffuseColor.program.end();
+				
+				modelMatrix.popMatrix();
+			}
+			
+			{
+				modelMatrix.pushMatrix();
+				
+				modelMatrix.getTop().mult(objectPole.calcMatrix());
+				
+				if(scaleCyl)
+					modelMatrix.getTop().scale(1, 1, 0.2f);
+				
+				vertexDiffuseColor.program.begin();
+				glUniformMatrix4(vertexDiffuseColor.modelToCameraMatrixUniform, false, modelMatrix.getTop().toBuffer());
+				Matrix3 normMatrix = new Matrix3(modelMatrix.getTop());
+				if(doInvTranspose)
+					normMatrix.inverse().transpose();
+				glUniformMatrix3(vertexDiffuseColor.normalModelToCameraMatrixUniform, false, normMatrix.toBuffer());
+				glUniform4f(vertexDiffuseColor.lightIntensityUniform, 1, 1, 1, 1);
+				cylinderMesh.render("lit-color");
+				vertexDiffuseColor.program.end();
+			}
+		}
+	}
+	
+	private static class ProgramData {
+		private ShaderProgram program;
+		
+		private int dirTolightUniform;
+		private int lightIntensityUniform;
+		
+		private int modelToCameraMatrixUniform;
+		private int normalModelToCameraMatrixUniform;
+		
+		public ProgramData(ShaderProgram program) {
+			this.program = program;
+		}
 	}
 }

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/example9.2.LargePlane.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<?oxygen RNGSchema="../../Documents/meshFormat.rnc" type="compact"?>
+
+<mesh xmlns="http://www.arcsynthesis.com/gltut/mesh" >
+	<attribute index="0" type="float" size="3" > 
+		3 0 -3
+		3 0 3
+		-3 0 3
+		-3 0 -3
+		3 0 -3
+		3 0 3
+		-3 0 3
+		-3 0 -3
+	</attribute>
+	<attribute index="2" type="float" size="3" > 
+		0 1 0
+		0 1 0
+		0 1 0
+		0 1 0
+		0 -1 0
+		0 -1 0
+		0 -1 0
+		0 -1 0
+	</attribute>
+	<indices cmd="triangles" type="ushort" > 
+		0 1 2
+		2 3 0
+		4 6 5
+		6 4 7
+	</indices>
+</mesh>

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/example9.2.UnitCylinder.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<?oxygen RNGSchema="../../Documents/meshFormat.rnc" type="compact"?>
+
+<mesh xmlns="http://www.arcsynthesis.com/gltut/mesh" >
+	<attribute index="0" type="float" size="3" > 
+		0 0.5 0
+		0.5 0.5 0
+		0.5 -0.5 0
+		0.48907381875731 0.5 0.1039557588888
+		0.48907381875731 -0.5 0.1039557588888
+		0.45677280077542 0.5 0.20336815992623
+		0.45677280077542 -0.5 0.20336815992623
+		0.40450865316151 0.5 0.29389241146627
+		0.40450865316151 -0.5 0.29389241146627
+		0.33456556611288 0.5 0.37157217599218
+		0.33456556611288 -0.5 0.37157217599218
+		0.2500003830126 0.5 0.43301248075957
+		0.2500003830126 -0.5 0.43301248075957
+		0.15450900193016 0.5 0.47552809414644
+		0.15450900193016 -0.5 0.47552809414644
+		0.052264847412855 0.5 0.49726088296277
+		0.052264847412855 -0.5 0.49726088296277
+		-0.052263527886268 0.5 0.49726102165048
+		-0.052263527886268 -0.5 0.49726102165048
+		-0.15450774007312 0.5 0.47552850414828
+		-0.15450774007312 -0.5 0.47552850414828
+		-0.24999923397422 0.5 0.43301314415651
+		-0.24999923397422 -0.5 0.43301314415651
+		-0.33456458011157 0.5 0.37157306379065
+		-0.33456458011157 -0.5 0.37157306379065
+		-0.40450787329018 0.5 0.29389348486527
+		-0.40450787329018 -0.5 0.29389348486527
+		-0.45677226111814 0.5 0.20336937201315
+		-0.45677226111814 -0.5 0.20336937201315
+		-0.48907354289964 0.5 0.10395705668972
+		-0.48907354289964 -0.5 0.10395705668972
+		-0.49999999999824 0.5 1.3267948966764e-006
+		-0.49999999999824 -0.5 1.3267948966764e-006
+		-0.48907409461153 0.5 -0.10395446108714
+		-0.48907409461153 -0.5 -0.10395446108714
+		-0.45677334042948 0.5 -0.20336694783787
+		-0.45677334042948 -0.5 -0.20336694783787
+		-0.40450943302999 0.5 -0.2938913380652
+		-0.40450943302999 -0.5 -0.2938913380652
+		-0.33456655211184 0.5 -0.3715712881911
+		-0.33456655211184 -0.5 -0.3715712881911
+		-0.25000153204922 0.5 -0.43301181735958
+		-0.25000153204922 -0.5 -0.43301181735958
+		-0.15451026378611 0.5 -0.47552768414126
+		-0.15451026378611 -0.5 -0.47552768414126
+		-0.052266166939075 0.5 -0.49726074427155
+		-0.052266166939075 -0.5 -0.49726074427155
+		0.052262208359312 0.5 -0.4972611603347
+		0.052262208359312 -0.5 -0.4972611603347
+		0.15450647821499 0.5 -0.47552891414676
+		0.15450647821499 -0.5 -0.47552891414676
+		0.24999808493408 0.5 -0.4330138075504
+		0.24999808493408 -0.5 -0.4330138075504
+		0.3345635941079 0.5 -0.37157395158649
+		0.3345635941079 -0.5 -0.37157395158649
+		0.40450709341601 0.5 -0.2938945582622
+		0.40450709341601 -0.5 -0.2938945582622
+		0.45677172145764 0.5 -0.20337058409865
+		0.45677172145764 -0.5 -0.20337058409865
+		0.48907326703854 0.5 -0.10395835448992
+		0.48907326703854 -0.5 -0.10395835448992
+		0 -0.5 0
+		0.5 0.5 0
+		0.5 -0.5 0
+		0.48907381875731 0.5 0.1039557588888
+		0.48907381875731 -0.5 0.1039557588888
+		0.45677280077542 0.5 0.20336815992623
+		0.45677280077542 -0.5 0.20336815992623
+		0.40450865316151 0.5 0.29389241146627
+		0.40450865316151 -0.5 0.29389241146627
+		0.33456556611288 0.5 0.37157217599218
+		0.33456556611288 -0.5 0.37157217599218
+		0.2500003830126 0.5 0.43301248075957
+		0.2500003830126 -0.5 0.43301248075957
+		0.15450900193016 0.5 0.47552809414644
+		0.15450900193016 -0.5 0.47552809414644
+		0.052264847412855 0.5 0.49726088296277
+		0.052264847412855 -0.5 0.49726088296277
+		-0.052263527886268 0.5 0.49726102165048
+		-0.052263527886268 -0.5 0.49726102165048
+		-0.15450774007312 0.5 0.47552850414828
+		-0.15450774007312 -0.5 0.47552850414828
+		-0.24999923397422 0.5 0.43301314415651
+		-0.24999923397422 -0.5 0.43301314415651
+		-0.33456458011157 0.5 0.37157306379065
+		-0.33456458011157 -0.5 0.37157306379065
+		-0.40450787329018 0.5 0.29389348486527
+		-0.40450787329018 -0.5 0.29389348486527
+		-0.45677226111814 0.5 0.20336937201315
+		-0.45677226111814 -0.5 0.20336937201315
+		-0.48907354289964 0.5 0.10395705668972
+		-0.48907354289964 -0.5 0.10395705668972
+		-0.49999999999824 0.5 1.3267948966764e-006
+		-0.49999999999824 -0.5 1.3267948966764e-006
+		-0.48907409461153 0.5 -0.10395446108714
+		-0.48907409461153 -0.5 -0.10395446108714
+		-0.45677334042948 0.5 -0.20336694783787
+		-0.45677334042948 -0.5 -0.20336694783787
+		-0.40450943302999 0.5 -0.2938913380652
+		-0.40450943302999 -0.5 -0.2938913380652
+		-0.33456655211184 0.5 -0.3715712881911
+		-0.33456655211184 -0.5 -0.3715712881911
+		-0.25000153204922 0.5 -0.43301181735958
+		-0.25000153204922 -0.5 -0.43301181735958
+		-0.15451026378611 0.5 -0.47552768414126
+		-0.15451026378611 -0.5 -0.47552768414126
+		-0.052266166939075 0.5 -0.49726074427155
+		-0.052266166939075 -0.5 -0.49726074427155
+		0.052262208359312 0.5 -0.4972611603347
+		0.052262208359312 -0.5 -0.4972611603347
+		0.15450647821499 0.5 -0.47552891414676
+		0.15450647821499 -0.5 -0.47552891414676
+		0.24999808493408 0.5 -0.4330138075504
+		0.24999808493408 -0.5 -0.4330138075504
+		0.3345635941079 0.5 -0.37157395158649
+		0.3345635941079 -0.5 -0.37157395158649
+		0.40450709341601 0.5 -0.2938945582622
+		0.40450709341601 -0.5 -0.2938945582622
+		0.45677172145764 0.5 -0.20337058409865
+		0.45677172145764 -0.5 -0.20337058409865
+		0.48907326703854 0.5 -0.10395835448992
+		0.48907326703854 -0.5 -0.10395835448992
+	</attribute>
+	<attribute index="1" type="float" size="4" > 
+		1 1 1 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		1 1 1 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.9 0.5 0.5 1
+		0.9 0.5 0.5 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.5 0.1 0.1 1
+		0.5 0.1 0.1 1
+		0.58 0.18 0.18 1
+		0.58 0.18 0.18 1
+		0.66 0.26 0.26 1
+		0.66 0.26 0.26 1
+		0.74 0.34 0.34 1
+		0.74 0.34 0.34 1
+		0.82 0.42 0.42 1
+		0.82 0.42 0.42 1
+	</attribute>
+	<attribute index="2" type="float" size="3" > 
+		0 1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 1 0
+		0 -1 0
+		0 -1 0
+		1 0 0
+		1 0 0
+		0.97814763751461 0 0.20791151777759
+		0.97814763751461 0 0.20791151777759
+		0.91354560155084 0 0.40673631985245
+		0.91354560155084 0 0.40673631985245
+		0.80901730632302 0 0.58778482293254
+		0.80901730632302 0 0.58778482293254
+		0.66913113222576 0 0.74314435198437
+		0.66913113222576 0 0.74314435198437
+		0.5000007660252 0 0.86602496151913
+		0.5000007660252 0 0.86602496151913
+		0.30901800386032 0 0.95105618829288
+		0.30901800386032 0 0.95105618829288
+		0.10452969482571 0 0.99452176592553
+		0.10452969482571 0 0.99452176592553
+		-0.10452705577254 0 0.99452204330096
+		-0.10452705577254 0 0.99452204330096
+		-0.30901548014624 0 0.95105700829655
+		-0.30901548014624 0 0.95105700829655
+		-0.49999846794844 0 0.86602628831301
+		-0.49999846794844 0 0.86602628831301
+		-0.66912916022314 0 0.7431461275813
+		-0.66912916022314 0 0.7431461275813
+		-0.80901574658037 0 0.58778696973054
+		-0.80901574658037 0 0.58778696973054
+		-0.91354452223627 0 0.40673874402631
+		-0.91354452223627 0 0.40673874402631
+		-0.97814708579929 0 0.20791411337945
+		-0.97814708579929 0 0.20791411337945
+		-0.99999999999648 0 2.6535897933527e-006
+		-0.99999999999648 0 2.6535897933527e-006
+		-0.97814818922305 0 -0.20790892217427
+		-0.97814818922305 0 -0.20790892217427
+		-0.91354668085897 0 -0.40673389567574
+		-0.91354668085897 0 -0.40673389567574
+		-0.80901886605998 0 -0.58778267613041
+		-0.80901886605998 0 -0.58778267613041
+		-0.66913310422368 0 -0.74314257638221
+		-0.66913310422368 0 -0.74314257638221
+		-0.50000306409843 0 -0.86602363471916
+		-0.50000306409843 0 -0.86602363471916
+		-0.30902052757222 0 -0.95105536828251
+		-0.30902052757222 0 -0.95105536828251
+		-0.10453233387815 0 -0.9945214885431
+		-0.10453233387815 0 -0.9945214885431
+		0.10452441671862 0 -0.99452232066939
+		0.10452441671862 0 -0.99452232066939
+		0.30901295642998 0 -0.95105782829353
+		0.30901295642998 0 -0.95105782829353
+		0.49999616986816 0 -0.8660276151008
+		0.49999616986816 0 -0.8660276151008
+		0.66912718821581 0 -0.74314790317299
+		0.66912718821581 0 -0.74314790317299
+		0.80901418683202 0 -0.5877891165244
+		0.80901418683202 0 -0.5877891165244
+		0.91354344291528 0 -0.40674116819729
+		0.91354344291528 0 -0.40674116819729
+		0.97814653407707 0 -0.20791670897984
+		0.97814653407707 0 -0.20791670897984
+	</attribute>
+	<vao name="lit-color" >
+		<source attrib="0" />
+		<source attrib="1" />
+		<source attrib="2" />
+	</vao>
+	<vao name="lit" >
+		<source attrib="0" />
+		<source attrib="2" />
+	</vao>
+	<vao name="color" >
+		<source attrib="0" />
+		<source attrib="1" />
+	</vao>
+	<indices cmd="tri-fan" type="ushort" >0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 1</indices>
+	<indices cmd="tri-fan" type="ushort" >61 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 60</indices>
+	<indices cmd="tri-strip" type="ushort" >62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 62 63</indices>
+</mesh>

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/example9.2.VertexLighting_PCN.vert

+#version 330
+
+layout(location = 0) in vec3 position;
+layout(location = 1) in vec4 diffuseColor;
+layout(location = 2) in vec3 normal;
+
+smooth out vec4 interpColor;
+
+uniform vec3 dirToLight;
+uniform vec4 lightIntensity;
+
+uniform mat4 modelToCameraMatrix;
+uniform mat3 normalModelToCameraMatrix;
+
+layout(std140) uniform Projection
+{
+	mat4 cameraToClipMatrix;
+};
+
+void main()
+{
+	gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1));
+	
+	vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal);
+	
+	float cosAngIncidence = dot(normCamSpace, dirToLight);
+	cosAngIncidence = clamp(cosAngIncidence, 0, 1);
+	
+	interpColor = lightIntensity * diffuseColor * cosAngIncidence;
+}

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/example9.2.VertexLighting_PN.vert

+#version 330
+
+layout(location = 0) in vec3 position;
+layout(location = 2) in vec3 normal;
+
+smooth out vec4 interpColor;
+
+uniform vec3 dirToLight;
+uniform vec4 lightIntensity;
+
+uniform mat4 modelToCameraMatrix;
+uniform mat3 normalModelToCameraMatrix;
+
+layout(std140) uniform Projection
+{
+	mat4 cameraToClipMatrix;
+};
+
+void main()
+{
+	gl_Position = cameraToClipMatrix * (modelToCameraMatrix * vec4(position, 1));
+	
+	vec3 normCamSpace = normalize(normalModelToCameraMatrix * normal);
+	
+	float cosAngIncidence = dot(normCamSpace, dirToLight);
+	cosAngIncidence = clamp(cosAngIncidence, 0, 1);
+	
+	interpColor = lightIntensity * cosAngIncidence;
+}

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter9/example2/example9.2.frag

+#version 330
+
+smooth in vec4 interpColor;
+
+out vec4 outputColor;
+
+void main()
+{
+	outputColor = interpColor;
+}

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

 		return this;
 	}
 	
+	public float determinant() {
+		return + get(0)*get(4)*get(8) + get(3)*get(7)*get(2) + get(6)*get(1)*get(5)
+			   - get(2)*get(4)*get(6) - get(5)*get(7)*get(0) - get(8)*get(1)*get(3);
+	}
+	
+	public Matrix3 inverse() {
+		Matrix3 inv = new Matrix3();
+		
+		inv.put(0, + (get(4)*get(8) - get(5)*get(7)));
+		inv.put(1, - (get(3)*get(8) - get(5)*get(6)));
+		inv.put(2, + (get(3)*get(7) - get(4)*get(6)));
+		
+		inv.put(3, - (get(1)*get(8) - get(2)*get(7)));
+		inv.put(4, + (get(0)*get(8) - get(2)*get(6)));
+		inv.put(5, - (get(0)*get(7) - get(1)*get(6)));
+		
+		inv.put(6, + (get(1)*get(5) - get(2)*get(4)));
+		inv.put(7, - (get(0)*get(5) - get(2)*get(3)));
+		inv.put(8, + (get(0)*get(4) - get(1)*get(3)));
+		
+		return put(inv.transpose().mult(1/determinant()));
+	}
+	
 	private final static FloatBuffer direct = BufferUtils.createFloatBuffer(9);
 	
 	public FloatBuffer toBuffer() {

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

 		inv.put(14, - (get(0)*get(5)*get(11) + get(4)*get(9)*get(3) + get(8)*get(1)*get(7) - get(3)*get(5)*get(8) - get(7)*get(9)*get(0) - get(11)*get(1)*get(4)));
 		inv.put(15, + (get(0)*get(5)*get(10) + get(4)*get(9)*get(2) + get(8)*get(1)*get(6) - get(2)*get(5)*get(8) - get(6)*get(9)*get(0) - get(10)*get(1)*get(4)));
 		
-		return put(inv.transpose().mult(1f/determinant()));
+		return put(inv.transpose().mult(1/determinant()));
 	}
 	
 	public Quaternion toQuaternion() {
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.