Mercurial > hg > forks > gldragon
comparison dmmodel.cpp @ 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 | 9909014498f0 |
children |
comparison
equal
deleted
inserted
replaced
47:9909014498f0 | 48:0ae1ff609626 |
---|---|
622 { | 622 { |
623 DMTextFileInfo info; | 623 DMTextFileInfo info; |
624 DMModel *model = 0; | 624 DMModel *model = 0; |
625 DMLight *light = 0; | 625 DMLight *light = 0; |
626 DMVector4 *ppos = 0, *ppointAt = 0; | 626 DMVector4 *ppos = 0, *ppointAt = 0; |
627 DMMaterial *pmat = 0; | |
627 | 628 |
628 info.filename = filename; | 629 info.filename = filename; |
629 info.nline = info.state = 0; | 630 info.nline = info.state = 0; |
630 info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary); | 631 info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary); |
631 | 632 |
669 } | 670 } |
670 | 671 |
671 models.push_back(newmodel); | 672 models.push_back(newmodel); |
672 model = &models.back(); | 673 model = &models.back(); |
673 model->modelFile = tokens[1]; | 674 model->modelFile = tokens[1]; |
675 pmat = &model->material; | |
674 info.state = 1; | 676 info.state = 1; |
675 } | 677 } |
676 else | 678 else |
677 if (info.state == 1 && (key == "shaderfile")) | 679 if (info.state == 1 && (key == "shaderfile")) |
678 { | 680 { |
725 model->scale = vec; | 727 model->scale = vec; |
726 model->scaleSet = true; | 728 model->scaleSet = true; |
727 } | 729 } |
728 } | 730 } |
729 else | 731 else |
730 if (info.state == 1 && key == "specular") | |
731 { | |
732 DMVector4 val; | |
733 val.p.w = 1.0f; | |
734 | |
735 if (!dmParseVector(info, tokens, 1, val)) | |
736 return false; | |
737 | |
738 model->specular = val; | |
739 } | |
740 else | |
741 if (info.state == 1 && key == "shininess") | 732 if (info.state == 1 && key == "shininess") |
742 { | 733 { |
743 if (tokens.size() != 2) | 734 if (tokens.size() != 2) |
744 { | 735 { |
745 return dmSyntaxError(info, | 736 return dmSyntaxError(info, |
746 "Expected argument for shininess"); | 737 "Expected argument for shininess"); |
747 } | 738 } |
748 | 739 |
749 model->shininess = std::stoi(tokens[1], 0, 0); | 740 model->material.shininess = std::stoi(tokens[1], 0, 0); |
750 } | 741 } |
751 else | 742 else |
752 if (key == "light") | 743 if (key == "light") |
753 { | 744 { |
754 DMLight newlight; | 745 DMLight newlight; |
761 | 752 |
762 lights.push_back(newlight); | 753 lights.push_back(newlight); |
763 light = &lights.back(); | 754 light = &lights.back(); |
764 ppos = &light->position; | 755 ppos = &light->position; |
765 ppointAt = &light->pointAt; | 756 ppointAt = &light->pointAt; |
757 pmat = &light->color; | |
766 info.state = 2; | 758 info.state = 2; |
767 } | 759 } |
768 else | 760 else |
769 if (info.state == 2 && (key == "ambient" || key == "diffuse" || key == "specular")) | 761 if ((info.state == 1 || info.state == 2) && |
762 (key == "ambient" || key == "diffuse" || key == "specular")) | |
770 { | 763 { |
771 DMVector4 val; | 764 DMVector4 val; |
772 val.p.w = 1.0f; | 765 val.c.a = 1.0f; |
773 | 766 |
774 if (!dmParseVector(info, tokens, 1, val)) | 767 if (!dmParseVector(info, tokens, 1, val)) |
775 return false; | 768 return false; |
776 | 769 |
777 if (key == "ambient") | 770 if (key == "ambient") |
778 light->ambient = val; | 771 pmat->ambient = val; |
779 else | 772 else |
780 if (key == "diffuse") | 773 if (key == "diffuse") |
781 light->diffuse = val; | 774 pmat->diffuse = val; |
782 else | 775 else |
783 if (key == "specular") | 776 if (key == "specular") |
784 light->specular = val; | 777 pmat->specular = val; |
785 } | 778 } |
786 else | 779 else |
787 if (key == "camera") | 780 if (key == "camera") |
788 { | 781 { |
789 info.state = 3; | 782 info.state = 3; |