Calculating the 3 closest locations
#2

Try with 3 loops:

pawn Код:
stock ReturnClosestDestinations(playerid, &dest1, &dest2, &dest3)
{
    new Float:Pos[3], tmp1, tmp2, tmp3, Float:pdistance, Float:closest=9999.99;
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    foreach(Locations, i)
    {
        pdistance = DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]);
        if(pdistance < closest)
        {
            dest1 = tmp1 = i;
            closest = pdistance;
        }
    }
    closest = 9999.99;
    foreach(Locations, i)
    {
        if(i == tmp1) continue;
        pdistance = DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]);
        if(pdistance < closest)
        {
            dest2 = tmp2 = i;
            closest = pdistance;
        }
    }
    closest = 9999.99;
    foreach(Locations, i)
    {
        if(i == tmp1 || i == tmp2) continue;
        pdistance = DistanceToPoint(Pos[0], Pos[1], Pos[2], lInfo[i][PointX], lInfo[i][PointY], lInfo[i][PointZ]);
        if(pdistance < closest)
        {
            dest3 = tmp3 = i;
            closest = pdistance;
        }
    }
    return 1;
}
Reply


Messages In This Thread
Calculating the 3 closest locations - by [03]Garsino - 20.02.2011, 17:15
Re: Calculating the 3 closest locations - by MadeMan - 20.02.2011, 19:15
Re: Calculating the 3 closest locations - by [03]Garsino - 20.02.2011, 20:05
Re: Calculating the 3 closest locations - by [03]Garsino - 24.02.2011, 05:51
Re: Calculating the 3 closest locations - by [03]Garsino - 28.02.2011, 07:08
Re: Calculating the 3 closest locations - by legodude - 28.02.2011, 08:26
Re: Calculating the 3 closest locations - by Simon - 28.02.2011, 08:50

Forum Jump:


Users browsing this thread: 1 Guest(s)