]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Graphic/Decal.cpp
Fixes #74 Shadow glitch (was using decal.vertex instead of model.vertex)
[lugaru.git] / Source / Graphic / Decal.cpp
index a535dee287111b5445cd31c69544da67a0a49e86..335a4bc9471d2a6e74de93f39d0da3af9fbebefe 100644 (file)
@@ -21,10 +21,11 @@ along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 #include "Graphic/Decal.hpp"
 
 #include "Environment/Terrain.hpp"
+#include "Graphic/Models.hpp"
 
 Decal::Decal() :
     position(),
-    type(0),
+    type(shadowdecal),
     opacity(0),
     rotation(0),
     alivetime(0),
@@ -32,7 +33,7 @@ Decal::Decal() :
 {
 }
 
-Decal::Decal(XYZ _position, int _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) :
+Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float _brightness, int whichx, int whichy, float size, const Terrain& terrain, bool first) :
     position(_position),
     type(_type),
     opacity(_opacity),
@@ -93,3 +94,111 @@ Decal::Decal(XYZ _position, int _type, float _opacity, float _rotation, float _b
         }
     }
 }
+
+Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, float size, const Model& model, int i, int which) :
+    position(_position),
+    type(_type),
+    opacity(_opacity),
+    rotation(_rotation),
+    alivetime(0),
+    brightness(0)
+{
+    float placex, placez;
+    if (which == 0) {
+        placex = model.vertex[model.Triangles[i].vertex[0]].x;
+        placez = model.vertex[model.Triangles[i].vertex[0]].z;
+
+        texcoords[0][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[0][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[0].x = placex;
+        vertex[0].z = placez;
+        vertex[0].y = model.vertex[model.Triangles[i].vertex[0]].y;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[1]].x;
+        placez = model.vertex[model.Triangles[i].vertex[1]].z;
+
+        texcoords[1][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[1][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[1].x = placex;
+        vertex[1].z = placez;
+        vertex[1].y = model.vertex[model.Triangles[i].vertex[1]].y;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[2]].x;
+        placez = model.vertex[model.Triangles[i].vertex[2]].z;
+
+        texcoords[2][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[2][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[2].x = placex;
+        vertex[2].z = placez;
+        vertex[2].y = model.vertex[model.Triangles[i].vertex[2]].y;
+    } else if (which == 1) {
+        placex = model.vertex[model.Triangles[i].vertex[0]].y;
+        placez = model.vertex[model.Triangles[i].vertex[0]].z;
+
+        texcoords[0][0] = (placex - position.y) / (size) / 2 + .5;
+        texcoords[0][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[0].x = model.vertex[model.Triangles[i].vertex[0]].x;
+        vertex[0].z = placez;
+        vertex[0].y = placex;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[1]].y;
+        placez = model.vertex[model.Triangles[i].vertex[1]].z;
+
+        texcoords[1][0] = (placex - position.y) / (size) / 2 + .5;
+        texcoords[1][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[1].x = model.vertex[model.Triangles[i].vertex[1]].x;
+        vertex[1].z = placez;
+        vertex[1].y = placex;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[2]].y;
+        placez = model.vertex[model.Triangles[i].vertex[2]].z;
+
+        texcoords[2][0] = (placex - position.y) / (size) / 2 + .5;
+        texcoords[2][1] = (placez - position.z) / (size) / 2 + .5;
+
+        vertex[2].x = model.vertex[model.Triangles[i].vertex[2]].x;
+        vertex[2].z = placez;
+        vertex[2].y = placex;
+    } else {
+        placex = model.vertex[model.Triangles[i].vertex[0]].x;
+        placez = model.vertex[model.Triangles[i].vertex[0]].y;
+
+        texcoords[0][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[0][1] = (placez - position.y) / (size) / 2 + .5;
+
+        vertex[0].x = placex;
+        vertex[0].z = model.vertex[model.Triangles[i].vertex[0]].z;
+        vertex[0].y = placez;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[1]].x;
+        placez = model.vertex[model.Triangles[i].vertex[1]].y;
+
+        texcoords[1][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[1][1] = (placez - position.y) / (size) / 2 + .5;
+
+        vertex[1].x = placex;
+        vertex[1].z = model.vertex[model.Triangles[i].vertex[1]].z;
+        vertex[1].y = placez;
+
+
+        placex = model.vertex[model.Triangles[i].vertex[2]].x;
+        placez = model.vertex[model.Triangles[i].vertex[2]].y;
+
+        texcoords[2][0] = (placex - position.x) / (size) / 2 + .5;
+        texcoords[2][1] = (placez - position.y) / (size) / 2 + .5;
+
+        vertex[2].x = placex;
+        vertex[2].z = model.vertex[model.Triangles[i].vertex[2]].z;
+        vertex[2].y = placez;
+    }
+}