We got a skybox

This commit is contained in:
2026-01-21 06:05:35 +01:00
parent b9878f2a06
commit a5b26f3bdd
27 changed files with 843 additions and 42 deletions

View File

@@ -4,7 +4,10 @@
#include <random>
#include <cmath>
#include "destrum/ObjectModel/GameObject.h"
#include "destrum/ObjectModel/Transform.h"
#include "destrum/Components/MeshRendererComponent.h"
#include "destrum/Util/GameState.h"
static glm::vec3 RandomUnitVector(std::mt19937& rng)
{
@@ -48,11 +51,6 @@ void OrbitAndSpin::BuildOrbitBasis()
void OrbitAndSpin::Update()
{
// If your engine provides dt via a global/time service, use that instead.
// Since your Spinner takes dt indirectly, I'm assuming Component::Update()
// is called once per frame and you can access dt somewhere globally.
//
// If you CAN pass dt into Update, change signature to Update(float dt).
float dt = 1.0f / 60.0f;
// orbit
@@ -60,10 +58,37 @@ void OrbitAndSpin::Update()
float a = m_OrbitAngle + m_OrbitPhase;
glm::vec3 offset = (m_U * std::cos(a) + m_V * std::sin(a)) * m_Radius;
// IMPORTANT: if SetWorldPosition resets TRS in your engine, this will wipe scale unless you set it again after.
GetTransform().SetWorldPosition(m_Center + offset);
// self spin (local rotation)
// spin
glm::quat dq = glm::angleAxis(m_SpinSpeed * dt, glm::normalize(m_SpinAxis));
auto current = GetTransform().GetLocalRotation(); // adapt to your API
auto current = GetTransform().GetLocalRotation();
GetTransform().SetLocalRotation(glm::normalize(dq * current));
// grow (always positive)
m_GrowPhase += m_GrowSpeed * dt;
float t = 0.5f * (std::sin(m_GrowPhase) + 1.0f); // 0..1
float s = 1.50 + t * 0.70f; // 0.05..0.15 (pick what you want)
GetTransform().SetLocalScale(glm::vec3(std::sin(m_GrowPhase)));
// material color
// auto& mat = GameState::GetInstance().Renderer().getMaterialMutable(m_MaterialID);
// mat.baseColor = glm::vec3(
// 0.5f + 0.5f * std::sin(m_OrbitAngle * 2.0f),
// 0.5f + 0.5f * std::sin(m_OrbitAngle * 3.0f + 2.0f),
// 0.5f + 0.5f * std::sin(m_OrbitAngle * 4.0f + 4.0f)
// );
// GameState::GetInstance().Renderer().updateMaterialGPU(m_MaterialID);
}
void OrbitAndSpin::Start() {
auto meshComp = this->GetGameObject()->GetComponent<MeshRendererComponent>();
m_MaterialID = meshComp->GetMaterialID();
m_BaseScale = GetTransform().GetLocalScale(); // <-- important
}