Skip to content
Snippets Groups Projects
Commit 2cd066b1 authored by JonShard's avatar JonShard
Browse files

Moved sun rotation to dayTime value. NOw prints time of day to gui.

parent 31b0108f
No related branches found
No related tags found
No related merge requests found
......@@ -101,7 +101,7 @@ pointlight: blueish
hasSun: 1
dirlight: distantSunLight
rotation: 0 0 0
angleVelocity: 0 20 0
angleVelocity: 0 0 0
intensities: 1 1 1
......
......@@ -29,7 +29,6 @@ private:
// Member hacked in for the exam. Move to a appropirate classes or containers
// for a good impolementation of the exam task:
static bool m_dayMoving;
static bool m_marker;
public:
......@@ -51,6 +50,10 @@ public:
static float m_planeMinSpeed;
static float m_planeMaxSpeed;
static bool m_dayMoving;
static float m_timeOfDay;
static float m_maxDay;
static void OnInputKeyPress(GLFWwindow* window, int keyCode, int scanCode, int mods);
static void OnInputKeyHold(GLFWwindow* window, int keyCode, int scanCode, int mods);
static void OnInputKeyUnpress(GLFWwindow* window, int keyCode, int scanCode, int mods);
......
......@@ -10,9 +10,11 @@ namespace overkill
bool Input::m_marker = false;
float Input::m_season = 0;
float Input::m_maxSeason = 360;
float Input::m_planeSpeed = 0.006;
float Input::m_planeMinSpeed = 0.001;
float Input::m_planeMaxSpeed = 0.026;
float Input::m_planeSpeed = 0.016;
float Input::m_planeMinSpeed = 0.004;
float Input::m_planeMaxSpeed = 0.056;
float Input::m_timeOfDay = 0;
float Input::m_maxDay = 24;
float Input::m_fovy = C::FOV;
float Input::m_cursorX = 0;
......@@ -91,39 +93,19 @@ namespace overkill
// PRESS 6 TO change daytime to morning.
else if(keyCode == GLFW_KEY_6) {
Entity* sun = Scene::getEntityByTag("distantSunLight");
if (sun == nullptr)
{
LOG_ERROR("No Sun in scene by tag distantSunLight"); // Terminates app.
}
sun-> setRotation(glm::vec3(0,-180,0));
m_timeOfDay = 4;
}
// PRESS 7 TO change daytime to noon
else if(keyCode == GLFW_KEY_7) {
Entity* sun = Scene::getEntityByTag("distantSunLight");
if (sun == nullptr)
{
LOG_ERROR("No Sun in scene by tag distantSunLight"); // Terminates app.
}
sun-> setRotation(glm::vec3(0,-90,0));
m_timeOfDay = 10;
}
// PRESS 8 TO change daytime to afternoon
else if(keyCode == GLFW_KEY_8) {
Entity* sun = Scene::getEntityByTag("distantSunLight");
if (sun == nullptr)
{
LOG_ERROR("No Sun in scene by tag distantSunLight"); // Terminates app.
}
sun-> setRotation(glm::vec3(0,-45,0));
m_timeOfDay = 14;
}
// PRESS 9 TO change daytime to night
else if(keyCode == GLFW_KEY_9) {
Entity* sun = Scene::getEntityByTag("distantSunLight");
if (sun == nullptr)
{
LOG_ERROR("No Sun in scene by tag distantSunLight"); // Terminates app.
}
sun-> setRotation(glm::vec3(0,0,0));
m_timeOfDay = 0;
}
// PRESS 0 TO toggle daytime changing.
else if(keyCode == GLFW_KEY_0) {
......
......@@ -119,6 +119,8 @@ int main(int argc, char** args)
"\nFrame rate: %d\nLast frame dt: %f\nTotal runtime: %f\n\n", oldFrameRate, dt, t);
float seasonSpeed = 20; // Basicly days per second.
float dayCycleSpeed = 3;
// Update season:
if (Input::m_seasonMoving)
{
Input::m_season += seasonSpeed * dt;
......@@ -139,6 +141,25 @@ int main(int argc, char** args)
program.bind();
GLCall(glUniform1f(program.getUniformLocation("season"), Input::m_season));
// Update day:
if (Input::m_dayMoving)
{
Input::m_timeOfDay += dayCycleSpeed * dt;
}
if (Input::m_timeOfDay > Input::m_maxDay)
{
Input::m_timeOfDay = 0;
}
ImGui::Text("Time of day: %d:%d", int(Input::m_timeOfDay), int(Input::m_timeOfDay * 60) % 60);
Entity* sun = Scene::getEntityByTag("distantSunLight"); // Rotate sun.
if (sun == nullptr)
{
LOG_ERROR("No Sun in scene by tag distantSunLight"); // Terminates app.
}
sun-> setRotation(glm::vec3(0, (Input::m_timeOfDay / Input::m_maxDay) * 360,0));
// Plane controls:
Entity* plane = Scene::getEntityByTag("planeCore");
if (plane == nullptr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment