GetNearestDynObject - doing the opposite
#2

hm.. despite 3 or 4 optimisations, i cannot see why this algorithm should fail.. are you sure the surrounding code is ok? ^^
brb, onto editing later, expect some faster script, which will not change behavior i guess...
edit:done:
pawn Код:
stock GetNearestDynObject(playerid)
{
    new
        Float:px,
        Float:py,
        Float:pz,
        currentobject = -1,
        Float:distance = 10000.0,
        Float:ox,
        Float:oy,
        Float:oz,
        Float:odist;
    GetPlayerPos( playerid, px, py, pz );
    for( new index = 0; index < CountDynamicObjects(); index++ )
    {
        if ( !IsValidDynamicObject( index ) ) continue;
        GetDynamicObjectPos( index, ox, oy, oz );
        odist = floatsqroot(
        floatpower( floatsub( ox, px ), 2.0 ) +
        floatpower( floatsub( oy, py ), 2.0 ) +
        floatpower( floatsub( oz, pz ), 2.0 )
        );
        if ( odist < distance )
        {
            currentobject = index;
            distance = odist;
        }
    }
    return currentobject;
}
...this wont fix the bug, but its a little faster - the reasons are obvious. hm... despits that, i cant help without seeing: more coooode :P

edit2: ok, i will inlcude that snippet into my actual project FS, lets see what happens. iam on it, hope youre online in .. 1 hour brb
Reply


Messages In This Thread
GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 21:24
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 21:52
Re: GetNearestDynObject - doing the opposite - by Stylock - 17.02.2013, 22:01
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:10
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:13
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:18
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:19
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:20
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:32
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 22:43

Forum Jump:


Users browsing this thread: 4 Guest(s)