comparison dmmodel.h @ 48:0ae1ff609626

Implement diffuse setting for models in scenefile. Also refactor parsing/handling of ambient/diffuse/specular values and unify it for both models and lights.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Dec 2019 01:12:23 +0200
parents 73a785323e8a
children 8b335eb444ae
comparison
equal deleted inserted replaced
47:9909014498f0 48:0ae1ff609626
128 128
129 129
130 union DMVector4 130 union DMVector4
131 { 131 {
132 struct { float x, y, z, w; } p; 132 struct { float x, y, z, w; } p;
133 struct { float r, g, b, a; } c;
133 float values[4]; 134 float values[4];
135 };
136
137
138 struct DMMaterial
139 {
140 DMVector4 ambient, diffuse, specular;
141 int shininess;
134 }; 142 };
135 143
136 144
137 struct DMModel 145 struct DMModel
138 { 146 {
139 int nvertices, nfaces; 147 int nvertices, nfaces;
140 std::vector<DMVector3> vertices, normals; 148 std::vector<DMVector3> vertices, normals;
141 std::vector<unsigned int> faces; 149 std::vector<unsigned int> faces;
142 150
143 DMVector4 ambient, diffuse, specular; 151 DMMaterial material;
144 int shininess;
145 DMVector3 translate, scale, rotate; 152 DMVector3 translate, scale, rotate;
146 bool translateSet, scaleSet, rotateSet; 153 bool translateSet, scaleSet, rotateSet;
147 154
148 unsigned int id_prog, id_fs, id_vs; 155 unsigned int id_prog, id_fs, id_vs;
149 156
153 fragShaderStr, vertShaderStr; 160 fragShaderStr, vertShaderStr;
154 161
155 bool loadFromPLY(const std::string &filename); 162 bool loadFromPLY(const std::string &filename);
156 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info); 163 bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info);
157 164
158 void printInfo()
159 {
160 printf(
161 "MODEL: scale <%1.5f, %1.5f, %1.5f>\n"
162 "MODEL: translate <%1.5f, %1.5f, %1.5f>\n"
163 "MODEL: rotate <%1.5f, %1.5f, %1.5f>\n"
164 ,
165 scale.x, scale.y, scale.z,
166 translate.x, translate.y, translate.z,
167 rotate.x, rotate.y, rotate.z);
168 }
169
170 DMModel() 165 DMModel()
171 { 166 {
172 nfaces = nvertices = 0; 167 nfaces = nvertices = 0;
173 168
174 translate.x = translate.y = translate.z = 0; 169 translate.x = translate.y = translate.z = 0;
175 rotate.x = rotate.y = rotate.z = 0; 170 rotate.x = rotate.y = rotate.z = 0;
176 scale.x = scale.y = scale.z = 0; 171 scale.x = scale.y = scale.z = 0;
177 translateSet = rotateSet = scaleSet = false; 172 translateSet = rotateSet = scaleSet = false;
178 173
179 diffuse.p.x = diffuse.p.z = 0.56471f; diffuse.p.y = 0.5f; diffuse.p.w = 1.0f; 174 material.diffuse.c.r = material.diffuse.p.z = 0.56471f;
180 specular.p.x = specular.p.y = specular.p.z = 0.8f; specular.p.w = 1.0f; 175 material.diffuse.c.g = 0.5f;
181 shininess = 96; 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 } 182 }
183 }; 183 };
184 184
185 185
186 struct DMLight 186 struct DMLight
187 { 187 {
188 DMVector4 188 DMMaterial color;
189 ambient, diffuse, specular, 189 DMVector4 position, pointAt;
190 position, pointAt;
191 190
192 DMLight() 191 DMLight()
193 { 192 {
194 ambient.p.x = ambient.p.y = ambient.p.z = 0.2f; ambient.p.w = 1.0f; 193 color.ambient.c.r = color.ambient.c.g = color.ambient.p.z = 0.2f; color.ambient.c.a = 1.0f;
195 diffuse.p.x = diffuse.p.y = diffuse.p.z = 0.8f; diffuse.p.w = 1.0f; 194 color.diffuse.c.r = color.diffuse.c.g = color.diffuse.p.z = 0.8f; color.diffuse.c.a = 1.0f;
196 specular.p.x = specular.p.y = specular.p.z = 0.5f; specular.p.w = 1.0f; 195 color.specular.c.r = color.specular.c.g = color.specular.p.z = 0.5f; color.specular.c.a = 1.0f;
197 196
198 position.p.x = 10.0f; 197 position.p.x = 10.0f;
199 position.p.y = 10.0f; 198 position.p.y = 10.0f;
200 position.p.z = 0.0f; 199 position.p.z = 0.0f;
201 } 200 }