-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.cpp
48 lines (37 loc) · 1.17 KB
/
Light.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Light.h"
// +- constraints for random light positions
static const float maxRandX = 10;
static const float maxRandY = 20;
static const float maxRandZ = 10;
static const float lightSpeed = 5.0f;
Light::Light() :
m_position(0, 0, 0)
{
}
Light::Light(glm::vec3 const& color, float radius) :
m_position(0, 0, 0),
m_prevPosition(0,0,0),
m_interpolator(0)
{
m_color = color;
m_radius = radius;
m_nextPosition.x = (float)(rand()) / ((float)RAND_MAX / (2 * maxRandX)) - maxRandX;
m_nextPosition.y = (float)(rand()) / ((float)RAND_MAX / (maxRandY));
m_nextPosition.z = (float)(rand()) / ((float)RAND_MAX / (2 * maxRandZ)) - maxRandZ;
}
Light::~Light()
{
}
void Light::UpdatePosition(double dt)
{
m_interpolator += dt / lightSpeed;
m_position = m_prevPosition + (m_nextPosition - m_prevPosition) * m_interpolator;
if (m_interpolator >= 1.0f)
{
m_prevPosition = m_position;
m_nextPosition.x = (float)(rand()) / ((float)RAND_MAX / (2 * maxRandX)) - maxRandX;
m_nextPosition.y = (float)(rand()) / ((float)RAND_MAX / (maxRandY));
m_nextPosition.z = (float)(rand()) / ((float)RAND_MAX / (2 * maxRandZ)) - maxRandZ;
m_interpolator = 0;
}
}