X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FModels.cpp;h=9f92cb531d2f5eeabc43b4396ba7e83eb5905f49;hb=3d9b1d366f1b3607c40eb5bcbbe631794ed899de;hp=95b93fe4c489d238a2efe1afbfd6e1b04fdc7885;hpb=35b5d8a643d2ff04614a8b9f57026b57d4a82667;p=lugaru.git diff --git a/Source/Models.cpp b/Source/Models.cpp index 95b93fe..9f92cb5 100644 --- a/Source/Models.cpp +++ b/Source/Models.cpp @@ -173,7 +173,7 @@ int Model::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate) oldp1=*p1; *p1=*p1-*move; if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0); - if(findDistancefast(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1; + if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius)return -1; for(i=0;i<4;i++){ for (j=0;jradius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;} + if(distsq(p1,&boundingspherecenter)>radius*radius+boundingsphereradius*boundingsphereradius){*p1=oldp1; return -1;} for (j=0;jboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -538,8 +538,8 @@ bool Model::load(const char *filename,bool texture ) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -620,8 +620,8 @@ bool Model::loaddecal(const char *filename,bool texture ) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -769,8 +769,8 @@ void Model::Scale(float xscale,float yscale,float zscale) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -809,8 +809,8 @@ void Model::Translate(float xtrans,float ytrans,float ztrans) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -830,8 +830,8 @@ void Model::Rotate(float xang,float yang,float zang) boundingsphereradius=0; for(i=0;iboundingsphereradius){ - boundingsphereradius=findDistancefast(&vertex[j],&vertex[i])/2; + if(j!=i&&distsq(&vertex[j],&vertex[i])/2>boundingsphereradius){ + boundingsphereradius=distsq(&vertex[j],&vertex[i])/2; boundingspherecenter=(vertex[i]+vertex[j])/2; } } @@ -1151,7 +1151,7 @@ void Model::MakeDecal(int atype, XYZ *where,float *size, float *opacity, float * static int i,j; if(*opacity>0) - if(findDistancefast(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size)) + if(distsq(where,&boundingspherecenter)<(boundingsphereradius+*size)*(boundingsphereradius+*size)) for(i=0;iy||vertex[Triangles[i].vertex[1]].yy||vertex[Triangles[i].vertex[2]].yy)){ decalposition[numdecals]=*where; @@ -1228,7 +1228,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota static int i,j; if(opacity>0) - if(findDistancefast(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size)) + if(distsq(&where,&boundingspherecenter)<(boundingsphereradius+size)*(boundingsphereradius+size)) for(i=0;iabs(facenormals[i].x)&&abs(facenormals[i].y)>abs(facenormals[i].z)){