Jason McKesson avatar Jason McKesson committed 0162d4e

Tut15: Code updated to have a corridor.

Comments (0)

Files changed (3)

Tut 15 Many Images/Many Images.cpp

 	glm::mat4 cameraToClipMatrix;
 };
 
-Framework::Mesh *g_pPlane = NULL;
-
 GLuint g_projectionUniformBuffer = 0;
 GLuint g_checkerTexture = 0;
 GLuint g_mipmapTestTexture = 0;
 	}
 }
 
+Framework::Mesh *g_pPlane = NULL;
+Framework::Mesh *g_pCorridor = NULL;
+
 //Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
 void init()
 {
 
 	try
 	{
+		g_pCorridor = new Framework::Mesh("Corridor.xml");
 		g_pPlane = new Framework::Mesh("BigPlane.xml");
 	}
 	catch(std::exception &except)
 int g_currSampler = 0;
 
 bool g_useMipmapTexture = false;
+bool g_drawCorridor = false;
 
 //Called to update the display.
 //You should call glutSwapBuffers after all of your rendering to display what you rendered.
 	glClearDepth(1.0f);
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	if(g_pPlane)
+	if(g_pPlane && g_pCorridor)
 	{
 		g_camTimer.Update();
 
 				g_useMipmapTexture ? g_mipmapTestTexture : g_checkerTexture);
  			glBindSampler(g_colorTexUnit, g_samplers[g_currSampler]);
 
-			g_pPlane->Render("tex");
+			if(g_drawCorridor)
+				g_pCorridor->Render("tex");
+			else
+				g_pPlane->Render("tex");
 
  			glBindSampler(g_colorTexUnit, 0);
  			glBindTexture(GL_TEXTURE_2D, 0);
 	{
 	case 27:
 		delete g_pPlane;
+		delete g_pCorridor;
 		g_pPlane = NULL;
+		g_pCorridor = NULL;
 		glutLeaveMainLoop();
 		break;
 	case 32:
 		g_useMipmapTexture = !g_useMipmapTexture;
 		break;
+	case 'y':
+		g_drawCorridor = !g_drawCorridor;
+		break;
+	case 'p':
+		g_camTimer.TogglePause();
+		break;
+	case 'z':
+		delete g_pPlane;
+		delete g_pCorridor;
+		try
+		{
+			g_pCorridor = new Framework::Mesh("Corridor.xml");
+			g_pPlane = new Framework::Mesh("BigPlane.xml");
+		}
+		catch(std::exception &except)
+		{
+			printf("%s\n", except.what());
+			throw;
+		}
+		break;
 	}
 
 	if(('1' <= key) && (key <= '9'))

Tut 15 Many Images/data/Corridor.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" > 
+        1 0 -64
+        1 0 64
+        -1 0 64
+        -1 0 -64
+        -1 0 -64
+        -1 0 64
+        -1 2 64
+        -1 2 -64
+        1 0 64
+        1 0 -64
+        1 2 -64
+        1 2 64
+        1 2 64
+        1 2 -64
+        -1 2 -64
+        -1 2 64</attribute>
+	<attribute index="5" type="float" size="2" > 
+        1 -64
+        1 64
+        -1 64
+        -1 -64
+        1 -64
+        1 64
+        -1 64
+        -1 -64
+        1 -64
+        1 64
+        -1 64
+        -1 -64
+        1 -64
+        1 64
+        -1 64
+        -1 -64</attribute>
+	<vao name="flat" >
+		<source attrib="0" />
+	</vao>
+	<vao name="tex" >
+		<source attrib="0" />
+		<source attrib="5" />
+	</vao>
+	<indices cmd="triangles" type="ushort" > 
+        0 1 2
+        2 3 0
+        4 5 6
+        6 7 4
+        8 9 10
+        10 11 8
+        12 13 14
+        14 15 12</indices>
+</mesh>

Tut 15 Many Images/data/GenCorridor.lua

+require "XmlWriter"
+require "vmath"
+
+local function GenStringFromArray(theArray, bAsInt)
+	local array = {" "}
+	for i, vector in ipairs(theArray) do
+		local elements = vector;
+		if(bAsInt) then
+			elements = {};
+			for i, value in ipairs(vector) do
+				elements[#elements + 1] = string.format("%i", value);
+			end
+		end
+		
+		array[#array + 1] = "        " .. table.concat(vector, " ");
+	end
+	
+	return table.concat(array, "\n");
+end
+
+local halfWidth = 1.0;
+
+local positions =
+{
+	vmath.vec3( halfWidth, 0.0, -64.0),
+	vmath.vec3( halfWidth, 0.0,  64.0),
+	vmath.vec3(-halfWidth, 0.0,  64.0),
+	vmath.vec3(-halfWidth, 0.0, -64.0),
+	
+	vmath.vec3(-halfWidth, 0.0,           -64.0),
+	vmath.vec3(-halfWidth, 0.0,            64.0),
+	vmath.vec3(-halfWidth, halfWidth * 2,  64.0),
+	vmath.vec3(-halfWidth, halfWidth * 2, -64.0),
+	
+	vmath.vec3( halfWidth, 0.0,            64.0),
+	vmath.vec3( halfWidth, 0.0,           -64.0),
+	vmath.vec3( halfWidth, halfWidth * 2, -64.0),
+	vmath.vec3( halfWidth, halfWidth * 2,  64.0),
+
+	vmath.vec3( halfWidth, halfWidth * 2,  64.0),
+	vmath.vec3( halfWidth, halfWidth * 2, -64.0),
+	vmath.vec3(-halfWidth, halfWidth * 2, -64.0),
+	vmath.vec3(-halfWidth, halfWidth * 2,  64.0),
+};
+
+local texCoords =
+{
+	vmath.vec2( halfWidth, -64.0),
+	vmath.vec2( halfWidth,  64.0),
+	vmath.vec2(-halfWidth,  64.0),
+	vmath.vec2(-halfWidth, -64.0),
+
+	vmath.vec2( halfWidth, -64.0),
+	vmath.vec2( halfWidth,  64.0),
+	vmath.vec2(-halfWidth,  64.0),
+	vmath.vec2(-halfWidth, -64.0),
+
+	vmath.vec2( halfWidth, -64.0),
+	vmath.vec2( halfWidth,  64.0),
+	vmath.vec2(-halfWidth,  64.0),
+	vmath.vec2(-halfWidth, -64.0),
+
+	vmath.vec2( halfWidth, -64.0),
+	vmath.vec2( halfWidth,  64.0),
+	vmath.vec2(-halfWidth,  64.0),
+	vmath.vec2(-halfWidth, -64.0),
+};
+
+local indices =
+{
+	vmath.vec3(0, 1, 2),
+	vmath.vec3(2, 3, 0),
+
+	vmath.vec3(4, 5, 6),
+	vmath.vec3(6, 7, 4),
+
+	vmath.vec3(8, 9, 10),
+	vmath.vec3(10, 11, 8),
+
+	vmath.vec3(12, 13, 14),
+	vmath.vec3(14, 15, 12),
+};
+
+do
+	local writer = XmlWriter.XmlWriter("Corridor.xml");
+	writer:AddPI("oxygen", [[RNGSchema="../../Documents/meshFormat.rnc" type="compact"]]);
+	writer:PushElement("mesh", "http://www.arcsynthesis.com/gltut/mesh");
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "0");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "3");
+			writer:AddText(GenStringFromArray(positions));
+		writer:PopElement();
+		writer:PushElement("attribute");
+			writer:AddAttribute("index", "5");
+			writer:AddAttribute("type", "float");
+			writer:AddAttribute("size", "2");
+			writer:AddText(GenStringFromArray(texCoords));
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "flat");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("vao");
+			writer:AddAttribute("name", "tex");
+			writer:PushElement("source"); writer:AddAttribute("attrib", "0"); writer:PopElement();
+			writer:PushElement("source"); writer:AddAttribute("attrib", "5"); writer:PopElement();
+		writer:PopElement();
+		writer:PushElement("indices");
+			writer:AddAttribute("cmd", "triangles");
+			writer:AddAttribute("type", "ushort");
+			writer:AddText(GenStringFromArray(indices, true));
+		writer:PopElement();
+	writer:PopElement();
+	writer:Close();
+end
+
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.