From 602a0c5951050e7cce645534cb4f136cf9f4fee4 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Thu, 17 Jun 2021 14:20:54 +0700 Subject: Rename source and build directory --- src/Models.cpp | 341 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 src/Models.cpp (limited to 'src/Models.cpp') diff --git a/src/Models.cpp b/src/Models.cpp new file mode 100644 index 0000000..8caefd8 --- /dev/null +++ b/src/Models.cpp @@ -0,0 +1,341 @@ +#include "Models.h" + +#include "Serialize.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=fast_sqrt(boundingsphereradius); +} + +bool Model::load(Str255 Name) +{ + short tfile; + long err; + Files file; + + tfile=file.OpenFile(Name); + SetFPos(tfile,fsFromStart,0); + + // read model settings + + err=ReadShort(tfile,1,&vertexNum); + err=ReadShort(tfile,1,&TriangleNum); + + // read the model data + + err=ReadXYZ(tfile,vertexNum,vertex); + err=ReadTexturedTriangle(tfile,TriangleNum,Triangles); + + FSClose(tfile); + + UpdateVertexArray(); + + XYZ average; + int howmany; + average=0; + howmany=0; + for(int i=0;iboundingsphereradius)boundingsphereradius=findDistancefast(average,vertex[i]); + } + boundingsphereradius=fast_sqrt(boundingsphereradius); + + return 1; +} + +void Model::Scale(float xscale,float yscale,float zscale) +{ + 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