83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <iostream>
|
|
#include <ostream>
|
|
#include <sophia/handles.hpp>
|
|
#include <sophia/math.hpp>
|
|
#include <string>
|
|
|
|
namespace sophia {
|
|
|
|
struct TagComponent {
|
|
std::string tag; // entt::hashed_string ?
|
|
uint32_t mask = 0;
|
|
};
|
|
|
|
struct TransformComponent {
|
|
glm::vec3 position{0.f, 0.f, 0.f};
|
|
glm::quat rotation{1.f, 0.f, 0.f, 0.f};
|
|
glm::vec3 scale{1.f, 1.f, 1.f};
|
|
|
|
glm::mat4 mat4() const {
|
|
return glm::translate(glm::mat4{1.f}, position) * glm::mat4_cast(rotation) *
|
|
glm::scale(glm::mat4{1.f}, scale);
|
|
}
|
|
|
|
glm::mat3 normalMatrix() const {
|
|
return glm::mat3{glm::transpose(glm::inverse(mat4()))};
|
|
}
|
|
|
|
friend std::ostream& operator<<(std::ostream& os,
|
|
const TransformComponent& transform) {
|
|
os << "TransformComponent {\n"
|
|
<< " Position: (" << transform.position.x << ", "
|
|
<< transform.position.y << ", " << transform.position.z << ")\n"
|
|
<< " Rotation (w, x, y, z): (" << transform.rotation.w << ", "
|
|
<< transform.rotation.x << ", " << transform.rotation.y << ", "
|
|
<< transform.rotation.z << ")\n"
|
|
<< " Scale: (" << transform.scale.x << ", " << transform.scale.y << ", "
|
|
<< transform.scale.z << ")\n"
|
|
<< "}";
|
|
return os;
|
|
}
|
|
};
|
|
|
|
struct MeshComponent {
|
|
MeshHandle handle;
|
|
};
|
|
|
|
struct CameraComponent {
|
|
struct Orthographic {
|
|
float height = 10.f;
|
|
float nearPlane = -1.f;
|
|
float farPlane = 1.f;
|
|
};
|
|
|
|
struct Perspective {
|
|
float fov = glm::radians(60.f);
|
|
float nearPlane = 0.1f;
|
|
float farPlane = 100.f;
|
|
};
|
|
|
|
enum class Projection { Orthographic, Perspective };
|
|
|
|
Projection projection = Projection::Orthographic;
|
|
Orthographic ortho;
|
|
Perspective perspective;
|
|
|
|
glm::mat4 getProjection(float aspect) const {
|
|
if (projection == Projection::Perspective) {
|
|
return glm::perspective(perspective.fov, aspect, perspective.nearPlane,
|
|
perspective.farPlane);
|
|
}
|
|
|
|
float halfHeight = ortho.height / 2.f;
|
|
float halfWidth = halfHeight * aspect;
|
|
return glm::ortho(-halfWidth, halfWidth, -halfHeight, halfHeight,
|
|
ortho.nearPlane, ortho.farPlane);
|
|
}
|
|
};
|
|
|
|
} // namespace sophia
|