TazGraph Project v0.1.0
Loading...
Searching...
No Matches
Vertex.h
1#pragma once
2
3#include "../pch.h"
4
5static glm::mat4 getRotationMatrix(glm::vec3 newRot) {
6 float radX = glm::radians(newRot.x);
7 float radY = glm::radians(newRot.y);
8 float radZ = glm::radians(newRot.z);
9
10 glm::mat4 rotationX = glm::rotate(glm::mat4(1.0f), radX, glm::vec3(1.0f, 0.0f, 0.0f));
11 glm::mat4 rotationY = glm::rotate(glm::mat4(1.0f), radY, glm::vec3(0.0f, 1.0f, 0.0f));
12 glm::mat4 rotationZ = glm::rotate(glm::mat4(1.0f), radZ, glm::vec3(0.0f, 0.0f, 1.0f));
13
14 glm::mat4 rotationMatrix = rotationZ * rotationY * rotationX;
15 return rotationMatrix;
16}
17
18static glm::vec2 rotatePoint(float x, float y, float centerX, float centerY, float radians) {
19 float dx = x - centerX;
20 float dy = y - centerY;
21 return glm::vec2(
22 centerX + dx * cos(radians) - dy * sin(radians),
23 centerY + dx * sin(radians) + dy * cos(radians)
24 );
25};
26static glm::vec2 rotatePoint(float x, float y, float radians) {
27 return rotatePoint(x, y, 0.0f, 0.0f, radians);
28};
29/* glm::vec3 arotatedTopLeft = rotatePoint(atopLeft.x, atopLeft.y, atopLeft.z, centerX, centerY, centerZ, 0, 0, 0);
30 glm::vec3 arotatedBottomLeft = rotatePoint(abottomLeft.x, abottomLeft.y, abottomLeft.z, centerX, centerY, centerZ, 0, 0, 0);
31 glm::vec3 arotatedBottomRight = rotatePoint(abottomRight.x, abottomRight.y, abottomRight.z, centerX, centerY, centerZ, 0, 0, 0);
32 glm::vec3 arotatedTopRight = rotatePoint(atopRight.x, atopRight.y, atopRight.z, centerX, centerY, centerZ, 0, 0, 0);*/
33
34namespace TazGraphEngine {
35
36 using Position = glm::vec3;
37 using Size = glm::vec3;
38 using Rotation = glm::vec3;
39
40 using Normal = glm::vec3;
41
42 using UV = glm::vec2;
43
44 struct Color {
45 Color() : r(0), g(0), b(0), a(0) {}
46 Color(GLubyte R, GLubyte G, GLubyte B, GLubyte A) : r(R), g(G), b(B), a(A) {}
47
48 glm::vec4 toVec4() const {
49 return glm::vec4(r, g, b, a) / 255.0f; // Normalize 0-255 to 0-1
50 }
51
52 static Color fromVec4(const glm::vec4& v) {
53 return Color(
54 static_cast<GLubyte>(v.r * 255.0f),
55 static_cast<GLubyte>(v.g * 255.0f),
56 static_cast<GLubyte>(v.b * 255.0f),
57 static_cast<GLubyte>(v.a * 255.0f)
58 );
59 }
60
61 GLubyte r;
62 GLubyte g;
63 GLubyte b;
64 GLubyte a;
65
66 Color operator*(float scalar) const {
67 return Color(static_cast<GLubyte>(r * scalar),
68 static_cast<GLubyte>(g * scalar),
69 static_cast<GLubyte>(b * scalar),
70 static_cast<GLubyte>(a * scalar));
71 }
72
73 // Operator overload for color addition
74 Color operator+(const Color& other) const {
75 return Color(static_cast<GLubyte>(r + other.r),
76 static_cast<GLubyte>(g + other.g),
77 static_cast<GLubyte>(b + other.b),
78 static_cast<GLubyte>(a + other.a));
79 }
80
81 bool operator==(const Color& other) const {
82 return r == other.r && g == other.g && b == other.b && a == other.a;
83 }
84 };
85
86
87 struct Vertex {
88 Position position = Position(0);
89
90 inline void setPosition(Position m_position) {
91 position = m_position;
92 }
93 };
94
95 struct ColorVertex : Vertex { //instead of using the general Vertex that has also info about texture
96 // we use this where we want just color
97 //todo different instanceVBO for the centers
98 //Position centerMesh;
99 Color color = Color();
100
101 void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
102 color.r = r;
103 color.g = g;
104 color.b = b;
105 color.a = a;
106 }
107 };
108
110 Normal normal = Normal();
111
112 };
113
115 // UV texture coordinates
116 UV uv = UV(0);
117
118 inline void setUV(UV m_uv) {
119 uv = m_uv;
120 }
121 };
122
123}
124
125using TazPosition = TazGraphEngine::Position;
126using TazSize = TazGraphEngine::Size;
127using TazRotation = TazGraphEngine::Rotation;
128using TazUV = TazGraphEngine::UV;
129using TazNormal = TazGraphEngine::Normal;
Definition Vertex.h:95
Definition Vertex.h:44
Definition Vertex.h:109
Definition Vertex.h:114
Definition Vertex.h:87