From e5137c4c6194a41c13eb0752aa199b270481902f Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Thu, 4 Mar 2021 10:41:45 -0600 Subject: [PATCH] Directional Light get/set --- core/Light.cpp | 10 +++++++++- core/Light.h | 15 ++++++++++++++- core/Shaders/Shader.cpp | 2 +- demo/exampleworld/main.lua | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/Light.cpp b/core/Light.cpp index 9d5f940..c130529 100644 --- a/core/Light.cpp +++ b/core/Light.cpp @@ -12,7 +12,7 @@ This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, +nnn by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. DESCRIPTION @@ -92,6 +92,14 @@ DirectionalLight::DirectionalLight(Vector3 direction, Vector3 color, float ambie this->specular = specular; } +Vector3 DirectionalLight::GetDirection() { + return direction; +} + +void DirectionalLight::SetDirection(Vector3 direction) { + this->direction = direction; +} + DirectionalLight *DirectionalLight::Create() { return new DirectionalLight; } diff --git a/core/Light.h b/core/Light.h index 097cb03..624ef8d 100644 --- a/core/Light.h +++ b/core/Light.h @@ -95,13 +95,26 @@ protected: */ class DirectionalLight : public Light { public: - Vector3 direction; DirectionalLight(); DirectionalLight(Vector3 direction, Vector3 color, float ambient, float diffuse, float specular); + + /** + The direction from which this light is coming. + returns The direction of the light. + */ + Vector3 GetDirection(); + /** + Set the direction from which the light is coming. + @param direction The desired light direction + */ + void SetDirection(Vector3 direction); + virtual Name GetType() const; virtual DirectionalLight *Create(); virtual DirectionalLight *Duplicate(); virtual DirectionalLight *Instance(); +private: + Vector3 direction; }; #endif /* LIGHT_H */ diff --git a/core/Shaders/Shader.cpp b/core/Shaders/Shader.cpp index 248145a..43fab07 100644 --- a/core/Shaders/Shader.cpp +++ b/core/Shaders/Shader.cpp @@ -74,7 +74,7 @@ void Shader::UpdateMaterial(Material material) { } void Shader::UpdateDirectionalLight(DirectionalLight directionalLight) { - glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.direction)); + glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.GetDirection())); glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.GetColor())); glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.GetAmbient()); diff --git a/demo/exampleworld/main.lua b/demo/exampleworld/main.lua index 8a631e2..3bdd0ea 100644 --- a/demo/exampleworld/main.lua +++ b/demo/exampleworld/main.lua @@ -37,7 +37,7 @@ function init() camera:Translate(couch.Vector3(0.0, 0.0, 10.0)) local light = couch.DirectionalLight() - light.direction = couch.Vector3(0.0, -1.0, -1.0) + light:SetDirection(couch.Vector3(0.0, -1.0, -1.0)) light:SetColor(couch.Vector3(1.0, 1.0, 1.0)) light:SetAmbient(0.2) light:SetDiffuse(1.0)