From: sf17k Date: Mon, 30 Jul 2012 04:35:39 +0000 (-0400) Subject: rename for readability X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=298a6f90decc9910db67ad1d15789d0ff8c249fe rename for readability findDistancefast -> distsq findDistancefastflat -> distsqflat --- diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index a6b02a5..4b60a01 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -445,7 +445,7 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_BLEND); glEnable(GL_LIGHTING); terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z); - distance=findDistancefast(&viewer,&player[k].coords); + distance=distsq(&viewer,&player[k].coords); distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance; glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance); if(distance>=1) @@ -470,7 +470,7 @@ int Game::DrawGLScene(StereoSide side) } if(!cameramode&&musictype==stream_fighttheme) - playerdist=findDistancefastflat(&player[0].coords,&viewer); + playerdist=distsqflat(&player[0].coords,&viewer); else playerdist=-100; glPushMatrix(); @@ -490,7 +490,7 @@ int Game::DrawGLScene(StereoSide side) glTranslatef(hawkcoords.x,hawkcoords.y,hawkcoords.z); glRotatef(hawkyaw,0,1,0); glTranslatef(25,0,0); - distance=findDistancefast(&viewer,&realhawkcoords)*1.2; + distance=distsq(&viewer,&realhawkcoords)*1.2; glColor4f(light.color[0],light.color[1],light.color[2],(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance); if((viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance>1) glColor4f(light.color[0],light.color[1],light.color[2],1); @@ -508,7 +508,7 @@ int Game::DrawGLScene(StereoSide side) glEnable(GL_BLEND); glEnable(GL_LIGHTING); terrainlight=terrain.getLighting(player[k].coords.x,player[k].coords.z); - distance=findDistancefast(&viewer,&player[k].coords); + distance=distsq(&viewer,&player[k].coords); distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance; glColor4f(terrainlight.x,terrainlight.y,terrainlight.z,distance); if(distance>=1) @@ -917,9 +917,9 @@ int Game::DrawGLScene(StereoSide side) float distance=0; closest=currenthotspot; for(i=0;i=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){ + if(distsq(&player[0].coords,&hotspot[i])=0)||(hotspottype[i]<=40&&hotspottype[i]>=20))){ closestdist=distance; closest=i; } @@ -929,7 +929,7 @@ int Game::DrawGLScene(StereoSide side) currenthotspot=closest; if(currenthotspot!=-1){ if(hotspottype[closest]<=10){ - if(findDistancefast(&player[0].coords,&hotspot[closest])maxdistance){ //~ whichclosest=i; maxdistance=tempdist; @@ -1481,7 +1481,7 @@ int Game::DrawGLScene(StereoSide side) } for(i=0;imaxdistance){ //~ whichclosest=i; maxdistance=tempdist; @@ -1500,7 +1500,7 @@ int Game::DrawGLScene(StereoSide side) glTranslatef(-(center.x/terrain.scale/256*-2+1),(center.z/terrain.scale/256*-2+1),0); for(i=0;i::max(); for(int i=1; i::max(); for(int i=0; imaxdistance){ //~ whichclosest=i; maxdistance=tempdist; @@ -2800,7 +2800,7 @@ void doDebugKeys(){ float closestdist = std::numeric_limits::max(); for(int i=1; i=0 && findDistancefast(&player[closest].coords,&player[0].coords)<144){ + if(closest>=0 && distsq(&player[closest].coords,&player[0].coords)<144){ blah=player[closest].coords; emit_sound_at(splattersound, blah); emit_sound_at(breaksound2, blah); @@ -2909,18 +2909,18 @@ void doDebugKeys(){ XYZ temppos; for(int j=0;j1) for(int i=0;i0&& + if(distsq(&player[k].coords,&player[k].realoldcoords)>0&& !player[k].skeleton.free&& player[k].targetanimation!=climbanim&& player[k].targetanimation!=hanganim){ @@ -3834,7 +3834,7 @@ void doAttacks(){ player[i].targetanimation==knifeslashstartanim|| player[i].targetanimation==staffhitanim|| player[i].targetanimation==staffspinhitanim) - if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){ + if(distsq(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){ player[k].setAnimation(dodgebackanim); player[k].targetyaw=roughDirectionTo(player[k].coords,player[i].coords); player[k].targettilt2=pitchTo(player[k].coords,player[i].coords); @@ -3870,7 +3870,7 @@ void doAttacks(){ if(!player[k].hasvictim) if(animation[player[k].targetanimation].attack!=reversal){ //choose an attack - const float distance=findDistancefast(&player[k].coords,&player[i].coords); + const float distance=distsq(&player[k].coords,&player[i].coords); if(distance<4.5&& !player[i].skeleton.free&& player[i].howactivecoords)) + if(distsq(&player[k].coords,&player[i].coords)< + distsq(&player[k].coords,&player[k].victim->coords)) player[k].victim=&player[i]; }else{ player[k].victim=&player[i]; @@ -4279,8 +4279,8 @@ void doAttacks(){ player[k].isRun()&& player[k].wasRun()&& ((player[k].hasvictim&& - findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&& - findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&& + distsq(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&& + distsq(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&& !player[k].victim->skeleton.free&& player[k].victim->targetanimation!=getupfrombackanim&& player[k].victim->targetanimation!=getupfromfrontanim&& @@ -4343,7 +4343,7 @@ void doPlayerCollisions(){ if(player[i].coords.z>player[k].coords.z-3) if(player[i].coords.zskeleton.free) collisionradius=3; if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&& - (findDistancefast(&tempcoords1,&tempcoords2)player[i].coords.y+2&& !player[0].onterrain) player[i].pause=1; @@ -4533,8 +4533,8 @@ void doAI(int i){ closest=-1; closestdistance=-1; for(int j=0;j0) if(player[j].coords.y0&&(tutoriallevel!=1||cananger)&&hostile) for(int j=0;j0&&findDistancefast(&player[i].coords,&envsound[j])< + if(vol>0&&distsq(&player[i].coords,&envsound[j])< 2*(vol+vol*(player[i].creature==rabbittype)*3)) player[i].aitype=attacktypecutoff; } @@ -4779,12 +4779,12 @@ void doAI(int i){ if(player[i].howactive0) if((-1==checkcollide( DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)* @@ -4900,7 +4900,7 @@ void doAI(int i){ player[i].aiupdatedelay=.05; player[i].forwardkeydown=1; - if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){ + if(distsqflat(&player[i].coords,&player[i].lastseen)<1*sq(player[i].scale*5)||player[i].lastchecktime<0){ player[i].forwardkeydown=0; player[i].aiupdatedelay=1; player[i].lastseen.x+=(float(Random()%100)-50)/25; @@ -4922,8 +4922,8 @@ void doAI(int i){ float leftdist,rightdist; leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0); rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0); - leftdist = findDistancefast(&leftpos, &player[i].avoidwhere); - rightdist = findDistancefast(&rightpos, &player[i].avoidwhere); + leftdist = distsq(&leftpos, &player[i].avoidwhere); + rightdist = distsq(&rightpos, &player[i].avoidwhere); if(leftdist0&&((tutoriallevel!=1||cananger)&&hostile)) for(int k=0;k0) if((checkcollide( DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)* @@ -5006,7 +5006,7 @@ void doAI(int i){ player[k].howactive=0){ if(weapons[player[i].ally].owner!=-1|| - findDistancefast(&player[i].coords,&weapons[player[i].ally].position)>16){ + distsq(&player[i].coords,&weapons[player[i].ally].position)>16){ player[i].aitype=attacktypecutoff; player[i].lastseentime=1; } @@ -5145,8 +5145,8 @@ void doAI(int i){ float leftdist,rightdist; leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0); rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0); - leftdist = findDistancefast(&leftpos, &player[i].avoidwhere); - rightdist = findDistancefast(&rightpos, &player[i].avoidwhere); + leftdist = distsq(&leftpos, &player[i].avoidwhere); + rightdist = distsq(&rightpos, &player[i].avoidwhere); if(leftdist.5) player[i].stunned=1; } @@ -5220,7 +5220,7 @@ void doAI(int i){ weapons[i].velocity.x==0&& weapons[i].velocity.z==0&& weapons[i].velocity.y==0){ - if(findDistancefast(&player[i].coords,&weapons[k].position)<16) { + if(distsq(&player[i].coords,&weapons[k].position)<16) { player[i].wentforweapon++; player[i].lastchecktime=6; player[i].aitype=getweapontype; @@ -5294,18 +5294,18 @@ void doAI(int i){ //chase player XYZ rotatetarget=player[0].coords+player[0].velocity; XYZ targetpoint=player[0].coords; - if(findDistancefast(&player[0].coords,&player[i].coords)< - findDistancefast(&rotatetarget,&player[i].coords)) + if(distsq(&player[0].coords,&player[i].coords)< + distsq(&rotatetarget,&player[i].coords)) targetpoint+=player[0].velocity* findDistance(&player[0].coords,&player[i].coords)/findLength(&player[i].velocity); player[i].targetyaw=roughDirectionTo(player[i].coords,targetpoint); player[i].lookyaw=player[i].targetyaw; player[i].aiupdatedelay=.2+fabs((float)(Random()%100)/1000); - if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1)) + if(distsq(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1)) player[i].forwardkeydown=1; - else if((findDistancefast(&player[i].coords,&player[0].coords)>16|| - findDistancefast(&player[i].coords,&player[0].coords)<9)&& + else if((distsq(&player[i].coords,&player[0].coords)>16|| + distsq(&player[i].coords,&player[0].coords)<9)&& player[0].weaponactive!=-1) player[i].forwardkeydown=1; else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0)) @@ -5341,7 +5341,7 @@ void doAI(int i){ player[i].attackkeydown=1; else player[i].attackkeydown=0; - if(player[i].isRun()&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7) + if(player[i].isRun()&&Random()%6&&distsq(&player[i].coords,&player[0].coords)>7) player[i].attackkeydown=0; //TODO: wat @@ -5366,7 +5366,7 @@ void doAI(int i){ player[i].weaponactive!=-1|| player[j].targetanimation==staffhitanim|| player[j].targetanimation==staffspinhitanim)) - if(findDistancefast(&player[j].coords,&player[j].victim->coords)<4&& + if(distsq(&player[j].coords,&player[j].victim->coords)<4&& player[j].victim==&player[i]&& (player[j].targetanimation==sweepanim|| player[j].targetanimation==spinkickanim|| @@ -5377,7 +5377,7 @@ void doAI(int i){ player[j].targetanimation==wolfslapanim|| player[j].targetanimation==knifeslashstartanim|| player[j].targetanimation==swordslashanim&& - (findDistancefast(&player[j].coords,&player[i].coords)<2|| + (distsq(&player[j].coords,&player[i].coords)<2|| player[i].weaponactive!=-1))){ if(target>=0) target=-1; @@ -5391,7 +5391,7 @@ void doAI(int i){ if(player[i].collided<1) player[i].jumpkeydown=0; if(player[i].collided>.8&&player[i].jumppower>=5|| - findDistancefast(&player[i].coords,&player[0].coords)>400&& + distsq(&player[i].coords,&player[0].coords)>400&& player[i].onterrain&& player[i].creature==rabbittype) player[i].jumpkeydown=1; @@ -5399,7 +5399,7 @@ void doAI(int i){ if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0) player[0].jumpkeydown=0; if(player[0].targetanimation==jumpdownanim&& - findDistancefast(&player[0].coords,&player[i].coords)<40) + distsq(&player[0].coords,&player[i].coords)<40) player[i].crouchkeydown=1; if(player[i].jumpkeydown) player[i].attackkeydown=0; @@ -6381,7 +6381,7 @@ void Game::Tick(){ realdialoguetype>0&& (dialoguegonethrough[i]==0||!special)&& (special||Input::isKeyPressed(attackkey))){ - if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6|| + if(distsq(&player[0].coords,&player[realdialoguetype].coords)<6|| player[realdialoguetype].howactive>=typedead1|| dialoguetype[i]>40&&dialoguetype[i]<50){ whichdialogue=i; @@ -6833,14 +6833,14 @@ void Game::Tick(){ //avoid flaming things for(int j=0;jid) - if(findDistancefastflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1) - if(findDistancefast(&player[i].coords,&weapons[j].position)<1||player[i].victim){ + if(distsqflat(&player[i].coords,&weapons[j].position)<2&&player[i].weaponactive==-1) + if(distsq(&player[i].coords,&weapons[j].position)<1||player[i].victim){ if(weapons[j].getType()!=staff) emit_sound_at(knifedrawsound, player[i].coords, 128.); @@ -6972,7 +6972,7 @@ void Game::Tick(){ }else if((player[i].isIdle()|| player[i].isFlip()|| player[i].aitype!=playercontrolled)&& - findDistancefast(&player[i].coords,&weapons[j].position)<5&& + distsq(&player[i].coords,&weapons[j].position)<5&& player[i].coords.yid) - if(findDistancefastflat(&player[i].coords,&weapons[k].position)<3&& + if(distsqflat(&player[i].coords,&weapons[k].position)<3&& player[i].weaponactive==-1){ if(weapons[k].getType()!=staff) emit_sound_at(knifedrawsound, player[i].coords, 128.); @@ -7018,7 +7018,7 @@ void Game::Tick(){ if(j!=i) if(player[j].num_weapons&& player[j].skeleton.free&& - findDistancefast(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&& + distsq(&player[i].coords,&player[j].coords)<2/*&&player[j].dead*/&& (((player[j].skeleton.forward.y<0&& player[j].weaponstuckwhere==0)|| (player[j].skeleton.forward.y>0&& @@ -7121,8 +7121,8 @@ void Game::Tick(){ if(tutoriallevel!=1||tutorialstage==49) if(hostile) if(normaldotproduct(player[i].facing,player[i].coords-player[j].coords)<0&& - findDistancefast(&player[i].coords,&player[j].coords)<100&& - findDistancefast(&player[i].coords,&player[j].coords)>1.5&& + distsq(&player[i].coords,&player[j].coords)<100&& + distsq(&player[i].coords,&player[j].coords)>1.5&& !player[j].skeleton.free&& -1==checkcollide(DoRotation(player[j].getJointFor(head).position,0,player[j].yaw,0)*player[j].scale+player[j].coords,DoRotation(player[i].getJointFor(head).position,0,player[i].yaw,0)*player[i].scale+player[i].coords)){ if(!player[i].isFlip()){ @@ -7277,14 +7277,14 @@ void Game::Tick(){ if(numplayers>1) for(int j=0;j1) for(int j=0;jcoords)<3&& + if(distsq(&player[j].coords,&player[j].victim->coords)<3&& player[j].victim==&player[i]&& (player[j].targetanimation==sweepanim|| player[j].targetanimation==upunchanim|| @@ -7293,7 +7293,7 @@ void Game::Tick(){ player[j].targetanimation==knifeslashstartanim|| player[j].targetanimation==staffhitanim|| player[j].targetanimation==staffspinhitanim)&& - findDistancefast(&player[j].coords,&player[i].coords)<2))){ + distsq(&player[j].coords,&player[i].coords)<2))){ if(target>=0) target=-1; else @@ -7330,7 +7330,7 @@ void Game::Tick(){ !player[j].skeleton.free&& player[j].victim&& player[i].highreversaldelay<=0){ - if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&& + if(distsq(&player[j].coords,&player[j].victim->coords)<3&& player[j].victim==&player[i]&& (player[j].targetanimation==spinkickanim)&& player[i].isCrouch()){ @@ -7511,7 +7511,7 @@ void Game::Tick(){ if(numplayers>1) for(int j=0;jcoords)<3&& + if(distsq(&player[j].coords,&player[j].victim->coords)<3&& player[j].victim==&player[i]&& (player[j].targetanimation==sweepanim)){ if(target>=0)target=-1; @@ -7665,7 +7665,7 @@ void Game::Tick(){ oldtemp=temp; oldtemp2=temp2; if(tutorialstage>=51) - if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){ + if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){ OPENAL_StopSound(OPENAL_ALL); // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu... OPENAL_SetFrequency(OPENAL_ALL, 0.001); @@ -7679,7 +7679,7 @@ void Game::Tick(){ flash(); } if(tutorialstage<51) - if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){ + if(distsq(&temp,&player[0].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[0].coords)<4){ emit_sound_at(fireendsound, player[0].coords); player[0].coords=(oldtemp+oldtemp2)/2; @@ -7687,7 +7687,7 @@ void Game::Tick(){ flash(); } if(tutorialstage>=14&&tutorialstage<50) - if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){ + if(distsq(&temp,&player[1].coords)>=distsq(&temp,&temp2)-1||distsq(&temp3,&player[1].coords)<4){ emit_sound_at(fireendsound, player[1].coords); for(int i=0;iradius*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)){ diff --git a/Source/Objects.cpp b/Source/Objects.cpp index 8f2544f..06c8b8b 100644 --- a/Source/Objects.cpp +++ b/Source/Objects.cpp @@ -90,9 +90,9 @@ void Objects::Draw() if(type[i]!=firetype){ moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0); if(type[i]==tunneltype||frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){ - distance=findDistancefast(&viewer,&position[i]); + distance=distsq(&viewer,&position[i]); distance*=1.2; - hidden=!(findDistancefastflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype)); + hidden=!(distsqflat(&viewer,&position[i])>playerdist+3||(type[i]!=bushtype&&type[i]!=treeleavestype)); if(!hidden){ if(detail==2&&distance>viewdistance*viewdistance/4&&environment==desertenvironment)glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, blurness ); @@ -329,7 +329,7 @@ void Objects::Draw() if(type[i]==treeleavestype||type[i]==bushtype){ moved=DoRotation(model[i].boundingspherecenter,0,yaw[i],0); if(frustum.SphereInFrustum(position[i].x+moved.x,position[i].y+moved.y,position[i].z+moved.z,model[i].boundingsphereradius)){ - hidden=findDistancefastflat(&viewer,&position[i])<=playerdist+3; + hidden=distsqflat(&viewer,&position[i])<=playerdist+3; if(hidden){ distance=1; if(distance>0){ diff --git a/Source/Person.cpp b/Source/Person.cpp index 87a4bbe..10118c1 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -93,7 +93,7 @@ void Person::CheckKick() && victim != this && currentframe >= 2 && currentanimation == rabbitkickanim) - && (findDistancefast(&coords,&victim->coords) < 1.2) + && (distsq(&coords,&victim->coords) < 1.2) && (!victim->skeleton.free))) return; @@ -552,9 +552,9 @@ bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){ t = dotproduct(&temp,&N)/findLength(&N); r = 1 - (s + t);*/ - bary.x=findDistancefast(&p0,&p1); - bary.y=findDistancefast(&p0,&p2); - bary.z=findDistancefast(&p0,&p3); + bary.x=distsq(&p0,&p1); + bary.y=distsq(&p0,&p2); + bary.z=distsq(&p0,&p3); total=bary.x+bary.y+bary.z; bary.x/=total; @@ -775,7 +775,7 @@ void Person::Reverse() victim->currentanimation=upunchreversalanim; victim->targetanimation=upunchreversalanim; } - if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){ + if(targetanimation==staffhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){ if(victim->weaponactive!=-1){ victim->throwtogglekeydown=1; weapons[victim->weaponids[0]].owner=-1; @@ -803,7 +803,7 @@ void Person::Reverse() victim->currentanimation=staffhitreversalanim; victim->targetanimation=staffhitreversalanim; } - if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){ + if(targetanimation==staffspinhitanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){ if(victim->weaponactive!=-1){ victim->throwtogglekeydown=1; weapons[victim->weaponids[0]].owner=-1; @@ -830,7 +830,7 @@ void Person::Reverse() victim->currentanimation=staffspinhitreversalanim; victim->targetanimation=staffspinhitreversalanim; } - if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){ + if(targetanimation==swordslashanim&&distsq(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){ if(victim->weaponactive!=-1){ victim->throwtogglekeydown=1; weapons[victim->weaponids[0]].owner=-1; @@ -857,7 +857,7 @@ void Person::Reverse() victim->currentanimation=swordslashreversalanim; victim->targetanimation=swordslashreversalanim; } - if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){ + if(targetanimation==knifeslashstartanim&&distsq(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){ if(victim->weaponactive!=-1){ victim->throwtogglekeydown=1; weapons[victim->weaponids[0]].owner=-1; @@ -1008,7 +1008,7 @@ void Person::Reverse() } if(hasvictim) if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){ - if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){ + if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||distsq(&coords,&victim->coords)>.2){ victim->targetanimation=dodgebackanim; victim->targetframe=0; victim->target=0; @@ -1391,7 +1391,7 @@ void Person::FootLand(int which, float opacity){ if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords; if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords; //footpoint.y=coords.y; - if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity); + if(distsq(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity); } else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){ footvel=velocity/5; @@ -1400,8 +1400,8 @@ void Person::FootLand(int which, float opacity){ if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords; footpoint.y=terrain.getHeight(footpoint.x,footpoint.z); terrainlight=terrain.getLighting(footpoint.x,footpoint.z); - if(findDistancefast(&footpoint,&viewer)=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)=1||detail==2)if(detail==2)if(distsq(&footpoint,&viewer)=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)=1||detail==2)if(detail==2)if(distsq(&footpoint,&viewer)=1){ + if(distsqflat(&coords,&weapons[i].position)<4&&weaponactive==-1){ + if(distsq(&coords,&weapons[i].position)>=1){ if(weapons[i].getType()!=staff){ emit_sound_at(knifedrawsound, coords, 128.); } @@ -1684,8 +1684,8 @@ void Person::DoAnimations(){ if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i) if(player[weapons[i].owner].num_weapons>1)willwork=0; if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free)) - if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){ - if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){ + if(willwork&&distsqflat(&coords,&weapons[i].position)<3&&weaponactive==-1){ + if(distsq(&coords,&weapons[i].position)<1||hasvictim){ bool fleshstuck=false; if(weapons[i].owner!=-1) if(victim->weaponstuck!=-1){ @@ -1789,7 +1789,7 @@ void Person::DoAnimations(){ dojumpattack=0; if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1; if(hasvictim) - if(findDistancefast(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1; if(!hostile)dojumpattack=0; + if(distsq(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1; if(!hostile)dojumpattack=0; if(dojumpattack){ if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){ targetanimation=rabbittackleanim; @@ -1807,8 +1807,8 @@ void Person::DoAnimations(){ targetloc+=coords; for(i=0;iskeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){ if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){ escapednum=0; if(id==0)camerashake+=.4; if(Random()%2||creature==wolftype){ @@ -1877,7 +1877,7 @@ void Person::DoAnimations(){ } if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){ escapednum=0; if(id==0)camerashake+=.4; if(Random()%2||creature==wolftype){ @@ -1909,7 +1909,7 @@ void Person::DoAnimations(){ } if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ escapednum=0; if(id==0)camerashake+=.4; victim->spurt=1; @@ -1944,7 +1944,7 @@ void Person::DoAnimations(){ } if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ escapednum=0; if(id==0)camerashake+=.4; victim->spurt=1; @@ -1979,7 +1979,7 @@ void Person::DoAnimations(){ } if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){ escapednum=0; if(id==0)camerashake+=.4; if(Random()%2){ @@ -2003,7 +2003,7 @@ void Person::DoAnimations(){ } if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){ escapednum=0; if(id==0)camerashake+=.2; emit_sound_at(whooshhitsound, victim->coords, 128.); @@ -2036,7 +2036,7 @@ void Person::DoAnimations(){ } if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){ escapednum=0; if(id==0)camerashake+=.4; if(tutoriallevel!=1){ @@ -2060,7 +2060,7 @@ void Person::DoAnimations(){ } if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){ escapednum=0; if(id==0)camerashake+=.4; if(tutoriallevel!=1){ @@ -2110,7 +2110,7 @@ void Person::DoAnimations(){ } if(victim&&hasvictim){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ XYZ where,startpoint,endpoint,movepoint,colpoint; float rotationpoint; @@ -2242,7 +2242,7 @@ void Person::DoAnimations(){ } hasvictim=victim->DoBloodBigWhere(2,220,footpoint); if(hasvictim){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ victim->skeleton.longdead=0; victim->skeleton.free=1; victim->skeleton.broken=0; @@ -2276,7 +2276,7 @@ void Person::DoAnimations(){ } if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3){ escapednum=0; if(id==0)camerashake+=.4; if(Random()%2){ @@ -2313,7 +2313,7 @@ void Person::DoAnimations(){ if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*2){ escapednum=0; if(id==0)camerashake+=.4; if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){ @@ -2359,7 +2359,7 @@ void Person::DoAnimations(){ } if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){ if(victim->id==0)camerashake+=.4; emit_sound_at(landsound2, victim->coords); @@ -2368,7 +2368,7 @@ void Person::DoAnimations(){ } if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4){ if(victim->id==0)camerashake+=.4; if(weaponactive!=-1){ @@ -2414,7 +2414,7 @@ void Person::DoAnimations(){ if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){ if(hasvictim) - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){ escapednum=0; if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225); @@ -2462,7 +2462,7 @@ void Person::DoAnimations(){ } } if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){ if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){ award_bonus(id, Slashbonus); escapednum=0; @@ -2487,7 +2487,7 @@ void Person::DoAnimations(){ float bloodlossamount; bloodlossamount=200+abs((float)(Random()%40))-20; victim->bloodloss+=bloodlossamount/victim->armorhigh; - //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords)); + //victim->bloodloss+=100*(6.5-distsq(&coords,&victim->coords)); victim->DoDamage(damagemult*0); XYZ footvel,footpoint; @@ -2553,7 +2553,7 @@ void Person::DoAnimations(){ } if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){ if(tutoriallevel!=1){ weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250; escapednum=0; @@ -2587,7 +2587,7 @@ void Person::DoAnimations(){ } if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){ if(tutoriallevel!=1){ weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250; escapednum=0; @@ -2618,7 +2618,7 @@ void Person::DoAnimations(){ } if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){ escapednum=0; if(tutoriallevel!=1){ if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500; @@ -2672,7 +2672,7 @@ void Person::DoAnimations(){ } if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){ - if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){ + if(distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){ escapednum=0; if(id==0)camerashake+=.4; XYZ relative; @@ -2730,7 +2730,7 @@ void Person::DoAnimations(){ } if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){ - if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){ + if(victim->targetanimation!=jumpupanim&&distsq(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){ escapednum=0; if(id==0)camerashake+=.2; if(tutoriallevel!=1){ @@ -3324,7 +3324,7 @@ void Person::DoAnimations(){ if(numplayers>1) for(i=0;i1) for(i=0;i0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){ + if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&distsq(&viewer,&coords)<9){ texupdatedelay=.12; bloodsize=5-realtexdetail; @@ -4339,7 +4339,7 @@ void Person::DoStuff(){ - if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){ + if((id==0||distsq(&coords,&viewer)<50)&&autoslomo){ slomo=1; slomodelay=.2; } @@ -4707,7 +4707,7 @@ void Person::DoStuff(){ if(findLengthfast(&velocity)>.1) for(i=0;iobjects.position[i].y+3*objects.scale[i]){ + if(distsqflat(&tempcoord,&objects.position[i])objects.position[i].y+3*objects.scale[i]){ if(objects.messedwith[i]<=0){ XYZ tempvel; XYZ pos; @@ -5361,7 +5361,7 @@ void Person::DoStuff(){ midterrain=0; midterrain.x=terrain.size*terrain.scale/2; midterrain.z=terrain.size*terrain.scale/2; - if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){ + if(distsqflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){ XYZ tempposit; tempposit=coords-midterrain; tempposit.y=0; @@ -5374,7 +5374,7 @@ void Person::DoStuff(){ int Person::DrawSkeleton(){ int oldplayerdetail; - if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)1)distance=1; if(distance>0){ @@ -6123,7 +6123,7 @@ int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, oldp1=*p1; *p1=*p1-*move; - if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1; + if(distsq(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1; if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0); for(i=0;i<4;i++){ for (j=0;jTriangleNum;j++){ diff --git a/Source/Quaternions.h b/Source/Quaternions.h index 39037b5..417c299 100644 --- a/Source/Quaternions.h +++ b/Source/Quaternions.h @@ -105,9 +105,9 @@ inline XYZ DoRotationRadian(XYZ thePoint, float xang, float yang, float zang); inline float findDistance(XYZ *point1, XYZ *point2); inline float findLength(XYZ *point1); inline float findLengthfast(XYZ *point1); -inline float findDistancefast(XYZ *point1, XYZ *point2); -inline float findDistancefast(XYZ point1, XYZ point2); -inline float findDistancefastflat(XYZ *point1, XYZ *point2); +inline float distsq(XYZ *point1, XYZ *point2); +inline float distsq(XYZ point1, XYZ point2); +inline float distsqflat(XYZ *point1, XYZ *point2); inline float dotproduct(const XYZ *point1, const XYZ *point2); bool sphere_line_intersection ( float x1, float y1 , float z1, @@ -302,15 +302,15 @@ inline float findLengthfast(XYZ *point1){ return((point1->x)*(point1->x)+(point1->y)*(point1->y)+(point1->z)*(point1->z)); } -inline float findDistancefast(XYZ *point1, XYZ *point2){ +inline float distsq(XYZ *point1, XYZ *point2){ return((point1->x-point2->x)*(point1->x-point2->x)+(point1->y-point2->y)*(point1->y-point2->y)+(point1->z-point2->z)*(point1->z-point2->z)); } -inline float findDistancefast(XYZ point1, XYZ point2){ +inline float distsq(XYZ point1, XYZ point2){ return((point1.x-point2.x)*(point1.x-point2.x)+(point1.y-point2.y)*(point1.y-point2.y)+(point1.z-point2.z)*(point1.z-point2.z)); } -inline float findDistancefastflat(XYZ *point1, XYZ *point2){ +inline float distsqflat(XYZ *point1, XYZ *point2){ return((point1->x-point2->x)*(point1->x-point2->x)+(point1->z-point2->z)*(point1->z-point2->z)); } diff --git a/Source/Sprite.cpp b/Source/Sprite.cpp index 334a6f5..8b7385f 100644 --- a/Source/Sprite.cpp +++ b/Source/Sprite.cpp @@ -189,9 +189,9 @@ void Sprite::Draw() } } if(sprites[i]->type==snowsprite) - distancemult=(144-(findDistancefast(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144; + distancemult=(144-(distsq(&tempviewer,&sprites[i]->position)-(144*fadestart))*(1/(1-fadestart)))/144; else - distancemult=(viewdistsquared-(findDistancefast(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; + distancemult=(viewdistsquared-(distsq(&viewer,&sprites[i]->position)-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; if(sprites[i]->type==flamesprite){ if(distancemult>=1) glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity); else glColor4f(sprites[i]->color[0],sprites[i]->color[1],sprites[i]->color[2],sprites[i]->opacity*distancemult); diff --git a/Source/Terrain.cpp b/Source/Terrain.cpp index ecc8757..1af3058 100644 --- a/Source/Terrain.cpp +++ b/Source/Terrain.cpp @@ -103,7 +103,7 @@ int Terrain::lineTerrain(XYZ p1,XYZ p2, XYZ *p) triangles[2].z=j; intersecting=LineFacet(p1,p2,triangles[0],triangles[1],triangles[2],&point); - distance=findDistancefast(&p1,&point); + distance=distsq(&p1,&point); if((distanceviewdistsquared)distance=viewdistsquared; colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; } @@ -222,7 +222,7 @@ void Terrain::UpdateTransparencyotherother(int whichx, int whichy){ vertex.x=i*scale; vertex.z=j*scale; vertex.y=heightmap[i][j]*scale; - distance=findDistancefast(&viewer,&vertex); + distance=distsq(&viewer,&vertex); if(distance>viewdistsquared)distance=viewdistsquared; colors[i][j][3]=(viewdistsquared-(distance-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; } @@ -982,7 +982,7 @@ void Terrain::draw(int layer) terrainpoint.x=i*patch_size+(patch_size)/2; terrainpoint.y=viewer.y;//heightmap[i][j]*scale; terrainpoint.z=j*patch_size+(patch_size)/2; - distance[i][j]=findDistancefast(&viewer,&terrainpoint); + distance[i][j]=distsq(&viewer,&terrainpoint); } } } @@ -1087,12 +1087,12 @@ void Terrain::drawdecals() } } if(decaltype[i]==shadowdecal||decaltype[i]==shadowdecalpermanent){ - distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; + distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; if(distancemult>=1)glColor4f(1,1,1,decalopacity[i]); if(distancemult<1)glColor4f(1,1,1,decalopacity[i]*distancemult); } if(decaltype[i]==footprintdecal||decaltype[i]==bodyprintdecal){ - distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; + distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; if(distancemult>=1){ glColor4f(1,1,1,decalopacity[i]); if(decalalivetime[i]>3)glColor4f(1,1,1,decalopacity[i]*(5-decalalivetime[i])/2); @@ -1103,7 +1103,7 @@ void Terrain::drawdecals() } } if((decaltype[i]==blooddecal||decaltype[i]==blooddecalfast||decaltype[i]==blooddecalslow)){ - distancemult=(viewdistsquared-(findDistancefast(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; + distancemult=(viewdistsquared-(distsq(&viewer,&decalposition[i])-(viewdistsquared*fadestart))*(1/(1-fadestart)))/viewdistsquared; if(distancemult>=1){ glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]); if(decalalivetime[i]<4)glColor4f(decalbrightness[i],decalbrightness[i],decalbrightness[i],decalopacity[i]*decalalivetime[i]*.25); diff --git a/Source/Weapons.cpp b/Source/Weapons.cpp index a7d587f..5998150 100644 --- a/Source/Weapons.cpp +++ b/Source/Weapons.cpp @@ -215,8 +215,8 @@ void Weapon::DoStuff(int i) { for(int j=0;j80) { + if(Random()%50==0&&distsq(&position,&viewer)>80) { XYZ shinepoint; shinepoint=position+(tippoint-position)*(((float)abs(Random()%100))/100); Sprite::MakeSprite(weaponshinesprite, shinepoint,normalrot, 1,1,1, (.1+(float)abs(Random()%100)/200-.25)*1/3*fast_sqrt(findDistance(&shinepoint,&viewer)), 1); @@ -898,7 +898,7 @@ void Weapon::Draw() { static GLfloat M[16]; if((frustum.SphereInFrustum(position.x,position.y,position.z,1)&& - findDistancefast(&viewer,&position)