| 08-31-2008, 08:26 PM | #1 |
Ok first of all the function I originally made using GUI is in the first link, and the version put into my knockback system in JASS, is the second one. If you wish to help, download and test the first map to see that the function does in fact work properly without bugs. the second one does not. then look at this, and tell me what's different and why it might cause the JASS version to NOT work properly in some instances. GUI version (ie i setup everything in .GUI but converted to JASS since the algorithm was huge): JASS:function Trig_Test_register_speed_Actions takes nothing returns nothing set udg_Ax1 = ( ( ( udg_B1 * CosBJ(( udg_aB - udg_aalpha )) ) + ( ( ( udg_MA / udg_MB ) * ( udg_A1 * CosBJ(( udg_aA - udg_aalpha )) ) ) - ( ( ( udg_A1 * CosBJ(( udg_aA - udg_aalpha )) ) - ( udg_B1 * CosBJ(( udg_aB - udg_aalpha )) ) ) * udg_eT ) ) ) / ( 1 + ( udg_MA / udg_MB ) ) ) set udg_Ay1 = ( udg_A1 * SinBJ(( udg_aA - udg_aalpha )) ) set udg_Bx1 = ( ( ( udg_A1 * CosBJ(( udg_aA - udg_aalpha )) ) + ( ( ( udg_MB / udg_MA ) * ( udg_B1 * CosBJ(( udg_aB - udg_aalpha )) ) ) + ( ( ( udg_A1 * CosBJ(( udg_aA - udg_aalpha )) ) - ( udg_B1 * CosBJ(( udg_aB - udg_aalpha )) ) ) * udg_eT ) ) ) / ( 1 + ( udg_MB / udg_MA ) ) ) set udg_By1 = ( udg_B1 * SinBJ(( udg_aB - udg_aalpha )) ) set udg_Ax2 = ((udg_Ax1/RAbsBJ(udg_Ax1)) * ( SquareRoot(( Pow(udg_Ax1, 2.00) + Pow(udg_Ay1, 2.00) )) * CosBJ(AtanBJ(( udg_Ay1 / udg_Ax1 )) + udg_aalpha ) )) set udg_Ay2 = ((udg_Ax1/RAbsBJ(udg_Ax1)) * ( SquareRoot(( Pow(udg_Ax1, 2.00) + Pow(udg_Ay1, 2.00) )) * SinBJ(AtanBJ(( udg_Ay1 / udg_Ax1 )) + udg_aalpha ) )) set udg_Bx2 = ((udg_Bx1/RAbsBJ(udg_Bx1)) * ( SquareRoot(( Pow(udg_Bx1, 2.00) + Pow(udg_By1, 2.00) )) * CosBJ(AtanBJ(( udg_By1 / udg_Bx1 )) + udg_aalpha ) )) set udg_By2 = ((udg_Bx1/RAbsBJ(udg_Bx1)) * ( SquareRoot(( Pow(udg_Bx1, 2.00) + Pow(udg_By1, 2.00) )) * SinBJ(AtanBJ(( udg_By1 / udg_Bx1 )) + udg_aalpha ) )) set udg_A2 = SquareRoot(( Pow(udg_Ax2, 2.00) + Pow(udg_Ay2, 2.00) )) set udg_B2 = SquareRoot(( Pow(udg_Bx2, 2.00) + Pow(udg_By2, 2.00) )) set udg_aA = Atan2BJ(udg_Ay2, udg_Ax2) set udg_aB = Atan2BJ(udg_By2, udg_Bx2) set udg_VA = udg_A2 set udg_VB = udg_B2 endfunction here's the JASS version: JASS:function GetNewVel takes real angleBtwn, real VelA, real VelB, real angleA, real angleB, real MassA, real MassB, real e returns nothing local real VelAx1 = ( ( ( VelB * Cos(( angleB - angleBtwn )) ) + ( ( ( MassA / MassB ) * ( VelA * Cos(( angleA - angleBtwn )) ) ) - ( ( ( VelA * Cos(( angleA - angleBtwn )) ) - ( VelB * Cos(( angleB - angleBtwn )) ) ) * e ) ) ) / ( 1 + ( MassA / MassB ) ) ) local real VelAy1 = ( VelA * Sin(( angleA - angleBtwn )) ) // ^ above sign originally '-' local real VelBx1 = ( ( ( VelA * Cos(( angleA - angleBtwn )) ) + ( ( ( MassB / MassA ) * ( VelB * Cos(( angleB - angleBtwn )) ) ) + ( ( ( VelA * Cos(( angleA - angleBtwn )) ) - ( VelB * Cos(( angleB - angleBtwn )) ) ) * e ) ) ) / ( 1 + ( MassB / MassA ) ) ) local real VelBy1 = ( VelB * Sin(( angleB - angleBtwn )) ) local real VelAx2 = ((VelAx1/RAbsBJ(VelAx1)) * ( SquareRoot(( Pow(VelAx1, 2.00) + Pow(VelAy1, 2.00) )) * Cos(Atan(( VelAy1 / VelAx1 )) + angleBtwn ) )) local real VelAy2 = ((VelAx1/RAbsBJ(VelAx1)) * ( SquareRoot(( Pow(VelAx1, 2.00) + Pow(VelAy1, 2.00) )) * Sin(Atan(( VelAy1 / VelAx1 )) + angleBtwn ) )) local real VelBx2 = ((VelBx1/RAbsBJ(VelBx1)) * ( SquareRoot(( Pow(VelBx1, 2.00) + Pow(VelBy1, 2.00) )) * Cos(Atan(( VelBy1 / VelBx1 )) + angleBtwn ) )) local real VelBy2 = ((VelBx1/RAbsBJ(VelBx1)) * ( SquareRoot(( Pow(VelBx1, 2.00) + Pow(VelBy1, 2.00) )) * Sin(Atan(( VelBy1 / VelBx1 )) + angleBtwn ) )) set VelA2 = SquareRoot(( Pow(VelAx2, 2.00) + Pow(VelAy2, 2.00) )) set VelB2 = SquareRoot(( Pow(VelBx2, 2.00) + Pow(VelBy2, 2.00) )) set angleA2 = Atan2(VelAy2, VelAx2) set angleB2 = Atan2(VelBy2, VelBx2) endfunction the global variables udg_A1 and udg_B1 are the current speed values of the units on the test map. the other ones were also replaced so everything that isn't global or local in the jass is provided, whereas in the GUI version all the values are global. the only important information is the 2 final speeds and angles so everything else doesn't matter after it is used in the calculation. Anyways, like previously stated, the one I did in GUI works fine, so it proves the equations work properly, but for some reason, and I can't figure it out, they don't work with the JASS version, and i get weird bounces (check the second map to see what i mean). There are some other bugs too, but I'm trying to first get units bouncing to work properly... so if anyone can help me figure out WHY the equations don't work with the JASS i'd greatly appreciate it. Just for the record, I'm not coming here because I'm lazy and want someone else to check ym syntax or all that. I've looked over the code for over 5 hours and tried and test and done everything and to no avail. I honestly don;t know what's wrong and I'm new to JASS so there's possibility that I'm doing somethign wrong that doesn't cause compile errors, yet makes my code not act as it should. |
| 09-01-2008, 02:14 AM | #2 |
Cos()/Sin() requires its argument to be in radians, while CosBJ()/SinBJ() requires the angle to be in degrees. Either revert back to CosBJ()/SinBJ() or multiply your angle by bj_DEGTORAD |
| 09-01-2008, 03:24 AM | #3 |
[edit] found the error, apparently ACos(Cos(angle)) != angle |
| 09-01-2008, 08:02 AM | #4 |
Uhh... ACos(Cos(angle)) should equal angle, unless I fail at math. |
| 09-01-2008, 12:58 PM | #5 |
It returns an angle between 0 and Pi radians. |
| 09-01-2008, 05:00 PM | #6 | |
Quote:
no you don't fail at maths, and neither do I, which is why I had such a problem finding this. the weird thing is when anything over pi and less than 0, even if you set it to a positive number, will return a negative value for the angle if you try to retrieve the data. It sort of works in my favor for some things and not for others. But yeah, by doing this, I had to store the actual angle rather than just take a component that I stored and use ACos(component) to get the real angle. That would also explain why it worked fine on anything between 0 and pi but nothing else. Now it works on almost every occasion, though sometimes I get a weird bounce back... |
| 09-01-2008, 08:45 PM | #7 |
learn math |
| 09-01-2008, 09:08 PM | #8 |
use vec wtf ^_^ |
| 09-01-2008, 10:40 PM | #9 |
"learn math" is a fairly general, and awfully useless comment, dontcha think? I know the math, and my second post was sarcastic. BTW I wonder how many of you actually looked at the code... |
| 09-02-2008, 03:44 AM | #10 |
- Clean up those brackets, you have a ton left over from the conversion that aren't necessary - Replace Pow(udg_Ax1, 2.00) with udg_Ax1*udg_Ax1, it's faster and generally easier to read - Atan(y/x) is completely dominated by Atan2(y, x). Atan2 always gives back the angle from 0,0 to x,y. Atan(y/x) does not. - You can replace x/RAbsBJ(x) with RSignBJ(x). - Use locals to store values you're going to reuse. You're recomputing Atans and SquareRoots all over the place. This will make the code much faster and, more importantly, actually readable. It breaks the computation down into little understandable steps. |
| 09-02-2008, 08:31 AM | #11 |
Thx for the extra stuff, that will help me reduce the code a bit. The main reason why it might seem really bad is that I started out with a huge equation, and was bracket happy to make sure I didn't leave things out, or that something wasn't calculated the right way. I also made this using GUI and then just replaced variables. Some stuff has obviously been modified but.... shit well look at that. that little bit about ATan2 trumping atan is not always true, since THAT is the reason why my system screwed up; i changed from atan to atan2 and shit hit the fan. how about that. well thank you. had you not brought that up i probably would not have found my error. still, now that my system works 100% properly, I can buffer all the bugs out and just make it overall better quality than what I've just hacked together. Regarless, the system works now, thanks to all for the help. |
