TazGraph Project v0.1.0
Loading...
Searching...
No Matches
Vertex.h
1#pragma once
2
3#define GLM_ENABLE_EXPERIMENTAL
4#include "GL/glew.h"
5#include "glm/glm.hpp"
6#include "glm/gtc/matrix_transform.hpp"
7#include "glm/gtc/type_ptr.hpp"
8
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);
13
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));
17
18 glm::mat4 rotationMatrix = rotationZ * rotationY * rotationX;
19 return rotationMatrix;
20}
21
22static glm::vec2 rotatePoint(float x, float y, float centerX, float centerY, float radians) {
23 float dx = x - centerX;
24 float dy = y - centerY;
25 return glm::vec2(
26 centerX + dx * cos(radians) - dy * sin(radians),
27 centerY + dx * sin(radians) + dy * cos(radians)
28 );
29};
30static glm::vec2 rotatePoint(float x, float y, float radians) {
31 return rotatePoint(x,y, 0.0f, 0.0f, radians);
32};
33/* glm::vec3 arotatedTopLeft = rotatePoint(atopLeft.x, atopLeft.y, atopLeft.z, centerX, centerY, centerZ, 0, 0, 0);
34 glm::vec3 arotatedBottomLeft = rotatePoint(abottomLeft.x, abottomLeft.y, abottomLeft.z, centerX, centerY, centerZ, 0, 0, 0);
35 glm::vec3 arotatedBottomRight = rotatePoint(abottomRight.x, abottomRight.y, abottomRight.z, centerX, centerY, centerZ, 0, 0, 0);
36 glm::vec3 arotatedTopRight = rotatePoint(atopRight.x, atopRight.y, atopRight.z, centerX, centerY, centerZ, 0, 0, 0);*/
37
38
39using Position = glm::vec3;
40using Size = glm::vec3;
41using Rotation = glm::vec3;
42
43using Normal = glm::vec3;
44
45using UV = glm::vec2;
46
47struct Color {
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) {}
50
51 glm::vec4 toVec4() const {
52 return glm::vec4(r, g, b, a) / 255.0f; // Normalize 0-255 to 0-1
53 }
54
55 static Color fromVec4(const glm::vec4& v) {
56 return Color(
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)
61 );
62 }
63
64 GLubyte r;
65 GLubyte g;
66 GLubyte b;
67 GLubyte a;
68
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));
74 }
75
76 // Operator overload for color addition
77 Color operator+(const Color& other) const {
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));
82 }
83
84 bool operator==(const Color& other) const {
85 return r == other.r && g == other.g && b == other.b && a == other.a;
86 }
87};
88
89
90struct Vertex {
91 Position position = Position(0);
92
93 inline void setPosition(Position m_position) {
94 position = m_position;
95 }
96};
97
98struct ColorVertex : Vertex { //instead of using the general Vertex that has also info about texture
99 // we use this where we want just color
100 //todo different instanceVBO for the centers
101 //Position centerMesh;
102 Color color = Color();
103
104 void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
105 color.r = r;
106 color.g = g;
107 color.b = b;
108 color.a = a;
109 }
110};
111
113 Normal normal = Normal();
114
115};
116
118 // UV texture coordinates
119 UV uv = UV(0);
120
121 inline void setUV(UV m_uv) {
122 uv = m_uv;
123 }
124};
Definition Vertex.h:98
Definition Vertex.h:47
Definition Vertex.h:112
Definition Vertex.h:117
Definition Vertex.h:90