diff dmmodel.cpp @ 25:2403030a0352

"Finish" implementing multiple lights support in scene files. If scene defines no lights, a default light will be used. Light objects will have default values and can redefine only color, position etc.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Nov 2019 06:47:13 +0200
parents 03b86b9c2f29
children 1215fdd0a8ab
line wrap: on
line diff
--- a/dmmodel.cpp	Fri Nov 22 05:49:14 2019 +0200
+++ b/dmmodel.cpp	Fri Nov 22 06:47:13 2019 +0200
@@ -594,21 +594,19 @@
 
 bool dmParseVector(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMVector4 &vec)
 {
-    vec.w = 1.0f;
-
     if (tokens.size() == offs + 1)
     {
-        vec.x = vec.y = vec.z = std::stof(tokens[offs]);
+        vec.p.x = vec.p.y = vec.p.z = std::stof(tokens[offs]);
     }
     else
     if (tokens.size() == offs + 3 || tokens.size() == offs + 4)
     {
-        vec.x = std::stof(tokens[offs]);
-        vec.y = std::stof(tokens[offs + 1]);
-        vec.z = std::stof(tokens[offs + 2]);
+        vec.p.x = std::stof(tokens[offs]);
+        vec.p.y = std::stof(tokens[offs + 1]);
+        vec.p.z = std::stof(tokens[offs + 2]);
 
         if (tokens.size() == offs + 4)
-            vec.w = std::stof(tokens[offs + 3]);
+            vec.p.w = std::stof(tokens[offs + 3]);
     }
     else
     {
@@ -653,7 +651,7 @@
     DMTextFileInfo info;
     DMModel *model = 0;
     DMLight *light = 0;
-    DMVector3 *ppos = 0, *ppointAt = 0;
+    DMVector4 *ppos = 0, *ppointAt = 0;
 
     info.filename = filename;
     info.nline = info.state = 0;
@@ -741,7 +739,7 @@
             }
             lights.push_back(newlight);
             light = &lights.back();
-            ppos = &light->pos;
+            ppos = &light->position;
             ppointAt = &light->pointAt;
             info.state = 2;
         }
@@ -749,6 +747,7 @@
         if (info.state == 2 && (key == "ambient" || key == "diffuse" || key == "specular"))
         {
             DMVector4 val;
+            val.p.w = 1.0f;
 
             if (!dmParseVector(info, tokens, 1, val))
                 return false;
@@ -767,18 +766,20 @@
         {
             info.state = 3;
 
-            ppos = &camera.pos;
+            ppos = &camera.position;
             ppointAt = &camera.pointAt;
         }
         else
-        if ((info.state == 3 || info.state == 2) && (key == "pos" || key == "point_at"))
+        if ((info.state == 3 || info.state == 2) &&
+            (key == "position" || key == "pos" || key == "point_at"))
         {
-            DMVector3 vec;
+            DMVector4 vec;
+            vec.p.w = 0;
 
             if (!dmParseVector(info, tokens, 1, vec))
                 return false;
 
-            if (key == "pos")
+            if (key == "position" || key == "pos")
                 *ppos = vec;
             else
             if (key == "point_at")