From afdb97f1c3e430801a1fd0c1b04a8a2102e8f1ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20Chilliet?= Date: Sun, 8 Jan 2017 15:44:11 +0100 Subject: [PATCH] Added a helper for getting model triangle vertexes, mostly used in Decal for now. --- Source/Graphic/Decal.cpp | 54 +++++++++++++++++++------------------- Source/Graphic/Models.cpp | 5 ++++ Source/Graphic/Models.hpp | 1 + Source/Objects/Person.cpp | 12 ++++----- Source/Objects/Weapons.cpp | 8 +++--- 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/Source/Graphic/Decal.cpp b/Source/Graphic/Decal.cpp index 335a4bc..0857bef 100644 --- a/Source/Graphic/Decal.cpp +++ b/Source/Graphic/Decal.cpp @@ -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; } } diff --git a/Source/Graphic/Models.cpp b/Source/Graphic/Models.cpp index 0edde87..09036ae 100644 --- a/Source/Graphic/Models.cpp +++ b/Source/Graphic/Models.cpp @@ -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--) { diff --git a/Source/Graphic/Models.hpp b/Source/Graphic/Models.hpp index 54b2885..cb5bcda 100644 --- a/Source/Graphic/Models.hpp +++ b/Source/Graphic/Models.hpp @@ -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); diff --git a/Source/Objects/Person.cpp b/Source/Objects/Person.cpp index 874194b..95cbf52 100644 --- a/Source/Objects/Person.cpp +++ b/Source/Objects/Person.cpp @@ -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); diff --git a/Source/Objects/Weapons.cpp b/Source/Objects/Weapons.cpp index 1cd4cea..1fe6011 100644 --- a/Source/Objects/Weapons.cpp +++ b/Source/Objects/Weapons.cpp @@ -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; -- 2.39.5