Mercurial > hg > forks > gldragon
comparison dmscene.h @ 61:7b138613e2fc
Rename dmmodel.* to dmscene.*
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 14 Dec 2019 14:08:51 +0200 |
parents | dmmodel.h@8b335eb444ae |
children | 701bef61dcf1 |
comparison
equal
deleted
inserted
replaced
60:f645e38e3157 | 61:7b138613e2fc |
---|---|
1 // | |
2 // GLDragon - OpenGL PLY model viewer / simple benchmark | |
3 // -- Scene and model handling + PLY file parsing | |
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> | |
5 // (C) Copyright 2019 Tecnic Software productions (TNSP) | |
6 // | |
7 // See file "COPYING" for license information. | |
8 // | |
9 #ifndef DMSCENE_H | |
10 #define DMSCENE_H 1 | |
11 | |
12 #include "dmutil.h" | |
13 #include <cstdint> | |
14 #include <fstream> | |
15 #include <unordered_map> | |
16 | |
17 | |
18 #define PLY_PROP_VERTEX_INDICES "vertex_indices" | |
19 #define PLY_ELEM_FACE "face" | |
20 #define PLY_ELEM_VERTEX "vertex" | |
21 | |
22 | |
23 enum DMPLYFormat | |
24 { | |
25 PLY_FMT_UNKNOWN, | |
26 PLY_FMT_ASCII, | |
27 PLY_FMT_BIN_LE, | |
28 PLY_FMT_BIN_BE | |
29 }; | |
30 | |
31 | |
32 enum DMPLYPropType | |
33 { | |
34 PLY_TYPE_NONE, | |
35 PLY_TYPE_LIST, | |
36 | |
37 PLY_TYPE_UINT8, | |
38 PLY_TYPE_INT8, | |
39 PLY_TYPE_INT16, | |
40 PLY_TYPE_UINT16, | |
41 PLY_TYPE_INT32, | |
42 PLY_TYPE_UINT32, | |
43 PLY_TYPE_FLOAT, | |
44 PLY_TYPE_DOUBLE | |
45 }; | |
46 | |
47 | |
48 /* Structures | |
49 */ | |
50 union DMPLYPropValue | |
51 { | |
52 double v_double; | |
53 float v_float; | |
54 unsigned int v_uint; | |
55 int v_int; | |
56 }; | |
57 | |
58 | |
59 struct DMPLYFileProperty | |
60 { | |
61 std::string name; | |
62 DMPLYPropType | |
63 type, | |
64 list_num_type, | |
65 list_values_type; | |
66 | |
67 DMPLYPropValue value, list_num_value; | |
68 std::vector<DMPLYPropValue> list_values; | |
69 }; | |
70 | |
71 | |
72 struct DMPLYFileElement | |
73 { | |
74 int value; | |
75 std::string name; | |
76 | |
77 std::unordered_map<std::string, DMPLYFileProperty> prop_map; | |
78 std::vector<DMPLYFileProperty *> properties; | |
79 | |
80 DMPLYFileProperty *checkProp(const std::string &prop) | |
81 { | |
82 if (prop_map.count(prop)) | |
83 return &prop_map[prop]; | |
84 else | |
85 return 0; | |
86 } | |
87 }; | |
88 | |
89 | |
90 struct DMTextFileInfo | |
91 { | |
92 int nline, state; | |
93 std::string filename; | |
94 std::string line; | |
95 std::ifstream file; | |
96 std::string *key; | |
97 }; | |
98 | |
99 | |
100 struct DMPLYFileInfo : DMTextFileInfo | |
101 { | |
102 DMPLYFormat format; | |
103 | |
104 std::unordered_map<std::string, DMPLYFileElement> elem_map; | |
105 std::vector<DMPLYFileElement *> elements; | |
106 DMPLYFileElement *element; | |
107 | |
108 DMPLYFileInfo() | |
109 { | |
110 element = 0; | |
111 format = PLY_FMT_UNKNOWN; | |
112 } | |
113 | |
114 DMPLYFileElement *checkElem(const std::string &elem) | |
115 { | |
116 if (elem_map.count(elem)) | |
117 return &elem_map[elem]; | |
118 else | |
119 return 0; | |
120 } | |
121 }; | |
122 | |
123 | |
124 struct DMVector3 | |
125 { | |
126 float x, y, z; | |
127 }; | |
128 | |
129 | |
130 union DMVector4 | |
131 { | |
132 struct { float x, y, z, w; } p; | |
133 struct { float r, g, b, a; } c; | |
134 float values[4]; | |
135 }; | |
136 | |
137 | |
138 struct DMMaterial | |
139 { | |
140 DMVector4 ambient, diffuse, specular; | |
141 int shininess; | |
142 }; | |
143 | |
144 | |
145 struct DMModel | |
146 { | |
147 int nvertices, nfaces; | |
148 std::vector<DMVector3> vertices, normals; | |
149 std::vector<unsigned int> faces; | |
150 | |
151 DMMaterial material; | |
152 DMVector3 translate, scale, rotate; | |
153 bool translateSet, scaleSet, rotateSet; | |
154 | |
155 unsigned int id_prog, id_fs, id_vs; | |
156 | |
157 std::string | |
158 modelFile, | |
159 fragShaderFile, vertShaderFile, | |
160 fragShaderStr, vertShaderStr; | |
161 | |
162 bool loadFromPLY(const std::string &filename); | |
163 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info); | |
164 | |
165 DMModel() | |
166 { | |
167 nfaces = nvertices = 0; | |
168 | |
169 translate.x = translate.y = translate.z = 0; | |
170 rotate.x = rotate.y = rotate.z = 0; | |
171 scale.x = scale.y = scale.z = 0; | |
172 translateSet = rotateSet = scaleSet = false; | |
173 | |
174 material.diffuse.c.r = material.diffuse.p.z = 0.56471f; | |
175 material.diffuse.c.g = 0.5f; | |
176 material.diffuse.c.a = 1.0f; | |
177 | |
178 material.specular.c.r = material.specular.c.g = material.specular.c.b = 0.8f; | |
179 material.specular.c.a = 1.0f; | |
180 | |
181 material.shininess = 96; | |
182 } | |
183 }; | |
184 | |
185 | |
186 struct DMLight | |
187 { | |
188 DMMaterial color; | |
189 DMVector4 position, pointAt; | |
190 | |
191 DMLight() | |
192 { | |
193 color.ambient.c.r = color.ambient.c.g = color.ambient.p.z = 0.2f; color.ambient.c.a = 1.0f; | |
194 color.diffuse.c.r = color.diffuse.c.g = color.diffuse.p.z = 0.8f; color.diffuse.c.a = 1.0f; | |
195 color.specular.c.r = color.specular.c.g = color.specular.p.z = 0.5f; color.specular.c.a = 1.0f; | |
196 | |
197 position.p.x = 10.0f; | |
198 position.p.y = 10.0f; | |
199 position.p.z = 0.0f; | |
200 position.p.w = 0.0f; | |
201 } | |
202 }; | |
203 | |
204 | |
205 struct DMCamera | |
206 { | |
207 DMVector4 position, pointAt; | |
208 }; | |
209 | |
210 | |
211 struct DMSimpleScene | |
212 { | |
213 DMCamera camera; | |
214 std::vector<DMLight> lights; | |
215 std::vector<DMModel> models; | |
216 | |
217 bool loadInfo(const std::string &filename); | |
218 }; | |
219 | |
220 #endif |