Mercurial > hg > forks > gldragon
diff 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 |
line wrap: on
line diff
--- a/dmmodel.h Thu Dec 05 23:52:45 2019 +0200 +++ b/dmmodel.h Fri Dec 06 01:12:23 2019 +0200 @@ -130,18 +130,25 @@ union DMVector4 { struct { float x, y, z, w; } p; + struct { float r, g, b, a; } c; float values[4]; }; +struct DMMaterial +{ + DMVector4 ambient, diffuse, specular; + int shininess; +}; + + struct DMModel { int nvertices, nfaces; std::vector<DMVector3> vertices, normals; std::vector<unsigned int> faces; - DMVector4 ambient, diffuse, specular; - int shininess; + DMMaterial material; DMVector3 translate, scale, rotate; bool translateSet, scaleSet, rotateSet; @@ -155,18 +162,6 @@ bool loadFromPLY(const std::string &filename); bool loadFromPLY(const std::string &filename, DMPLYFileInfo &info); - void printInfo() - { - printf( - "MODEL: scale <%1.5f, %1.5f, %1.5f>\n" - "MODEL: translate <%1.5f, %1.5f, %1.5f>\n" - "MODEL: rotate <%1.5f, %1.5f, %1.5f>\n" - , - scale.x, scale.y, scale.z, - translate.x, translate.y, translate.z, - rotate.x, rotate.y, rotate.z); - } - DMModel() { nfaces = nvertices = 0; @@ -176,24 +171,28 @@ scale.x = scale.y = scale.z = 0; translateSet = rotateSet = scaleSet = false; - diffuse.p.x = diffuse.p.z = 0.56471f; diffuse.p.y = 0.5f; diffuse.p.w = 1.0f; - specular.p.x = specular.p.y = specular.p.z = 0.8f; specular.p.w = 1.0f; - shininess = 96; + material.diffuse.c.r = material.diffuse.p.z = 0.56471f; + material.diffuse.c.g = 0.5f; + material.diffuse.c.a = 1.0f; + + material.specular.c.r = material.specular.c.g = material.specular.c.b = 0.8f; + material.specular.c.a = 1.0f; + + material.shininess = 96; } }; struct DMLight { - DMVector4 - ambient, diffuse, specular, - position, pointAt; + DMMaterial color; + DMVector4 position, pointAt; DMLight() { - ambient.p.x = ambient.p.y = ambient.p.z = 0.2f; ambient.p.w = 1.0f; - diffuse.p.x = diffuse.p.y = diffuse.p.z = 0.8f; diffuse.p.w = 1.0f; - specular.p.x = specular.p.y = specular.p.z = 0.5f; specular.p.w = 1.0f; + color.ambient.c.r = color.ambient.c.g = color.ambient.p.z = 0.2f; color.ambient.c.a = 1.0f; + color.diffuse.c.r = color.diffuse.c.g = color.diffuse.p.z = 0.8f; color.diffuse.c.a = 1.0f; + color.specular.c.r = color.specular.c.g = color.specular.p.z = 0.5f; color.specular.c.a = 1.0f; position.p.x = 10.0f; position.p.y = 10.0f;