Replace glm with vec.h

Vec2, IVec2, Vec3, Vec4, IVec4 and a column-major Mat4, with glm's formulas, in one header.
Free functions are vec_ and mat4_ prefixed. The leaked using namespace glm is gone.
Render goldens still match.
This commit is contained in:
shweet committed 2026-11-22 18:15:02 -05:00
1 parent c38a3a9890
commit 03bbb93ba6
79 files changed
+1232 -810

No files matched your search

+27 -28
View File
@@ -8,13 +8,13 @@
void frame_mix(Frame& frame, const Frame& next, float amount)
{
frame.rotation = glm::mix(frame.rotation, next.rotation, amount);
frame.position = glm::mix(frame.position, next.position, amount);
frame.scale = glm::mix(frame.scale, next.scale, amount);
frame.skew = glm::mix(frame.skew, next.skew, amount);
frame.colorOffset = glm::mix(frame.colorOffset, next.colorOffset, amount);
frame.tint = glm::mix(frame.tint, next.tint, amount);
frame.blur = glm::mix(frame.blur, next.blur, amount);
frame.rotation = vec_mix(frame.rotation, next.rotation, amount);
frame.position = vec_mix(frame.position, next.position, amount);
frame.scale = vec_mix(frame.scale, next.scale, amount);
frame.skew = vec_mix(frame.skew, next.skew, amount);
frame.colorOffset = vec_mix(frame.colorOffset, next.colorOffset, amount);
frame.tint = vec_mix(frame.tint, next.tint, amount);
frame.blur = vec_mix(frame.blur, next.blur, amount);
}
// Splits an interpolated frame into uninterpolated frames of at most `interval`. The first keeps the frame's uid.
@@ -31,14 +31,14 @@ std::vector<Frame> frame_bake_split(const Frame& original, const Frame& next, in
baked.duration = std::min(interval, total - duration);
baked.interpolation = Interpolation::NONE;
if (isRoundScale)
baked.scale = glm::round(baked.scale);
baked.scale = vec_round(baked.scale);
if (isRoundRotation)
baked.rotation = std::round(baked.rotation);
}
return frames;
}
glm::mat4 frame_parent_model_get(const Frame& frame)
Mat4 frame_parent_model_get(const Frame& frame)
{
return quad_model_parent_get(frame.position, {}, percent_to_unit(frame.scale), frame.rotation,
percent_to_unit(frame.skew));
@@ -48,20 +48,20 @@ void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRou
bool isUseRootPivot)
{
auto rootScale = percent_to_unit(rootFrame.scale);
auto pivot = isUseRootPivot ? rootFrame.position : glm::vec2();
auto pivot = isUseRootPivot ? rootFrame.position : Vec2();
auto offset = (frame.position - pivot) * rootScale;
auto radians = glm::radians(rootFrame.rotation);
auto cos = std::cos(radians);
auto sin = std::sin(radians);
auto angle = radians(rootFrame.rotation);
auto cos = std::cos(angle);
auto sin = std::sin(angle);
frame.position = rootFrame.position + glm::vec2(offset.x * cos - offset.y * sin, offset.x * sin + offset.y * cos);
frame.position = rootFrame.position + Vec2(offset.x * cos - offset.y * sin, offset.x * sin + offset.y * cos);
frame.scale *= rootScale;
frame.rotation += rootFrame.rotation;
frame.tint *= rootFrame.tint;
frame.colorOffset += rootFrame.colorOffset;
if (isRoundScale)
frame.scale = glm::round(frame.scale);
frame.scale = vec_round(frame.scale);
if (isRoundRotation)
frame.rotation = std::round(frame.rotation);
}
@@ -181,8 +181,8 @@ void frame_bake(Track& track, int index, int interval, bool isRoundScale, bool i
track.frames.insert(track.frames.begin() + index, baked.begin(), baked.end());
}
void frames_generate_from_grid(Track& track, glm::ivec2 startPosition, glm::ivec2 size, glm::vec2 pivot, int columns,
int count, int duration)
void frames_generate_from_grid(Track& track, IVec2 startPosition, IVec2 size, Vec2 pivot, int columns, int count,
int duration)
{
for (int i = 0; i < count; ++i)
{
@@ -190,7 +190,7 @@ void frames_generate_from_grid(Track& track, glm::ivec2 startPosition, glm::ivec
frame.duration = duration;
frame.pivot = pivot;
frame.size = size;
frame.crop = startPosition + glm::ivec2(size.x * (i % columns), size.y * (i / columns));
frame.crop = startPosition + IVec2(size.x * (i % columns), size.y * (i / columns));
}
}
@@ -267,31 +267,30 @@ void frames_change(Track& track, FrameChange change, ItemType itemType, ChangeTy
}
// Bounds of all visible layer frames over the animation's length, or -1 when nothing is drawn.
glm::vec4 animation_rect(const Model& model, const Animation& animation, bool isRootTransform,
const LibraryGet& library_get)
Vec4 animation_rect(const Model& model, const Animation& animation, bool isRootTransform, const LibraryGet& library_get)
{
constexpr glm::ivec2 CORNERS[4] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
glm::vec2 min{std::numeric_limits<float>::infinity()};
glm::vec2 max{-std::numeric_limits<float>::infinity()};
constexpr IVec2 CORNERS[4] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
Vec2 min{std::numeric_limits<float>::infinity()};
Vec2 max{-std::numeric_limits<float>::infinity()};
bool isAny = false;
for (float time = 0.0f; time < (float)animation.frameNum; time += 1.0f)
for (auto& draw : animation_draws_get(
model, animation, {.time = time, .isRootTransform = isRootTransform, .library_get = library_get}))
{
if (draw.type != DrawType::LAYER || draw.frame.size == glm::vec2())
if (draw.type != DrawType::LAYER || draw.frame.size == Vec2())
continue;
auto transform = draw.parent * draw_quad_model_get(draw);
for (auto& corner : CORNERS)
{
auto world = glm::vec2(transform * glm::vec4(corner, 0.0f, 1.0f));
min = glm::min(min, world);
max = glm::max(max, world);
auto world = Vec2(transform * Vec4(corner, 0.0f, 1.0f));
min = vec_min(min, world);
max = vec_max(max, world);
isAny = true;
}
}
if (!isAny)
return glm::vec4(-1.0f);
return Vec4(-1.0f);
return {min.x, min.y, max.x - min.x, max.y - min.y};
}