AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Other Type of 'get_distance()' (https://forums.alliedmods.net/showthread.php?t=76622)

atomen 08-27-2008 13:38

Other Type of 'get_distance()'
 
Hi!

As you know get_distance calculates the distance(units) between 2 X, Y and Z.
It returns the units between them. But let's say you only want to calculate the origins which is the furthest from each other.

In this example, let's say the 2 X origins are furthest from each other.
How to calculate the distance in units between them and don't include the 2 Y and Z origins??

This is just how It could look(illustration), but I want it in small language of course, not C#.
PHP Code:

static cell AMX_NATIVE_CALL get_distance_x(AMX *amxcell *params)
{
    
cell *cpVec1 get_amxaddr(amxparams[1]);
    
cell *cpVec2 get_amxaddr(amxparams[2]);

    
Vector vec1 Vector((float)cpVec1[X]);
    
Vector vec2 Vector((float)cpVec2[X]);

    
int iDist = (int)((vec1 vec2).Length());

    return 
iDist;



Alka 08-27-2008 15:33

Re: Other Type of 'get_distance()'
 
Dunno, but a origin is a dot with 3 coordinates XYZ, so distance between 2 origins will be equal with distance between only an axe of origin.

XxAvalanchexX 08-27-2008 20:26

Re: Other Type of 'get_distance()'
 
Code:
abs(origin1[0] - origin2[0]);

Exolent[jNr] 08-27-2008 21:03

Re: Other Type of 'get_distance()'
 
Quote:

Originally Posted by Alka (Post 676834)
Dunno, but a origin is a dot with 3 coordinates XYZ, so distance between 2 origins will be equal with distance between only an axe of origin.

Not true.

Let's say our origins are points E and D.

Code:

        A______B
        |\    |\
          | \  | \
          |  \C_|__\D
          |  |  |  |
          |  |  |  |
        E|__|__|F |
          \ |  \ |
            \|____\|
            G      H

The distance from point E to point D is greater than the distance of point E to point A, which is the 1 axis. It is also greater than point B, which is the 2 axis. To get the full distance of our 3-dimensional box, we need to use all 3 dimensions.

You can try yourself:

Code:
public test(id) {     for( new i = 1; i <= g_max_players; i++ )     {         if( i == id || !is_user_connected(i) ) continue;                 new Float:distance[3];         GetPlayerDistance3D(id, i);                 console_print(id, "Distance of all 3 dimensions");         console_print(id, "X Axis: %f", distance[0]);         console_print(id, "X & Y Axis: %f", distance[1]);         console_print(id, "X & Y & Z Axis: %f", distance[2]);                 break;     } } GetPlayerDistance3D(id1, id2, Float:distance[3]) {     new Float:origin1[3], Float:origin2[3];     pev(id1, pev_origin, origin1);     pev(id2, pev_origin, origin2);         new Float:temp1[3], Float:temp2[3];     for( new i = 0; i < 3; i++ )     {         temp1[i] = origin1[i];         temp2[i] = origin2[i];                 distance[i] = get_distance_f(temp1, temp2);     } }


All times are GMT -4. The time now is 03:04.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.