summaryrefslogtreecommitdiff
path: root/inc/graphicsobjects.hpp
blob: 66e3fc37d02f3e4d0d886cf28922f6bb8f0f6f4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#ifndef graphicsobjects_h
#define graphicsobjects_h

#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>


struct Camera
{
public:
	Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar)
	{
		this->pos = pos;
		this->forward = glm::vec3(0.0f, 0.0f, -1.0f);
		this->up = glm::vec3(0.0f, 1.0f, 0.0f);
		this->projection = glm::perspective(fov, aspect, zNear, zFar);
	}

	inline glm::mat4 GetViewProjection() const
	{
		return projection * glm::lookAt(pos, pos + forward, up);
	}

	void MoveForward()
	{
		pos += forward * amt;
	}

	void MoveBackward()
	{
		pos += forward * -amt;
	}

	void MoveRight()
	{
		pos += -glm::cross(up, forward) * amt;
	}

	void MoveLeft()
	{
		pos += glm::cross(up, forward) * amt;
	}

	void MoveUp()
	{
		//pos += glm::cross(up, forward) * amt;
		pos += glm::vec3(0,.2,0);
	}

	void MoveDown()
	{
		//pos += glm::cross(up, forward) * amt;
		pos -= glm::vec3(0,.2,0);
	}

	void Pitch(float angle)
	{
		glm::vec3 right = glm::normalize(glm::cross(up, forward));

		forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
		up = glm::normalize(glm::cross(forward, right));
	}

	/*void RotateY(float angle)
	{
		static const glm::vec3 UP(0.0f, 1.0f, 0.0f);

		glm::mat4 rotation = glm::rotate(angle, UP);

		forward = glm::vec3(glm::normalize(rotation * glm::vec4(forward, 0.0)));
		up = glm::vec3(glm::normalize(rotation * glm::vec4(up, 0.0)));
	}*/

private:
	float amt = .2;
	//glm::vec3 speed = glm::vec3(0,0,0.2);
	glm::mat4 projection;
	glm::vec3 pos;
	glm::vec3 forward;
	glm::vec3 up;
};



struct Transform
{
public:
	Transform(const glm::vec3& pos = glm::vec3(), const glm::vec3& rot = glm::vec3(), const glm::vec3& scale = glm::vec3(1.0f, 1.0f, 1.0f))
	{
		this->pos = pos;
		this->rot = rot;
		this->scale = scale;
	}

	inline glm::mat4 GetModel() const
	{
		glm::mat4 posMat = glm::translate(pos);
		glm::mat4 scaleMat = glm::scale(scale);
		glm::mat4 rotX = glm::rotate(rot.x, glm::vec3(1.0, 0.0, 0.0));
		glm::mat4 rotY = glm::rotate(rot.y, glm::vec3(0.0, 1.0, 0.0));
		glm::mat4 rotZ = glm::rotate(rot.z, glm::vec3(0.0, 0.0, 1.0));
		glm::mat4 rotMat = rotX * rotY * rotZ;

		return posMat * rotMat * scaleMat;
	}

	inline glm::mat4 GetMVP(const Camera& camera) const
	{
		glm::mat4 VP = camera.GetViewProjection();
		glm::mat4 M = GetModel();

		return VP * M;//camera.GetViewProjection() * GetModel();
	}

	inline glm::vec3* GetPos() { return &pos; }
	inline glm::vec3* GetRot() { return &rot; }
	inline glm::vec3* GetScale() { return &scale; }

	inline void SetPos(glm::vec3& pos) { this->pos = pos; }
	inline void SetRot(glm::vec3& rot) { this->rot = rot; }
	inline void SetScale(glm::vec3& scale) { this->scale = scale; }
protected:
private:
	glm::vec3 pos;
	glm::vec3 rot;
	glm::vec3 scale;
};






class Location
{
  public:
  	Location(float x1, float y1){x=x1;y=y1; w=5; h=5;};
    Location(){x=y=0; w=5; h=5;};
	
	float getX(){
		return x;
	}
	
	float getY(){
		return y;
	}
	
    float x;
    float y;
	float w;
    float h;
};


class GraphicsData
{
  public:

    float x;
    float y;
    float r;
    float g;
    float b;
    float sides;
    //float theret[6];
    //float* ret[6];

    GraphicsData(){
		this->x = 0;
		this->y = 0;
		this->r = 0;
		this->g = 0;
		this->b = 0;
		this->sides = 0;
	}


    GraphicsData(float x,float y,float r,float g,float b,float sides){
		this->x = 0;
		this->y = 0;
		this->r = 0;
		this->g = 0;
		this->b = 0;
		this->sides = 0;
	}

	float getX(){
		return x;
	}
	
	float getY(){
		return y;
	}

};


class Rectangle
{
  public:
  	Rectangle(float x1, float y1, float wid, float heit){x=x1;y=y1;width=wid; height=heit;};
    Rectangle(){x=y=width=height=0;};


	void setX(float x1){
		x=x1;
	}
	
	void setY(float y1){
		y=y1;
	}


	
	float getX(){
		return x;
	}
	
	float getY(){
		return y;
	}
	
	float getWidth(){
		return width;
	}
	
	float getHeight(){
		return height;
	}
	
    float x;
    float y;
	float width;
	float height;
};

#endif