Skip to content

Commit 81d016d

Browse files
author
Alfonse
committed
Tut12: All objects now properly positions. They have individual materials.
1 parent 6357348 commit 81d016d

19 files changed

+1659
-271
lines changed

Tut 12 Dynamic Range/Lights.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,31 @@ LightManager::LightManager()
7878
m_lightTimers.push_back(Framework::Timer(Framework::Timer::TT_LOOP, 15.0f));
7979
}
8080

81+
struct UpdateTimer
82+
{
83+
void operator()(Framework::Timer &timer) {timer.Update();}
84+
void operator()(std::pair<const std::string, Framework::Timer> &timeData)
85+
{timeData.second.Update();}
86+
};
87+
88+
struct PauseTimer
89+
{
90+
void operator()(Framework::Timer &timer) {timer.TogglePause();}
91+
void operator()(std::pair<const std::string, Framework::Timer> &timeData)
92+
{timeData.second.TogglePause();}
93+
};
94+
8195
void LightManager::UpdateTime()
8296
{
8397
m_keyLightTimer.Update();
84-
for(size_t loop = 0; loop < m_lightTimers.size(); loop++)
85-
{
86-
m_lightTimers[loop].Update();
87-
}
98+
std::for_each(m_lightTimers.begin(), m_lightTimers.end(), UpdateTimer());
99+
std::for_each(m_extraTimers.begin(), m_extraTimers.end(), UpdateTimer());
88100
}
89101

90102
bool LightManager::TogglePause()
91103
{
92-
for(size_t loop = 0; loop < m_lightTimers.size(); loop++)
93-
{
94-
m_lightTimers[loop].TogglePause();
95-
}
104+
std::for_each(m_lightTimers.begin(), m_lightTimers.end(), PauseTimer());
105+
std::for_each(m_extraTimers.begin(), m_extraTimers.end(), PauseTimer());
96106

97107
return m_keyLightTimer.TogglePause();
98108
}
@@ -105,7 +115,7 @@ LightBlock LightManager::GetLightPositions( const glm::mat4 &worldToCameraMat )
105115
lightData.lightAttenuation = g_fLightAttenuation;
106116

107117
lightData.lights[0].cameraSpaceLightPos =
108-
worldToCameraMat * glm::vec4(0.0f, 1.0f, 0.0f, 0.0f);
118+
worldToCameraMat * glm::vec4(0.0f, 0.981f, 0.196f, 0.0f);
109119

110120
lightData.lights[0].lightIntensity = glm::vec4(0.1f, 0.1f, 0.1f, 1.0f);
111121

@@ -116,7 +126,7 @@ LightBlock LightManager::GetLightPositions( const glm::mat4 &worldToCameraMat )
116126
glm::vec4 lightPosCameraSpace = worldToCameraMat * worldLightPos;
117127

118128
lightData.lights[light].cameraSpaceLightPos = lightPosCameraSpace;
119-
lightData.lights[light].lightIntensity = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f);
129+
lightData.lights[light].lightIntensity = glm::vec4(0.2f, 0.2f, 0.2f, 1.0f);
120130
}
121131

122132
return lightData;
@@ -131,3 +141,20 @@ glm::vec3 LightManager::GetWorldLightPosition( int lightIx ) const
131141
{
132142
return m_lightPos[lightIx].Interpolate(m_lightTimers[lightIx].GetAlpha());
133143
}
144+
145+
void LightManager::CreateTimer( const std::string &timerName,
146+
Framework::Timer::Type eType, float fDuration )
147+
{
148+
m_extraTimers[timerName] = Framework::Timer(eType, fDuration);
149+
}
150+
151+
float LightManager::GetTimerValue( const std::string &timerName ) const
152+
{
153+
ExtraTimerMap::const_iterator loc = m_extraTimers.find(timerName);
154+
155+
if(loc == m_extraTimers.end())
156+
return -1.0f;
157+
158+
return loc->second.GetAlpha();
159+
}
160+

Tut 12 Dynamic Range/Lights.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef LIGHTS_H
33
#define LIGHTS_H
44

5+
#include <map>
56
#include "../framework/Timer.h"
67
#include <glm/glm.hpp>
78
#include "../framework/Interpolators.h"
@@ -37,15 +38,19 @@ class LightManager
3738
int GetNumberOfPointLights() const;
3839
glm::vec3 GetWorldLightPosition(int iLightIx) const;
3940

41+
void CreateTimer(const std::string &timerName, Framework::Timer::Type eType, float fDuration);
42+
float GetTimerValue(const std::string &timerName) const;
43+
4044
private:
4145
typedef Framework::ConstVelLinearInterpolator<glm::vec3> LightInterpolator;
46+
typedef std::map<std::string, Framework::Timer> ExtraTimerMap;
4247

4348
Framework::Timer m_keyLightTimer;
4449
Framework::LinearInterpolator<glm::vec4> m_ambientInterpolator;
4550

4651
std::vector<LightInterpolator> m_lightPos;
4752
std::vector<Framework::Timer> m_lightTimers;
48-
53+
ExtraTimerMap m_extraTimers;
4954
};
5055

5156
#endif //LIGHTS_H

0 commit comments

Comments
 (0)