#include #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); } void Model::load(const char* path) { auto model = loadModel(path); vertexNum = model.vertices.len; for (short i = 0; i < vertexNum; ++i) { vertex[i].x = model.vertices.ptr[i].x; vertex[i].y = model.vertices.ptr[i].y; vertex[i].z = model.vertices.ptr[i].z; } free(model.vertices.ptr); TriangleNum = model.faces.len; for (short i = 0; i < TriangleNum; ++i) { Triangles[i].vertex[0] = model.faces.ptr[i].v[0]; Triangles[i].vertex[1] = model.faces.ptr[i].v[1]; Triangles[i].vertex[2] = model.faces.ptr[i].v[2]; Triangles[i].r = model.faces.ptr[i].r; Triangles[i].g = model.faces.ptr[i].g; 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;ix,p1->y,p1->z, p2->x,p2->y,p2->z, boundingspherecenter.x,boundingspherecenter.y,boundingspherecenter.z, boundingsphereradius)) for (j=0;jx)*(point.x-p1->x)+(point.y-p1->y)*(point.y-p1->y)+(point.z-p1->z)*(point.z-p1->z); if((distance