ADD: Convert translation to ndc

This commit is contained in:
sebastian 2026-02-12 10:18:59 +01:00
parent 1e266709c5
commit 47d18092ac
2 changed files with 62 additions and 1 deletions

View File

@ -0,0 +1,56 @@
//
// Created by sebastian on 12.02.26.
//
#ifndef DICEWARS_SIEDLER_LAYOUTSTYLE_H
#define DICEWARS_SIEDLER_LAYOUTSTYLE_H
enum class SizeUnit {
Pixels,
Percent
};
struct SizeValue {
float value;
SizeUnit unit;
};
struct Margin {
SizeValue left;
SizeValue right;
SizeValue top;
SizeValue bottom;
};
enum class FlexDirection {
Row,
Column
};
enum class JustifyContent {
Start,
Center,
End,
SpaceBetween,
};
enum class AlignItems {
Start,
Center,
End,
Stretch
};
struct LayoutStyle {
SizeValue width = {1.0f, SizeUnit::Percent};
SizeValue height = {1.0f, SizeUnit::Percent};
Margin margin;
FlexDirection flexDirection = FlexDirection::Column;
JustifyContent justifyContent = JustifyContent::Start;
AlignItems alignItems = AlignItems::Start;
float flexGrow = 0.0f;
};
#endif //DICEWARS_SIEDLER_LAYOUTSTYLE_H

View File

@ -4,6 +4,7 @@
#ifndef MATHUTILS_H #ifndef MATHUTILS_H
#define MATHUTILS_H #define MATHUTILS_H
#include "../core/Application.h"
#include "../layer/entities/Camera.h" #include "../layer/entities/Camera.h"
#include "glm/mat4x4.hpp" #include "glm/mat4x4.hpp"
#include "glm/vec3.hpp" #include "glm/vec3.hpp"
@ -24,8 +25,12 @@ namespace MathUtils {
} }
inline static glm::mat4 createTransformationMatrix(const glm::vec2 translation, const glm::vec2 scale) { inline static glm::mat4 createTransformationMatrix(const glm::vec2 translation, const glm::vec2 scale) {
glm::vec2 translationNDC;
translationNDC.x = translation.x * 2.0f - 1.0f + scale.x;
translationNDC.y = 1.0f - translation.y * 2.0f - scale.y;
auto matrix = glm::identity<glm::mat4>(); auto matrix = glm::identity<glm::mat4>();
matrix = glm::translate(matrix, glm::vec3( translation.x, translation.y, 0.0f)); matrix = glm::translate(matrix, glm::vec3( translationNDC, 0.0f));
matrix = glm::scale(matrix, glm::vec3(scale.x, scale.y, 1.0f)); matrix = glm::scale(matrix, glm::vec3(scale.x, scale.y, 1.0f));
return matrix; return matrix;
} }