AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Sprite math [advanced users] (https://forums.alliedmods.net/showthread.php?t=171535)

tuty 11-07-2011 09:10

Sprite math [advanced users]
 
Hi, i want to know how the heck i calculate to make a sprite floating and spinning around the player body in same time :) anyone can help me?

ConnorMcLeod 11-07-2011 10:08

Re: Sprite math [advanced users]
 
I think i've already seen something like that, like a green line drawing a cylinder around a player, may be in WC3FT

nikhilgupta345 11-07-2011 10:23

Re: Sprite math [advanced users]
 
Quote:

Originally Posted by ConnorMcLeod (Post 1591874)
I think i've already seen something like that, like a green line drawing a cylinder around a player, may be in WC3FT

Yes it's in WC3FT. Check in nightelf.inl for the "Entangle" spell. (maybe elf.inl or night_elf.inl, not sure)

Emp` 11-07-2011 12:41

Re: Sprite math [advanced users]
 
Code:

public NE_ULT_EntangleEffect( id, iSeconds )
{

        // Get the user's origin
        new vOrigin[3];
        get_user_origin( id, vOrigin );
       
        // Play the entangle sound
        emit_sound( id, CHAN_STATIC, g_szSounds[SOUND_ENTANGLING], 1.0, ATTN_NORM, 0, PITCH_NORM );

        new iStart[3], iEnd[3], iHeight;
        new iRadius        = 20, iCounter = 0;
        new x1, y1, x2, y2;

        // Some sweet crap that I don't understand courtesy of SpaceDude - draws the "cylinder" around the player
        while ( iCounter <= 7 )
        {
                if ( iCounter == 0 || iCounter == 8 )
                        x1 = -iRadius;
                else if ( iCounter == 1 || iCounter == 7 )
                        x1 = -iRadius * 100/141;
                else if ( iCounter == 2 || iCounter == 6 )
                        x1 = 0;
                else if ( iCounter == 3 || iCounter == 5 )
                        x1 = iRadius*100/141
                else if ( iCounter == 4 )
                        x1 = iRadius

                if ( iCounter <= 4 )
                        y1 = sqroot( iRadius*iRadius-x1*x1 );
                else
                        y1 = -sqroot( iRadius*iRadius-x1*x1 );

                ++iCounter;

                if ( iCounter == 0 || iCounter == 8 )
                        x2 = -iRadius;
                else if ( iCounter == 1 || iCounter==7 )
                        x2 = -iRadius*100/141;
                else if ( iCounter == 2 || iCounter==6 )
                        x2 = 0;
                else if ( iCounter == 3 || iCounter==5 )
                        x2 = iRadius*100/141;
                else if ( iCounter == 4 )
                        x2 = iRadius;
               
                if ( iCounter <= 4 )
                        y2 = sqroot( iRadius*iRadius-x2*x2 );
                else
                        y2 = -sqroot( iRadius*iRadius-x2*x2 );

                iHeight = 16 + 2 * iCounter;

                while ( iHeight > -40 )
                {
                       
                        iStart[0]        = vOrigin[0] + x1;
                        iStart[1]        = vOrigin[1] + y1;
                        iStart[2]        = vOrigin[2] + iHeight;
                        iEnd[0]                = vOrigin[0] + x2;
                        iEnd[1]                = vOrigin[1] + y2;
                        iEnd[2]                = vOrigin[2] + iHeight + 2;
                       
                        Create_TE_BEAMPOINTS( iStart, iEnd, g_iSprites[SPR_BEAM], 0, 0, ( iSeconds * 10 ), 10, 5, 10, 108, 23, 255, 0 );

                        iHeight -= 16;
                }
        }

        return;
}

Just leaving this here so people do not have to go download the entire WC3FT package.

xPaw 11-07-2011 15:43

Re: Sprite math [advanced users]
 
while ( iCounter <= 7 )

iCounter == 8

That's genius.

Sylwester 11-07-2011 16:03

Re: Sprite math [advanced users]
 
That code looks horrible.
This is how you do rotation:
PHP Code:

#include <amxmodx>

new Float:g_rotation_matrix[2][2]
new 
Float:g_vec[3] = {70.00.00.0}


public 
plugin_init() {
    
rotation_init(10.0)
    
set_task(0.1"rotate"4373__"b")
}


public 
rotation_init(Float:degrees_step){
    
g_rotation_matrix[0][0] = g_rotation_matrix[1][1] = floatcos(degrees_stepdegrees
    
g_rotation_matrix[1][0] = -(g_rotation_matrix[0][1] = -floatsin(degrees_stepdegrees))
}


public 
rotate(){
    new 
Float:xFloat:y
    x 
g_vec[0]*g_rotation_matrix[0][0] + g_vec[1]*g_rotation_matrix[0][1]
    
g_vec[0]*g_rotation_matrix[1][0] + g_vec[1]*g_rotation_matrix[1][1]
    
    
display()
    
    
g_vec[0] = x
    g_vec
[1] = y
}


public 
display(){
    static 
players[32], pnumorigin[3]
    
get_players(playerspnum)
    for(new 
ii<pnumi++){
        
get_user_origin(players[i], origin)
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
        
write_byte(TE_SPARKS)
        
write_coordfloatround(g_vec[0] + origin[0]) )
        
write_coordfloatround(g_vec[1] + origin[1]) )
        
write_coordfloatround(g_vec[2] + origin[2]) )
        
message_end()
    }



tuty 11-08-2011 03:37

Re: Sprite math [advanced users]
 
thanks guys :):3

sake 11-08-2011 16:03

Re: Sprite math [advanced users]
 
@Sylwester:

PHP Code:

new Float:g_rotation_matrix[2][2]
new 
Float:g_vec[3] = {70.00.00.0}
new 
Float:g_deg 0;


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR);
    
set_task(0.0001"rotate"4373__"b")
}

public 
rotate(){
    new 
Float:xFloat:y
    x 
70*floatcos(g_degdegrees);
    
70*floatsin(g_degdegrees);
    
g_deg += 10;
    
    
display()
    
    
g_vec[0] = x
    g_vec
[1] = y
}


public 
display(){
    static 
players[32], pnumorigin[3]
    
get_players(playerspnum)
    for(new 
ii<pnumi++){
        
get_user_origin(players[i], origin)
        
message_begin(MSG_BROADCASTSVC_TEMPENTITY)
        
write_byte(TE_SPARKS)
        
write_coordfloatround(g_vec[0] + origin[0]) )
        
write_coordfloatround(g_vec[1] + origin[1]) )
        
write_coordfloatround(g_vec[2] + origin[2]) )
        
message_end()
    }


I didn't really understand your example. Could you explain how your method works? I tried to do my own version (and succeeded) by using sin and cos in every cycle but that is quite unefficient. So I would be pleased to have you explain your version. :)

EDIT:

Does it have to do with this here? http://en.wikipedia.org/wiki/Rotation_matrix

EDIT2:

Oh, there is a formula for that. I'd like to see the prove.

Sylwester 11-08-2011 17:41

Re: Sprite math [advanced users]
 
What you are doing is rotating starting vector by 10 degrees, then rotating starting vector by 20 degrees and so on...
What my code does is rotate starting vector by 10 degrees, then rotate vector returned by previous operation by another 10 degrees and so on...

The general formula for rotation is:
new_x = x*cos(angle) - y*sin(angle)
new_y = x*sin(angle) + y*cos(angle)

and as you can see the formula you used is simply a special case of general formula:
PHP Code:

    x 70*floatcos(g_degdegrees) - 0*floatsin(g_degdegrees);
    
70*floatsin(g_degdegrees) + 0*floatcos(g_degdegrees); 

Since I use the same angle in every operation, I could cache values of sin and cos and I stored them in a matrix.
2D transformations are usually done using 3x3 matrix, but since we need only rotation, then 2x2 was enough for that.


All times are GMT -4. The time now is 14:19.

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