Files
Destrum/destrum/include/destrum/Components/OrbitAndSpin.h
2026-01-20 00:13:54 +01:00

49 lines
1.2 KiB
C++

#ifndef ORBITANDSPIN_H
#define ORBITANDSPIN_H
#include <destrum/ObjectModel/Component.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
class OrbitAndSpin final : public Component {
public:
OrbitAndSpin(
GameObject& parent,
float radius,
glm::vec3 center = glm::vec3(0.0f)
)
: Component(parent, "OrbitAndSpin")
, m_Radius(radius)
, m_Center(center)
{}
// Call after constructing if you want deterministic randomness per object
void Randomize(uint32_t seed);
void Update() override;
// optional setters
void SetRadius(float r) { m_Radius = r; }
void SetCenter(glm::vec3 c) { m_Center = c; }
private:
void BuildOrbitBasis(); // builds m_U/m_V from m_OrbitAxis
float m_Radius = 5.0f;
glm::vec3 m_Center{0.0f};
// orbit
glm::vec3 m_OrbitAxis{0,1,0}; // normal of the orbit plane
float m_OrbitSpeed = 1.0f; // rad/sec
float m_OrbitAngle = 0.0f; // current angle
float m_OrbitPhase = 0.0f; // starting offset
glm::vec3 m_U{1,0,0}; // orbit basis axis 1
glm::vec3 m_V{0,0,1}; // orbit basis axis 2
// self spin
glm::vec3 m_SpinAxis{0,1,0};
float m_SpinSpeed = 2.0f; // rad/sec
};
#endif //ORBITANDSPIN_H