Source

gltut / Tut 09 Plane Lights / Fragment Attenuation.cpp

Diff from to

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;