3#define GLM_ENABLE_EXPERIMENTAL
6#include "glm/gtc/matrix_transform.hpp"
7#include "glm/gtc/type_ptr.hpp"
9static glm::mat4 getRotationMatrix(glm::vec3 newRot) {
10 float radX = glm::radians(newRot.x);
11 float radY = glm::radians(newRot.y);
12 float radZ = glm::radians(newRot.z);
14 glm::mat4 rotationX = glm::rotate(glm::mat4(1.0f), radX, glm::vec3(1.0f, 0.0f, 0.0f));
15 glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), radY, glm::vec3(0.0f, 1.0f, 0.0f));
16 glm::mat4 rotationZ = glm::rotate(glm::mat4(1.0f), radZ, glm::vec3(0.0f, 0.0f, 1.0f));
18 glm::mat4 rotationMatrix = rotationZ * rotationY * rotationX;
19 return rotationMatrix;
22static glm::vec2 rotatePoint(
float x,
float y,
float centerX,
float centerY,
float radians) {
23 float dx = x - centerX;
24 float dy = y - centerY;
26 centerX + dx * cos(radians) - dy * sin(radians),
27 centerY + dx * sin(radians) + dy * cos(radians)
30static glm::vec2 rotatePoint(
float x,
float y,
float radians) {
31 return rotatePoint(x,y, 0.0f, 0.0f, radians);
39using Position = glm::vec3;
40using Size = glm::vec3;
41using Rotation = glm::vec3;
43using Normal = glm::vec3;
48 Color() : r(0), g(0), b(0), a(0) {}
49 Color(GLubyte R, GLubyte G, GLubyte B, GLubyte A) : r(R), g(G), b(B), a(A) {}
51 glm::vec4 toVec4()
const {
52 return glm::vec4(r, g, b, a) / 255.0f;
55 static Color fromVec4(
const glm::vec4& v) {
57 static_cast<GLubyte
>(v.r * 255.0f),
58 static_cast<GLubyte
>(v.g * 255.0f),
59 static_cast<GLubyte
>(v.b * 255.0f),
60 static_cast<GLubyte
>(v.a * 255.0f)
69 Color operator*(
float scalar)
const {
70 return Color(
static_cast<GLubyte
>(r * scalar),
71 static_cast<GLubyte
>(g * scalar),
72 static_cast<GLubyte
>(b * scalar),
73 static_cast<GLubyte
>(a * scalar));
78 return Color(
static_cast<GLubyte
>(r + other.r),
79 static_cast<GLubyte
>(g + other.g),
80 static_cast<GLubyte
>(b + other.b),
81 static_cast<GLubyte
>(a + other.a));
84 bool operator==(
const Color& other)
const {
85 return r == other.r && g == other.g && b == other.b && a == other.a;
91 Position position = Position(0);
93 inline void setPosition(Position m_position) {
94 position = m_position;
104 void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
113 Normal normal = Normal();
121 inline void setUV(UV m_uv) {