diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml
index 2192918..f48c5b2 100644
--- a/data/levels/Level1.xml
+++ b/data/levels/Level1.xml
@@ -11936,6 +11936,38 @@
105
0
+
+ sunStart
+ false
+ -216
+ 20
+ 34
+ -
+ -
+ 10
+ false
+ 0
+ sunStart.lua
+ 0
+ 105
+ 0
+
+
+ sunUpdate
+ false
+ -216
+ 20
+ 34
+ -
+ -
+ 10
+ false
+ 0
+ sunUpdate.lua
+ 0
+ 105
+ 0
+
diff --git a/data/levels/scripts/sunUpdate.lua b/data/levels/scripts/sunUpdate.lua
index 49d25af..972c629 100644
--- a/data/levels/scripts/sunUpdate.lua
+++ b/data/levels/scripts/sunUpdate.lua
@@ -14,8 +14,8 @@ function trigger(objectToChange)
end
timeDiff = timeDiff/maxTimeDiff
local x = 1 - 0.3 * timeDiff
- local y = 0.7 * timeDiff
- local z = timeDiff^0.5 * 0.6 -0.1
- level:setSunAngle(x,y,z)
+ local y = math.sqrt(timeDiff) * 1.0 - 0.1
+ local z = 0.7 * timeDiff
+ level:setSunDirection(x,y,z)
end
end
diff --git a/level.cc b/level.cc
index edd58a2..735a3d2 100644
--- a/level.cc
+++ b/level.cc
@@ -40,6 +40,7 @@ void Level::load() {
.addFunction("moveObject", &Level::moveObject)
.addFunction("resetPlayer", &Level::resetPlayer)
.addFunction("movePlayer", &Level::movePlayer)
+ .addFunction("setSunDirection", &Level::setSunDirection)
.endClass();
//Push the level to Lua as a global variable
luabridge::push(luaState, this);
@@ -229,6 +230,13 @@ void Level::setDirectionalLight(Light light) {
this->directionalLight = light;
}
+void Level::setSunDirection(float x, float y, float z){
+ glm::vec3 lightPosition = glm::vec3(x,y,z);
+ glm::vec3 lightColour = this->directionalLight.getColour();
+ float lightIntensity = this->directionalLight.getIntensity();
+ this->directionalLight = Light(lightPosition, lightColour, lightIntensity);
+}
+
Physics* Level::getPhysics() {
return &physics;
}
diff --git a/level.hh b/level.hh
index 197c6e6..e18db48 100644
--- a/level.hh
+++ b/level.hh
@@ -49,6 +49,7 @@ class Level {
void setAmbientLight(glm::vec3 colour);
void setFogColour(glm::vec4 colour);
void setDirectionalLight(Light light);
+ void setSunDirection(float x, float y, float z);
Physics* getPhysics();
unsigned int getObjectsVectorSize();
unsigned int getPhysicsObjectsVectorSize();