-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelHandler.h
More file actions
158 lines (142 loc) · 4.56 KB
/
ModelHandler.h
File metadata and controls
158 lines (142 loc) · 4.56 KB
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
//
// Created by Brett on 3/3/2018.
//
#include "model.h"
#include "shapes.h"
#include "GameState.h"
#include "CustomShape.h"
#include <list>
#ifndef PROJECT_1_SHAPEHANDLER_H
#define PROJECT_1_SHAPEHANDLER_H
// class for managing models
class ModelHandler{
public:
std::list<Model*> models; // list of all models
/* model creation methods */
void createTriangle(){
float* triangleVerts = Shapes::triangle(0,1,0);
Model* triangleModel = new Model(triangleVerts, 18);
(*triangleModel).setGameStateToModel();
models.push_back(triangleModel);
}
void createSquare(){
float* squareVerts = Shapes::square(0,0,1);
Model* squareModel = new Model(squareVerts, 36);
(*squareModel).setGameStateToModel();
models.push_back(squareModel);
}
void createCircle(){
float* circleVerts = Shapes::circle(10,1,0,0);
Model* circleModel = new Model(circleVerts, 180);
(*circleModel).setGameStateToModel();
models.push_back(circleModel);
}
void createCustom(){
int length;
int* lenPtr = &length;
CustomShape::currentCustom->earClipping();
float* customShape = CustomShape::currentCustom->buildShape(lenPtr);
Model* customModel = new Model(customShape, length);
models.push_back(customModel);
CustomShape::resetShape();
}
// re-create model with new color
void changeColor(Model* model){
int r = 0;
int g = 0;
int b = 0;
switch(GameState::setColor){
case red:
r = 1;
break;
case green:
g = 1;
break;
case blue:
b = 1;
break;
}
float* verts;
switch(model->vertsSize){
case 18:
verts = Shapes::triangle(r,g,b);
break;
case 36:
verts = Shapes::square(r,g,b);
break;
case 180:
verts = Shapes::circle(10,r,g,b);
break;
}
model->verts = verts;
}
// calls creation methods
void handleObjectCreation(){
if(GameState::createTriangle){
createTriangle();
GameState::createTriangle = false;
}
if(GameState::createSquare){
createSquare();
GameState::createSquare = false;
}
if(GameState::createCircle){
createCircle();
GameState::createCircle = false;
}
if(GameState::createCustom){
createCustom();
GameState::createCustom = false;
}
}
// display all models
void displayModels(Shader shader, Matrix vMatrix, Matrix pMatrix, Matrix oMatrix){
for(Model* model : models){
model->bind(shader,vMatrix, pMatrix,oMatrix);
model->display();
}
}
// set model transformation matrix of most recently created model (for stamp mode)
void setLastTransform(){
(*models.back()).setModel(GameState::rx, GameState::ry, GameState::rz,
GameState::sx,GameState::sy, GameState::sz,
GameState::tx, GameState::ty, GameState::tz);
}
// transform selected models
void setSelectedTransform(){
for(Model* model: models){
if(model->selected){
if(GameState::setColor != dont){
changeColor(model);
GameState::setColor = dont;
}
model->setModel(GameState::rx, GameState::ry, GameState::rz,
GameState::sx,GameState::sy, GameState::sz,
GameState::tx, GameState::ty, GameState::tz);
}
}
}
// transform selected group
void setSelectedGroupTransform(){
for(Model* model: models){
if(model->selected){
if(GameState::setColor != dont){
changeColor(model);
}
model->setGroupModel(GameState::rx, GameState::ry, GameState::rz,
GameState::sx,GameState::sy, GameState::sz,
GameState::tx, GameState::ty, GameState::tz);
}
}
GameState::setColor = dont;
}
// deselect models
void deselectAllModels() {
for (Model *model: models) {
if (model->selected) {
model->selected = false;
}
}
}
};
#endif //PROJECT_1_SHAPEHANDLER_H