From 48417e11854f832c40a42ec497cad3b275b57b2e Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 9 Dec 2021 23:07:32 +0700 Subject: Make XYZ C-compatible --- src/Models.cpp | 70 ++++++++++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) (limited to 'src/Models.cpp') diff --git a/src/Models.cpp b/src/Models.cpp index 4c92f93..6632562 100644 --- a/src/Models.cpp +++ b/src/Models.cpp @@ -4,10 +4,18 @@ #include "Models.h" #include "misc.h" -//Functions -void Model::UpdateVertexArray(){ - int i; - for(i=0;iboundingboxmax.x)boundingboxmax.x=vertex[i].x; - if(vertex[i].y>boundingboxmax.y)boundingboxmax.y=vertex[i].y; - if(vertex[i].z>boundingboxmax.z)boundingboxmax.z=vertex[i].z; - } - average=average/howmany; - boundingspherecenter=average; - boundingsphereradius=0; - for(int i=0;iboundingsphereradius)boundingsphereradius=findDistancefast(average,vertex[i]); - } - boundingsphereradius=sqrt(boundingsphereradius); + boundingspherecenter = {}; + for (int i = 0; i < vertexNum; ++i) + boundingspherecenter += vertex[i]; + boundingspherecenter /= vertexNum; + + boundingsphereradius = 0; + for (int i = 0; i < vertexNum; ++i) + boundingsphereradius = max(boundingsphereradius, + findDistancefast(boundingspherecenter, vertex[i])); + boundingsphereradius = sqrt(boundingsphereradius); } void Model::load(const char* path) @@ -85,30 +80,9 @@ void Model::load(const char* path) Triangles[i].b = model.faces.ptr[i].b; } free(model.faces.ptr); - - XYZ average {}; - for (auto&& v : vertex) - boundingspherecenter += v; - boundingspherecenter /= vertexNum; - - boundingsphereradius = 0; - for (auto&& v : vertex) - boundingsphereradius = std::max(boundingsphereradius, - findDistancefast(average, v)); - boundingsphereradius = sqrt(boundingsphereradius); CalculateNormals(); } -void Model::CalculateNormals() -{ - int i; - for(i=0;i