comparison dmmodel.h @ 21:1404dfcee7b8

More work on scenefile and model loading support. Can now load PLY models and simple scene definition files. Converted dragon mesh to binary PLY format.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Nov 2019 03:03:52 +0200
parents a329f0216491
children 03b86b9c2f29
comparison
equal deleted inserted replaced
20:294c4c7943b5 21:1404dfcee7b8
86 { 86 {
87 int nline, state; 87 int nline, state;
88 std::string filename; 88 std::string filename;
89 std::string line; 89 std::string line;
90 std::ifstream file; 90 std::ifstream file;
91 std::string *key;
91 }; 92 };
92 93
93 94
94 struct DMPLYFileInfo : DMTextFileInfo 95 struct DMPLYFileInfo : DMTextFileInfo
95 { 96 {
119 { 120 {
120 int r, g, b, alpha; 121 int r, g, b, alpha;
121 }; 122 };
122 123
123 124
124 struct DMVertex 125 struct DMVector3
125 { 126 {
126 float x, y, z; 127 float x, y, z;
127 }; 128 };
128 129
129 130
131 struct DMVector4
132 {
133 float x, y, z, w;
134 };
135
136
130 struct DMModel 137 struct DMModel
131 { 138 {
132 int nvertices, nfaces; 139 int nvertices, nfaces;
133 std::vector<DMVertex> vertices, normals; 140 std::vector<DMVector3> vertices, normals;
134 std::vector<unsigned int> faces; 141 std::vector<unsigned int> faces;
135 142
136 DMColor color; 143 DMColor color;
137 DMVertex translate, scale, rotate; 144 DMVector3 translate, scale, rotate;
138 145
139 unsigned int id_prog, id_fs, id_vs; 146 unsigned int id_prog, id_fs, id_vs;
147
148 std::string
149 modelFile,
150 fragShaderFile, vertShaderFile,
151 fragShaderStr, vertShaderStr;
140 152
141 bool loadFromPLY(const std::string &filename); 153 bool loadFromPLY(const std::string &filename);
142 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info); 154 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info);
143 155
144 void printInfo() 156 void printInfo()
153 rotate.x, rotate.y, rotate.z); 165 rotate.x, rotate.y, rotate.z);
154 } 166 }
155 167
156 DMModel() 168 DMModel()
157 { 169 {
170 nfaces = nvertices = 0;
171
158 translate.x = translate.y = translate.z = 0; 172 translate.x = translate.y = translate.z = 0;
159 rotate.x = rotate.y = rotate.z = 0; 173 rotate.x = rotate.y = rotate.z = 0;
160 scale.x = scale.y = scale.z = 1; 174 scale.x = scale.y = scale.z = 1;
161 } 175 }
162 }; 176 };
163 177
164 178
165 struct DMLight 179 struct DMLight
166 { 180 {
167 DMVertex pos; 181 DMVector3 pos, pointAt;
168 float ambient[4], diffuse[4], specular[4]; 182 DMVector4 ambient, diffuse, specular;
169 }; 183 };
170 184
171 185
172 struct DMCamera 186 struct DMCamera
173 { 187 {
174 DMVertex pos, lookAt; 188 DMVector3 pos, pointAt;
175 }; 189 };
176 190
177 191
178 struct DMSimpleScene 192 struct DMSimpleScene
179 { 193 {
180 DMModel model;
181 DMCamera camera; 194 DMCamera camera;
182 std::vector<DMLight> lights; 195 std::vector<DMLight> lights;
196 std::vector<DMModel> models;
183 197
184 bool loadInfo(const std::string &filename); 198 bool loadInfo(const std::string &filename);
185 }; 199 };
186 200
187 #endif 201 #endif