Commits

Jason McKesson  committed 1efa9f6

Added the ability to pause/unpause the light's rotation.

  • Participants
  • Parent commits 740c6be

Comments (0)

Files changed (3)

File Tut 09 Plane Lights/Fragment Attenuation.cpp

 
 static float g_fLightHeight = 1.5f;
 static float g_fLightRadius = 1.0f;
+static bool g_bRotateLight = true;
+
+static float g_fRotateTime = 0.0f;
+static float g_fPrevTime = 0.0f;
 
 glm::vec4 CalcLightPosition()
 {
 	const float fLoopDuration = 5.0f;
 	const float fScale = 3.14159f * 2.0f / fLoopDuration;
 
-	float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fCurrTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fDeltaTime = fCurrTime - g_fPrevTime;
+	g_fPrevTime = fCurrTime;
 
-	float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);
+	if(g_bRotateLight)
+		g_fRotateTime += fDeltaTime;
+
+	float fCurrTimeThroughLoop = fmodf(g_fRotateTime, fLoopDuration);
 
 	glm::vec4 ret(0.0f, g_fLightHeight, 0.0f, 1.0f);
 
 
 	case 'y': g_bDrawLight = !g_bDrawLight; break;
 	case 't': g_bScaleCyl = !g_bScaleCyl; break;
+	case 'b': g_bRotateLight = !g_bRotateLight; break;
 
 	case 'h':
 		g_bUseRSquare = !g_bUseRSquare;

File Tut 09 Plane Lights/Fragment Point Lighting.cpp

 
 static float g_fLightHeight = 1.5f;
 static float g_fLightRadius = 1.0f;
+static bool g_bRotateLight = true;
+
+static float g_fRotateTime = 0.0f;
+static float g_fPrevTime = 0.0f;
 
 glm::vec4 CalcLightPosition()
 {
 	const float fLoopDuration = 5.0f;
 	const float fScale = 3.14159f * 2.0f / fLoopDuration;
 
-	float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fCurrTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fDeltaTime = fCurrTime - g_fPrevTime;
+	g_fPrevTime = fCurrTime;
 
-	float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);
+	if(g_bRotateLight)
+		g_fRotateTime += fDeltaTime;
+
+	float fCurrTimeThroughLoop = fmodf(g_fRotateTime, fLoopDuration);
 
 	glm::vec4 ret(0.0f, g_fLightHeight, 0.0f, 1.0f);
 
 	case 'y': g_bDrawLight = !g_bDrawLight; break;
 	case 't': g_bScaleCyl = !g_bScaleCyl; break;
 	case 'h': g_bUseFragmentLighting = !g_bUseFragmentLighting; break;
+	case 'b': g_bRotateLight = !g_bRotateLight; break;
 	}
 
 	if(g_fLightRadius < 0.2f)

File Tut 09 Plane Lights/Vertex Point Lighting.cpp

 
 static float g_fLightHeight = 1.5f;
 static float g_fLightRadius = 1.0f;
+static bool g_bRotateLight = true;
+
+static float g_fRotateTime = 0.0f;
+static float g_fPrevTime = 0.0f;
 
 glm::vec4 CalcLightPosition()
 {
 	const float fLoopDuration = 5.0f;
 	const float fScale = 3.14159f * 2.0f / fLoopDuration;
 
-	float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fCurrTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
+	float fDeltaTime = fCurrTime - g_fPrevTime;
+	g_fPrevTime = fCurrTime;
 
-	float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);
+	if(g_bRotateLight)
+		g_fRotateTime += fDeltaTime;
+
+	float fCurrTimeThroughLoop = fmodf(g_fRotateTime, fLoopDuration);
 
 	glm::vec4 ret(0.0f, g_fLightHeight, 0.0f, 1.0f);
 
 	case 'J': g_fLightRadius -= 0.05f; break;
 
 	case 'y': g_bDrawLight = !g_bDrawLight; break;
+	case 'b': g_bRotateLight = !g_bRotateLight; break;
 	}
 
 	if(g_fLightRadius < 0.2f)