Raised This Month: $12 Target: $400
 3% 

Sprite math [advanced users]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 11-07-2011 , 09:10   Sprite math [advanced users]
Reply With Quote #1

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?
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-07-2011 , 10:08   Re: Sprite math [advanced users]
Reply With Quote #2

I think i've already seen something like that, like a green line drawing a cylinder around a player, may be in WC3FT
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 11-07-2011 , 10:23   Re: Sprite math [advanced users]
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
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)
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 11-07-2011 at 10:24.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-07-2011 , 12:41   Re: Sprite math [advanced users]
Reply With Quote #4

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.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 11-07-2011 , 15:43   Re: Sprite math [advanced users]
Reply With Quote #5

while ( iCounter <= 7 )

iCounter == 8

That's genius.
__________________
xPaw is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-07-2011 , 16:03   Re: Sprite math [advanced users]
Reply With Quote #6

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()
    }

__________________
Impossible is Nothing
Sylwester is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 11-08-2011 , 03:37   Re: Sprite math [advanced users]
Reply With Quote #7

thanks guys
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
sake
Senior Member
Join Date: Jul 2011
Old 11-08-2011 , 16:03   Re: Sprite math [advanced users]
Reply With Quote #8

@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.
__________________

Last edited by sake; 11-08-2011 at 16:07.
sake is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 11-08-2011 , 17:41   Re: Sprite math [advanced users]
Reply With Quote #9

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.
__________________
Impossible is Nothing
Sylwester is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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