Mercurial > hg > forks > gldragon
diff dmmodel.cpp @ 32:1215fdd0a8ab
Add support for specifying specular and shininess values per model.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Nov 2019 22:57:14 +0200 |
parents | 2403030a0352 |
children | 2e85c180afdf |
line wrap: on
line diff
--- a/dmmodel.cpp Fri Nov 22 19:53:55 2019 +0200 +++ b/dmmodel.cpp Fri Nov 22 22:57:14 2019 +0200 @@ -618,34 +618,6 @@ } -bool dmParseColor(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMColor &color) -{ - color.alpha = 0xff; - - if (tokens.size() == offs + 1) - { - color.r = color.g = color.b = std::stoi(tokens[offs], 0, 0); - } - else - if (tokens.size() == offs + 3 || tokens.size() == offs + 4) - { - color.r = std::stoi(tokens[offs], 0, 0); - color.g = std::stoi(tokens[offs + 1], 0, 0); - color.b = std::stoi(tokens[offs + 2], 0, 0); - - if (tokens.size() == offs + 4) - color.alpha = std::stoi(tokens[offs + 3], 0, 0); - } - else - { - return dmSyntaxError(info, - "Expected color values <value> or <red> <green> <blue> [<alpha>] for '"+ *info.key +"'"); - } - - return true; -} - - bool DMSimpleScene::loadInfo(const std::string &filename) { DMTextFileInfo info; @@ -702,12 +674,6 @@ info.state = 1; } else - if (info.state == 1 && key == "color") - { - if (!dmParseColor(info, tokens, 1, model->color)) - return false; - } - else if (info.state == 1 && (key == "translate" || key == "rotate" || key == "scale")) { DMVector3 vec; @@ -728,15 +694,38 @@ model->scale = vec; } else + if (info.state == 1 && key == "specular") + { + DMVector4 val; + val.p.w = 1.0f; + + if (!dmParseVector(info, tokens, 1, val)) + return false; + + model->specular = val; + } + else + if (info.state == 1 && key == "shininess") + { + if (tokens.size() != 2) + { + return dmError(info, + "Expected argument for shininess"); + } + + model->shininess = std::stoi(tokens[1], 0, 0); + } + else if (key == "light") { DMLight newlight; if (lights.size() >= 4) { - printf("ERROR: Too many lights defined.\n"); - return false; + return dmError(info, + "Too many lights defined (max 4)"); } + lights.push_back(newlight); light = &lights.back(); ppos = &light->position;