AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Two origins, get origin of points in line (https://forums.alliedmods.net/showthread.php?t=132171)

Hunter-Digital 07-12-2010 15:18

Two origins, get origin of points in line
 
Well, I have a line, each point has different XYZ and line total width may varray.

[A]----------------------[B]

And I want to generate points of predefined distance accros the line:

[A]-.-.-.-.-.-.-.-.-.-.-.-.-[B]

Having origins for each one of them.

It's more a math problem and I really suck at maths :mrgreen:

joaquimandrade 07-12-2010 16:12

Re: Two origins, get origin of points in line
 
Let's see if I can say it right:

Subtract B by A and you will get the vector that goes from A to B.
Normalize it so it becomes with length 1.
Than multiply it by the length between points (as you defined it)

PHP Code:

xs_vec_sub(b,a,c)
xs_vec_normalize(c,c)
xs_vec_mul_scalar(c,lengthBetweenPoints,c

Now C is a vector with the direction from A to B and with length as you defined between points.

So, now to get the point N from A you will do:

PHP Code:


new 3
new Float:nOrigin[3]

xs_vec_mul_scalar(c,n,nOrigin)
xs_vec_add(nOrigin,a,nOrigin

Edit: if you want all the points in between you just have to do in the last step:

PHP Code:


for(new i=0;i<=lastPoint;i++)
{
  
// use "a" here

  
xs_vec_add(a,c,a)



Hunter-Digital 07-12-2010 17:00

Re: Two origins, get origin of points in line
 
Hmm... thanks, I think I got the 'trick'.

PHP Code:

    new iOrigin[3]
    new 
Float:fA[3]
    new 
Float:fB[3]

    
entity_get_vector(idEV_VEC_originfA)
    
get_user_origin(idiOrigin3)
    
IVecFVec(iOriginfB)

    new 
iNum floatround(get_distance_f(fAfB) / 50.0floatround_floor)

    
xs_vec_sub(fBfAfB)
    
xs_vec_normalize(fBfB)
    
xs_vec_mul_scalar(fB50.0fB)

    for(new 
iNumi++)
    {
        
xs_vec_add(fAfBfA)

        
/* sprite @ fA */
    


And by mistake I made a nice railgun effect :lol:

[IMG]http://img295.**************/img295/8889/dedust20057.th.jpg[/IMG]

It fades out really nicely, used TE_GLOWSPRITE and ledglow.spr :mrgreen:


All times are GMT -4. The time now is 07:09.

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