gltut / Tut 18 Bumpy Textures / Bumpy Square.cpp

Diff from to

Tut 18 Bumpy Textures/Bumpy Square.cpp

 	}
 }
 */
+glutil::ObjectData g_objectData =
+{
+	glm::vec3(0.0f, 1.0f, 0.0f),
+	glm::fquat(1.0f, 0.0f, 0.0f, 0.0f),
+};
 
 glutil::ViewPole *g_pViewPole = NULL;
+glutil::ObjectPole *g_pObjPole = NULL;
 
 namespace
 {
 	void MouseMotion(int x, int y)
 	{
 		if(g_pViewPole)
+		{
 			Framework::ForwardMouseMotion(*g_pViewPole, x, y);
+			Framework::ForwardMouseMotion(*g_pObjPole, x, y);
+		}
 	}
 
 	void MouseButton(int button, int state, int x, int y)
 	{
 		if(g_pViewPole)
+		{
 			Framework::ForwardMouseButton(*g_pViewPole, button, state, x, y);
+			Framework::ForwardMouseButton(*g_pObjPole, button, state, x, y);
+		}
 	}
 
 	void MouseWheel(int wheel, int direction, int x, int y)
 	{
 		if(g_pViewPole)
+		{
 			Framework::ForwardMouseWheel(*g_pViewPole, wheel, direction, x, y);
+		}
 	}
 }
 
 GLuint g_unlitProg;
 Framework::Mesh *g_pSphereMesh = NULL;
 
+
+
 void LoadAndSetupScene()
 {
 	std::auto_ptr<Framework::Scene> pScene(new Framework::Scene("bump_square_scene.xml"));
 	if(pViewPole.get() == NULL)
 		throw std::runtime_error("Could not find the main camera in the scene.");
 
+	std::auto_ptr<glutil::ObjectPole> pObjPole(new glutil::ObjectPole(g_objectData, 0.36f,
+		glutil::MB_RIGHT_BTN, pViewPole.get()));
+
 	//No more things that can throw.
 	g_unlitProg = unlit;
 	g_unlitModelToCameraMatrixUnif = glGetUniformLocation(unlit, "modelToCameraMatrix");
 	g_pViewPole = pViewPole.release();
 	pViewPole.reset(pTemp);		//If something was there already, delete it.
 
+	glutil::ObjectPole *pTempObj = g_pObjPole;
+	g_pObjPole = pObjPole.release();
+	pObjPole.reset(pTempObj);		//If something was there already, delete it.
+
 	Framework::Scene *pOldScene = g_pScene;
 	g_pScene = pScene.release();
 	pScene.reset(pOldScene);	//If something was there already, delete it.
 // int g_currSampler = 0;
 
 bool g_bDrawCameraPos = false;
-bool g_bShowOtherLights = true;
+bool g_bDrawLightPos = true;
 
 int g_displayWidth = 500;
 int g_displayHeight = 500;
 
+const glm::vec4 g_lightPosOffset = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f);
+
 void BuildLights( const glm::mat4 &camMatrix )
 {
 	LightBlock lightData;
 	lightData.lights[0].lightIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
 	lightData.lights[0].cameraSpaceLightPos = camMatrix *
 		glm::normalize(glm::vec4(-0.2f, 0.5f, 0.5f, 0.0f));
+
 	lightData.lights[1].lightIntensity = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f);
-	lightData.lights[1].cameraSpaceLightPos = camMatrix *
-		glm::vec4(5.0f, 6.0f, 0.5f, 1.0f);
+
+	if(g_pObjPole)
+	{
+		lightData.lights[1].cameraSpaceLightPos = camMatrix * g_pObjPole->CalcMatrix() *
+			g_lightPosOffset;
+	}
+	else
+	{
+		lightData.lights[1].cameraSpaceLightPos = camMatrix *
+			glm::vec4(5.0f, 6.0f, 0.5f, 1.0f);
+	}
 
 	g_lightNumBinder.SetValue(2);
 
 
 	g_pScene->Render(modelMatrix.Top());
 
+	if(g_pObjPole && g_bDrawLightPos)
+	{
+		glutil::PushStack stackPush(modelMatrix);
+		modelMatrix.ApplyMatrix(g_pObjPole->CalcMatrix());
+		modelMatrix.Translate(glm::vec3(g_lightPosOffset.x, g_lightPosOffset.y, g_lightPosOffset.z));
+		modelMatrix.Scale(0.0625f);
+
+		glUseProgram(g_unlitProg);
+		glUniformMatrix4fv(g_unlitModelToCameraMatrixUnif, 1, GL_FALSE,
+			glm::value_ptr(modelMatrix.Top()));
+		glUniform4f(g_unlitObjectColorUnif, 0.25f, 0.25f, 0.25f, 1.0f);
+		g_pSphereMesh->Render("flat");
+	}
+
 	if(g_bDrawCameraPos)
 	{
 		//Draw lookat point.
 		g_bDrawCameraPos = !g_bDrawCameraPos;
 		break;
 	case 'g':
-		g_bShowOtherLights = !g_bShowOtherLights;
+		g_bDrawLightPos = !g_bDrawLightPos;
 		break;
 	case 'p':
 		g_timer.TogglePause();
 	}
 
 	if(g_pViewPole)
+	{
 		g_pViewPole->CharPress(key);
+		g_pObjPole->CharPress(key);
+	}
 }
 
 unsigned int defaults(unsigned int displayMode, int &width, int &height)
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.