]> git.jsancho.org Git - lugaru.git/commitdiff
Added a helper for getting model triangle vertexes, mostly used in Decal for now.
authorCôme Chilliet <come@chilliet.eu>
Sun, 8 Jan 2017 14:44:11 +0000 (15:44 +0100)
committerCôme Chilliet <come@chilliet.eu>
Sun, 8 Jan 2017 14:44:11 +0000 (15:44 +0100)
Source/Graphic/Decal.cpp
Source/Graphic/Models.cpp
Source/Graphic/Models.hpp
Source/Objects/Person.cpp
Source/Objects/Weapons.cpp

index 335a4bc9471d2a6e74de93f39d0da3af9fbebefe..0857befe22c46ab4bec14b89d9844188ffd530ee 100644 (file)
@@ -105,100 +105,100 @@ Decal::Decal(XYZ _position, decal_type _type, float _opacity, float _rotation, f
 {
     float placex, placez;
     if (which == 0) {
-        placex = model.vertex[model.Triangles[i].vertex[0]].x;
-        placez = model.vertex[model.Triangles[i].vertex[0]].z;
+        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.vertex[model.Triangles[i].vertex[0]].y;
+        vertex[0].y = model.getTriangleVertex(i, 0).y;
 
 
-        placex = model.vertex[model.Triangles[i].vertex[1]].x;
-        placez = model.vertex[model.Triangles[i].vertex[1]].z;
+        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.vertex[model.Triangles[i].vertex[1]].y;
+        vertex[1].y = model.getTriangleVertex(i, 1).y;
 
 
-        placex = model.vertex[model.Triangles[i].vertex[2]].x;
-        placez = model.vertex[model.Triangles[i].vertex[2]].z;
+        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.vertex[model.Triangles[i].vertex[2]].y;
+        vertex[2].y = model.getTriangleVertex(i, 2).y;
     } else if (which == 1) {
-        placex = model.vertex[model.Triangles[i].vertex[0]].y;
-        placez = model.vertex[model.Triangles[i].vertex[0]].z;
+        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.vertex[model.Triangles[i].vertex[0]].x;
+        vertex[0].x = model.getTriangleVertex(i, 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;
+        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.vertex[model.Triangles[i].vertex[1]].x;
+        vertex[1].x = model.getTriangleVertex(i, 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;
+        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.vertex[model.Triangles[i].vertex[2]].x;
+        vertex[2].x = model.getTriangleVertex(i, 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;
+        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.vertex[model.Triangles[i].vertex[0]].z;
+        vertex[0].z = model.getTriangleVertex(i, 0).z;
         vertex[0].y = placez;
 
 
-        placex = model.vertex[model.Triangles[i].vertex[1]].x;
-        placez = model.vertex[model.Triangles[i].vertex[1]].y;
+        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.vertex[model.Triangles[i].vertex[1]].z;
+        vertex[1].z = model.getTriangleVertex(i, 1).z;
         vertex[1].y = placez;
 
 
-        placex = model.vertex[model.Triangles[i].vertex[2]].x;
-        placez = model.vertex[model.Triangles[i].vertex[2]].y;
+        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.vertex[model.Triangles[i].vertex[2]].z;
+        vertex[2].z = model.getTriangleVertex(i, 2).z;
         vertex[2].y = placez;
     }
 }
index 0edde87f81841ae735b3c12faa78ca3638bbb3f7..09036ae9d5009e9d85e4e442a4d0c755c288f2d6 100644 (file)
@@ -1141,6 +1141,11 @@ void Model::MakeDecal(decal_type atype, XYZ where, float size, float opacity, fl
     }
 }
 
+const XYZ& Model::getTriangleVertex(unsigned triangleId, unsigned vertexId) const
+{
+    return vertex[Triangles[triangleId].vertex[vertexId]];
+}
+
 void Model::deleteDeadDecals()
 {
     for (int i = decals.size() - 1; i >= 0; i--) {
index 54b28858ae3a7d2f2a3bcf31e347bfe7b56f11ba..cb5bcdafdf4c3b953991dedc8951c2e4b23f3193 100644 (file)
@@ -98,6 +98,7 @@ public:
     void DeleteDecal(int which);
     void MakeDecal(decal_type atype, XYZ *where, float *size, float *opacity, float *rotation);
     void MakeDecal(decal_type atype, XYZ where, float size, float opacity, float rotation);
+    const XYZ& getTriangleVertex(unsigned triangleId, unsigned vertexId) const;
     void drawdecals(Texture shadowtexture, Texture bloodtexture, Texture bloodtexture2, Texture breaktexture);
     int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate);
     int SphereCheckPossible(XYZ *p1, float radius, XYZ *move, float *rotate);
index 874194b4a53419537c177aaf15352f9bf65002dd..95cbf5263a164e175344e6a20601577d29336e14 100644 (file)
@@ -996,9 +996,9 @@ bool Person::DoBloodBigWhere(float howmuch, int which, XYZ where)
         if (whichtri != -1) {
             // low level geometry math
             p0 = colpoint;
-            p1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
-            p2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
-            p3 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
+            p1 = skeleton.drawmodel.getTriangleVertex(whichtri, 0);
+            p2 = skeleton.drawmodel.getTriangleVertex(whichtri, 1);
+            p3 = skeleton.drawmodel.getTriangleVertex(whichtri, 2);
 
             bary.x = distsq(&p0, &p1);
             bary.y = distsq(&p0, &p2);
@@ -6364,9 +6364,9 @@ int Person::DrawSkeleton()
 
             if (playerdetail) {
                 for (unsigned int i = 0; i < skeleton.drawmodel.Triangles.size(); i++) {
-                    XYZ &v0 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]];
-                    XYZ &v1 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]];
-                    XYZ &v2 = skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]];
+                    const XYZ &v0 = skeleton.drawmodel.getTriangleVertex(i, 0);
+                    const XYZ &v1 = skeleton.drawmodel.getTriangleVertex(i, 1);
+                    const XYZ &v2 = skeleton.drawmodel.getTriangleVertex(i, 2);
                     glVertex3f(v0.x, v0.y, v0.z);
                     glVertex3f(v1.x, v1.y, v1.z);
                     glVertex3f(v1.x, v1.y, v1.z);
index 1cd4cea3f93c21ed6f77eac182afbc06b9354226..1fe60115a6d969c5bd1a2c12350eb31eed0af809 100644 (file)
@@ -622,10 +622,10 @@ void Weapon::doStuff(int i)
                             if (whichhit != -1) {
                                 hitsomething = 1;
                                 closestdistance = -1;
-                                closestswordpoint = colpoint; //(position+tippoint)/2;
-                                point[0] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[0]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
-                                point[1] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[1]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
-                                point[2] = DoRotation(Object::objects[k]->model.vertex[Object::objects[k]->model.Triangles[whichhit].vertex[2]], 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+                                closestswordpoint = colpoint;
+                                point[0] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 0), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+                                point[1] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 1), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
+                                point[2] = DoRotation(Object::objects[k]->model.getTriangleVertex(whichhit, 2), 0, Object::objects[k]->yaw, 0) + Object::objects[k]->position;
                                 if (DistancePointLine(&closestswordpoint, &point[0], &point[1], &distance, &colpoint )) {
                                     if (distance < closestdistance || closestdistance == -1) {
                                         closestpoint = colpoint;