diff 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
line wrap: on
line diff
--- a/dmmodel.cpp	Thu Dec 05 23:52:45 2019 +0200
+++ b/dmmodel.cpp	Fri Dec 06 01:12:23 2019 +0200
@@ -624,6 +624,7 @@
     DMModel *model = 0;
     DMLight *light = 0;
     DMVector4 *ppos = 0, *ppointAt = 0;
+    DMMaterial *pmat = 0;
 
     info.filename = filename;
     info.nline = info.state = 0;
@@ -671,6 +672,7 @@
             models.push_back(newmodel);
             model = &models.back();
             model->modelFile = tokens[1];
+            pmat = &model->material;
             info.state = 1;
         }
         else
@@ -727,17 +729,6 @@
             }
         }
         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)
@@ -746,7 +737,7 @@
                     "Expected argument for shininess");
             }
 
-            model->shininess = std::stoi(tokens[1], 0, 0);
+            model->material.shininess = std::stoi(tokens[1], 0, 0);
         }
         else
         if (key == "light")
@@ -763,25 +754,27 @@
             light = &lights.back();
             ppos = &light->position;
             ppointAt = &light->pointAt;
+            pmat = &light->color;
             info.state = 2;
         }
         else
-        if (info.state == 2 && (key == "ambient" || key == "diffuse" || key == "specular"))
+        if ((info.state == 1 || info.state == 2) &&
+            (key == "ambient" || key == "diffuse" || key == "specular"))
         {
             DMVector4 val;
-            val.p.w = 1.0f;
+            val.c.a = 1.0f;
 
             if (!dmParseVector(info, tokens, 1, val))
                 return false;
 
             if (key == "ambient")
-                light->ambient = val;
+                pmat->ambient = val;
             else
             if (key == "diffuse")
-                light->diffuse = val;
+                pmat->diffuse = val;
             else
             if (key == "specular")
-                light->specular = val;
+                pmat->specular = val;
         }
         else
         if (key == "camera")