-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderModel.h
More file actions
128 lines (113 loc) · 3.1 KB
/
RenderModel.h
File metadata and controls
128 lines (113 loc) · 3.1 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
//
// Created by Ben Dickson on 5/4/17.
//
#ifndef LIBRARY_RENDERMODEL_H
#define LIBRARY_RENDERMODEL_H
#include <list>
#include <map>
#include <sstream>
#include "Point.h"
#include "Color.h"
#include "Texture.h"
using namespace std;
class PhysicalModel;
class RenderModel
{
public:
enum Shape{BOX,CIRCLE};
private:
unsigned int width;
unsigned int height;
Shape model;
Color* color = nullptr;
Texture* texture = nullptr;
bool textured;
double origin_x,origin_y,box_bottom,box_top,box_left,box_right,circle_radius;
int angle=0.0;
PhysicalModel* parentElement;
enum ConType{INT,DOUBLE,STRING,ENUM,COLOR};
static map<string,ConType> conImport;
// import values
bool importDouble(string var , double value);
bool importInt(string var, int value);
bool importString(string var, string value);
bool importColor(string var, unsigned char r, unsigned char g, unsigned char b);
public:
inline Point getGlobalPos() const;
inline Point* getRectPoints() const;
inline bool parseConstructorPair(pair<string,string> p)
{
map<string,ConType>::iterator it = conImport.find(p.first);
if(it!=conImport.end())
{
switch((*it).second)
{
case DOUBLE:
return importDouble(p.first,stod(p.second));
case INT:
return importInt(p.first,stoi(p.second));
case STRING:
return importString(p.first,p.second);
case COLOR:
stringstream pS(p.second);
string c;
getline(pS,c,',');
int r=stoi(c);
getline(pS,c,',');
int g=stoi(c);
getline(pS,c,',');
int b=stoi(c);
if(r>255)
{
r=255;
}
if(r<0)
{
r=0;
}
if(g>255)
{
g=255;
}
if(g<0)
{
g=0;
}
if(b>255)
{
b=255;
}
if(b<0)
{
b=0;
}
return importColor(p.first,(unsigned char)r,(unsigned char)g,(unsigned char)b);
}
}
return false;
}
RenderModel(Shape s, PhysicalModel* p)
{
model = s;
parentElement = p;
color = new Color(255);
}
};
class RenderPipeline
{
private:
list<RenderModel*> pipeline;
int size=0;
public:
inline void addModel(RenderModel* model);
inline RenderModel* retrieveModel();
};
inline RenderModel& operator>>(RenderModel& cm , RenderPipeline& cp)
{
cp.addModel(&cm);
}
inline RenderModel& operator<<(RenderModel& cm , RenderPipeline& cp)
{
return *cp.retrieveModel();
}
#endif //LIBRARY_RENDERMODEL_H