Added basis for point light

This commit is contained in:
Robert 2021-01-26 16:03:41 +01:00
parent 862ef6d34b
commit b51c5a7557
6 changed files with 105 additions and 6 deletions

48
src/lighting/point.cpp Normal file
View file

@ -0,0 +1,48 @@
#include "lighting/point.hpp"
#include <transformable.hpp>
namespace oglu
{
PointLight::PointLight() :
position(new glm::vec3(0.0f)), color(oglu::Color::White)
{
}
PointLight::PointLight(const glm::vec3& position, const Color& color) :
position(new glm::vec3(0.0f)), color(color)
{
memcpy(this->position, &position, sizeof(glm::vec3));
}
PointLight::PointLight(const PointLight& other) :
position(new glm::vec3(0.0f)), color(other.color)
{
memcpy(this->position, position, sizeof(glm::vec3));
}
PointLight::~PointLight()
{
if(!isLinked)
delete position;
}
void PointLight::LinkPositionToTransformable(Transformable& link)
{
if (!isLinked)
delete position;
position = &link.translation;
}
void PointLight::UnlinkPositionFromTransformable()
{
if (isLinked)
position = new glm::vec3(0.0f);
}
float* PointLight::GetPositionPointer()
{
return &((*position)[0]);
}
}

View file

@ -183,9 +183,9 @@ namespace oglu
recalculateMatrix = true;
}
const glm::mat4& Transformable::GetMatrix()
const glm::mat4& Transformable::GetMatrix(bool forceRecalc)
{
if (recalculateMatrix)
if (recalculateMatrix || forceRecalc)
{
transformation = glm::mat4(1.0f);
transformation = glm::translate(transformation, translation);