X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGraphic%2FDecal.cpp;h=7491d73c0484d08483ab29cb6ce8b9d29aa9e47a;hb=8b6e8f3ad7390309795eb35c0959264cb7924402;hp=de3388f75ff191ba08a1169e6896dac837a43648;hpb=4690d99d2bec493f809c7065b222eaf18f46df60;p=lugaru.git diff --git a/Source/Graphic/Decal.cpp b/Source/Graphic/Decal.cpp index de3388f..7491d73 100644 --- a/Source/Graphic/Decal.cpp +++ b/Source/Graphic/Decal.cpp @@ -21,24 +21,25 @@ along with Lugaru. If not, see . #include "Graphic/Decal.hpp" #include "Environment/Terrain.hpp" - -Decal::Decal() : - position(), - type(shadowdecal), - opacity(0), - rotation(0), - alivetime(0), - brightness(0) +#include "Graphic/Models.hpp" + +Decal::Decal() + : position() + , type(shadowdecal) + , opacity(0) + , rotation(0) + , alivetime(0) + , brightness(0) { } -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), - rotation(_rotation), - alivetime(0), - brightness(_brightness) +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) + , rotation(_rotation) + , alivetime(0) + , brightness(_brightness) { float placex, placez; placex = (float)whichx * terrain.scale + terrain.scale; @@ -70,7 +71,6 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f vertex[1].y = terrain.heightmap[whichx][whichy] * terrain.scale + .01; } - placex = (float)whichx * terrain.scale; placez = (float)whichy * terrain.scale + terrain.scale; @@ -93,3 +93,105 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f } } } + +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.getTriangleVertex(i, 0).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 0).y; + + placex = model.getTriangleVertex(i, 1).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 1).y; + + placex = model.getTriangleVertex(i, 2).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 2).y; + } else if (which == 1) { + placex = model.getTriangleVertex(i, 0).y; + placez = model.getTriangleVertex(i, 0).z; + + texcoords[0][0] = (placex - position.y) / (size) / 2 + .5; + texcoords[0][1] = (placez - position.z) / (size) / 2 + .5; + + vertex[0].x = model.getTriangleVertex(i, 0).x; + vertex[0].z = placez; + vertex[0].y = placex; + + placex = model.getTriangleVertex(i, 1).y; + placez = model.getTriangleVertex(i, 1).z; + + texcoords[1][0] = (placex - position.y) / (size) / 2 + .5; + texcoords[1][1] = (placez - position.z) / (size) / 2 + .5; + + vertex[1].x = model.getTriangleVertex(i, 1).x; + vertex[1].z = placez; + vertex[1].y = placex; + + placex = model.getTriangleVertex(i, 2).y; + placez = model.getTriangleVertex(i, 2).z; + + texcoords[2][0] = (placex - position.y) / (size) / 2 + .5; + texcoords[2][1] = (placez - position.z) / (size) / 2 + .5; + + vertex[2].x = model.getTriangleVertex(i, 2).x; + vertex[2].z = placez; + vertex[2].y = placex; + } else { + placex = model.getTriangleVertex(i, 0).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 0).z; + vertex[0].y = placez; + + placex = model.getTriangleVertex(i, 1).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 1).z; + vertex[1].y = placez; + + placex = model.getTriangleVertex(i, 2).x; + placez = model.getTriangleVertex(i, 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.getTriangleVertex(i, 2).z; + vertex[2].y = placez; + } +}