Files
Seele/src/Engine/Actor/DirectionalLightActor.cpp
T

38 lines
1.8 KiB
C++
Raw Normal View History

2023-03-09 17:39:57 +01:00
#include "DirectionalLightActor.h"
using namespace Seele;
2024-06-09 12:20:04 +02:00
DirectionalLightActor::DirectionalLightActor(PScene scene) : Actor(scene) { attachComponent<Component::DirectionalLight>(); }
2023-03-09 17:39:57 +01:00
2025-03-13 08:23:00 +01:00
DirectionalLightActor::DirectionalLightActor(PScene scene, Vector color, float intensity, Vector direction) : Actor(scene) {
2025-05-07 16:08:12 +02:00
attachComponent<Component::DirectionalLight>(Vector4(color, intensity));
Vector lightDirection = Vector(direction);
float dot = glm::dot(lightDirection, Math::Transform::FORWARD);
Quaternion rotation = Quaternion(1, 0, 0, 0);
// Handle the edge cases first
if (glm::epsilonEqual(dot, 1.0f, 0.00001f)) {
// Vectors are the same, no rotation
} else if (glm::epsilonEqual(dot, -1.0f, 0.00001f)) {
// Vectors are opposite need 180-degree rotation around any perpendicular axis
rotation = glm::angleAxis(glm::pi<float>(), Vector(0, 1, 0));
} else {
// Normal case
Vector axis = glm::normalize(glm::cross(lightDirection, Math::Transform::FORWARD));
float angle = std::acos(dot); // angle between vectors
rotation = glm::angleAxis(angle, axis);
}
attachComponent<Component::Transform>(Math::Transform(Vector(0, 0, 0), rotation));
2024-02-01 17:07:51 +01:00
}
2024-06-09 12:20:04 +02:00
DirectionalLightActor::~DirectionalLightActor() {}
2023-03-09 17:39:57 +01:00
2024-06-09 12:20:04 +02:00
Component::DirectionalLight& DirectionalLightActor::getDirectionalLightComponent() {
2023-03-09 17:39:57 +01:00
return accessComponent<Component::DirectionalLight>();
}
2024-06-09 12:20:04 +02:00
const Component::DirectionalLight& DirectionalLightActor::getDirectionalLightComponent() const {
2023-03-09 17:39:57 +01:00
return accessComponent<Component::DirectionalLight>();
2025-05-07 16:08:12 +02:00
}
Component::Transform& DirectionalLightActor::getTransformComponent() { return accessComponent<Component::Transform>(); }
const Component::Transform& DirectionalLightActor::getTransformComponent() const { return accessComponent<Component::Transform>(); }