57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
// =============================================
|
|
// Aster: nodes.h
|
|
// Copyright (c) 2020-2024 Anish Bhobe
|
|
// =============================================
|
|
|
|
#pragma once
|
|
|
|
#include "aster/aster.h"
|
|
|
|
#include <EASTL/vector.h>
|
|
|
|
struct Nodes
|
|
{
|
|
struct Transform
|
|
{
|
|
mat4 m_GlobalTransforms;
|
|
mat4 m_NormalTransforms;
|
|
|
|
explicit Transform(const mat4 &transform)
|
|
: m_GlobalTransforms(transform)
|
|
, m_NormalTransforms(transpose(inverse(mat3{transform})))
|
|
{
|
|
}
|
|
|
|
Transform &
|
|
operator=(const mat4 &transform)
|
|
{
|
|
m_GlobalTransforms = transform;
|
|
m_NormalTransforms = transpose(inverse(mat3{transform}));
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
eastl::vector<mat4> m_Transforms;
|
|
eastl::vector<Transform> m_GlobalTransforms;
|
|
/// Parents are also used for bookkeeping
|
|
eastl::vector<u32> m_Parents_;
|
|
bool m_Dirty = true;
|
|
|
|
constexpr static u32 ROOT_BIT = 1u << 31;
|
|
constexpr static u32 DIRTY_BIT = 1u << 30;
|
|
constexpr static u32 PARENT_MASK = ~(ROOT_BIT | DIRTY_BIT);
|
|
|
|
u32 Add(const mat4 &transform, const i32 parent = -1);
|
|
[[nodiscard]] const mat4 &Get(const u32 index) const;
|
|
void Set(const u32 index, const mat4 &transform);
|
|
[[nodiscard]] u32 Count() const;
|
|
|
|
[[nodiscard]] const mat4 &operator[](const u32 index) const;
|
|
[[nodiscard]] mat4 &operator[](const u32 index);
|
|
|
|
[[nodiscard]] usize GetGlobalTransformByteSize() const;
|
|
[[nodiscard]] const Transform *GetGlobalTransformPtr() const;
|
|
|
|
bool Update();
|
|
};
|