Raised This Month: $ Target: $400
 0% 

Sprite math [advanced users]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 14:19.


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