set_polar() - Script Documentation

Documentation, usage tips and configuration guides for Titan Two scripts and bytecodes published by the community users.

Re: set_polar() - Script Documentation

Postby Convivium » Fri Mar 13, 2020 11:17 pm

FYI, you don't have to convert to from degrees to radian to use sin and cos.

I did a lot research on the XB1 analog sticks back when I was modifying Bonefisher's Modern Warfare MODzPACK v1.12 in November.

I found that regardless if you convert using deg2rad or not, the output is the same.

The main reason you do not have to convert from degrees to radian is because sin and cos are a perfect Taylor Series and thus converge. This simply means you can evaluate sin and cos at all real numbers. Conversely, tangent diverges and can not be evaluated at all real numbers. If you wanted to use non-real numbers or complex numbers you would need to convert them
and express them as polar coordinates.

Here is a portion of the modified script I came up with to use with Aim Assist on the XIM Apex with MODzPACK v1.12.

To change the diameter, alter the Aim Assist Speed value in the config.

To change the rotation direction, clockwise to counter clockwise, switch sin and cos in the combo.

Of course, either code will produce the same output but this version will save a little CPU Load since no conversion is needed.

Both output as fix32.

PS - put in a slot to test

Code: Select all
 
 
#pragma METAINFO("Aim Assist MW", 1, 0, "Convivium")
/*Credit bonefisher for the original Modern Warfare MODzPACK*/
 
/* *****************************************************************************
<cfgdesc>
[MODERN WARFARE MODzPACK]
 
[Stick Noise Remover]
group          = true
shortdesc      = <font color="brown">STICK NOISE:</font> <font color="green"> Set to the resting dead zone values for your right stick.</font>
byteoffset     = 18
bitsize        = 32
control        = spinboxf
default     = 30
minimum        = 0
maximum        = 1000
step           = 10
decimals       = 1
 
[ASSIST TRACKING SETTINGS:]
color       = #008000
collapsible = 2
 
 
[AIM ASSIST SETTINGS:]
group          = true
shortdesc      = <font color="green">Firing tracking option.</font>
byteoffset     = 36
bitsize        = 1
bitoffset      = 7
control        = checkbox
default     = 1
item           = Aim Assist
 
[Aim Assist Radius]
group          = true
shortdesc      = <font color="brown">Aim Assist Radius:</font> <font color="green"> Configure the length time period, in milli-seconds, of which the ADS(Scope) button activates the aim-assist.
byteoffset     = 37
bitsize        = 16
control        = spinbox
default    = 16
minimum        = 0
maximum        = 100
step           = 5
 
</cfgdesc>
***************************************************************************** */

#include "ColorLED.gph"
 
bool bUseAimAssist;
 
int AimAssistSpeed;
 
fix32 StickNoise;
 
init {
  pmem_load();   
  pmem_read(18, &StickNoise);
 
  bUseAimAssist = (pmem_read(36) >> 7) & 0b1;
  pmem_read(37, &AimAssistSpeed);
 
  ColorLED(CB);   
}
 
main {
 
    //STICK NOISE
    if (abs(get_actual(STICK_1_X)) < StickNoise) set_val(STICK_1_X, 0.0);
    if (abs(get_actual(STICK_1_Y)) < StickNoise) set_val(STICK_1_Y, 0.0);
    if (abs(get_actual(STICK_2_X)) < StickNoise) set_val(STICK_2_X, 0.0);
    if (abs(get_actual(STICK_2_Y)) < StickNoise) set_val(STICK_2_Y, 0.0);       
 
//ADS Hair Trigger
    if (get_val(BUTTON_8) != 0.0) {set_val(BUTTON_8, 100);}
    //if (get_val(BUTTON_5) > 10.0) {set_val(BUTTON_5, 100);}
 
    if(bUseAimAssist == 1)
        {
        if(get_val(BUTTON_8)&& !get_actual(BUTTON_5))
            {
            combo_run(ARA);
            }
        if(is_active(STICK_1_X))
            {
            combo_stop(ARA);
            }
        if(is_active(STICK_1_Y))
            {
            combo_stop(ARA);
            }
        }
 
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//COMBOS
////////////////////////////////////////////////////////////////////////////////////////////////////
combo ARA
    {
    set_val(STICK_1_X, cos((fix32)system_time()/(fix32)AimAssistSpeed)*(fix32)AimAssistSpeed);
    set_val(STICK_1_Y, sin((fix32)system_time()/(fix32)AimAssistSpeed)*(fix32)AimAssistSpeed);
    }
 
 
User avatar
Convivium
Master Sergeant
Master Sergeant
 
Posts: 26
Joined: Wed Mar 27, 2019 2:45 am
Location: Clemson, SC

Re: set_polar() - Script Documentation

Postby DontAtMe » Sat Mar 14, 2020 12:46 pm

Convivium wrote:FYI, you don't have to convert to from degrees to radian to use sin and cos.
Actually you do. If you are using degrees, you must convert to radians.

Since I decided to work with degrees in this script, the conversion is absolutely necessary.
As cos() and sin() uses radians not degrees.

The reason for using degrees is because it is a lot easier to visualize and remember angles in degrees oppose to radians.

To avoid use of the the deg2rad() completely. The set_polar() function can easily be written to use radians instead.
Code: Select all
void set_polar(uint8 x, uint8 y, fix32 angle, fix32 radius){
  angle = mod(angle + 6.28319, 6.28319);
  fix32 x_out, y_out;
  if(angle > 0.785522 && angle < 3.92761) {
    x_out = -sin(angle - 1.57104);
    y_out = -cos(angle - 4.71313);
  }
  else {
    x_out = cos(angle);
    y_out = sin(angle);
  }
  set_val(x, clamp(x_out * radius, -100.00, 100.00));
  set_val(y, clamp(y_out * radius, -100.00, 100.00));
  return;
}


I found that regardless if you convert using deg2rad or not, the output is the same.

I can assure you the output is definitely not the same. :wink:
Code: Select all
main {
  set_val(STICK_1_Y, sin(45.00) * 100.00);
  set_val(STICK_1_X, cos(45.00) * 100.00);
 
  set_val(STICK_2_Y, sin(deg2rad(45.00)) * 100.00);
  set_val(STICK_2_X, cos(deg2rad(45.00)) * 100.00);
}


...
Of course, either code will produce the same output but this version will save a little CPU Load since no conversion is needed.

Thank you for sharing.
You should post this in the online resources, :smile0517:

However, your code won't produce the same output as set_polar().
Your script only appears to rotate the stick, whereas set_polar() has many different applications, not just "aim assist".

Such as handling weapon recoil, dealing with radial menus. To even more complex tasks, such as executing unique stick maneuvers in certain games (Skate 3, is a good for example for this).
That's just to name a few, but really it can be used for any task that manipulates the sticks.
User avatar
DontAtMe
Captain
Captain
 
Posts: 502
Joined: Tue Oct 02, 2018 4:49 am

Re: set_polar() - Script Documentation

Postby Convivium » Sat Mar 14, 2020 2:31 pm

Never played Skate 3,

Does the game covert the input from Cartesian to Polar then back again for the output?

I usually don't post in the online resources only because it saves me from having to type out instructions.Plus, although I have a lot of other games, I mainly play PUBG. It's hard to beat PUBG's gun play mechanics even though BlueHole, and now Krafton have pretty much ruined everything else.

Agree that you absolutely need to convert if your goal is to use magnitude and a degree instead of a vector from (0,0) to (x1.y1).
User avatar
Convivium
Master Sergeant
Master Sergeant
 
Posts: 26
Joined: Wed Mar 27, 2019 2:45 am
Location: Clemson, SC

Re: set_polar() - Script Documentation

Postby antithesis » Tue Jun 02, 2020 1:59 pm

I'm trying to figure out a simple script to help kb users manage wheels more easily than clunky XIM Turn Assist, mouse aim or 8-directional WASD, which may skip past items.

I have yet to run the set_polar script, but could this be used to rotate through a wheel menu while holding a button? e.g Horizon Zero Dawn uses L1 to open a weapon wheel. Hold L1 to rotate around the wheel. Release L1 to select / stop.
Official Australian retailer for Titan One, Titan Two and XIM APEX at Mod Squad
User avatar
antithesis
Colonel
Colonel
 
Posts: 1912
Joined: Sat May 28, 2016 10:45 pm

Re: set_polar() - Script Documentation

Postby GamingScene » Tue Oct 06, 2020 8:44 pm

antithesis wrote:I'm trying to figure out a simple script to help kb users manage wheels more easily than clunky XIM Turn Assist, mouse aim or 8-directional WASD, which may skip past items.

I have yet to run the set_polar script, but could this be used to rotate through a wheel menu while holding a button? e.g Horizon Zero Dawn uses L1 to open a weapon wheel. Hold L1 to rotate around the wheel. Release L1 to select / stop.

Had any look?
User avatar
GamingScene
Sergeant Major
Sergeant Major
 
Posts: 104
Joined: Sat May 26, 2018 6:17 pm

Re: set_polar() - Script Documentation

Postby osori » Sun Dec 27, 2020 7:30 am

Here is a get_polar function as well. (Gets the degrees from your current X,Y, values)

However, since I was working on nba2k, I used clockwise degrees : 0 is right, 90 is down, 180 is left and 270 is up.


Code: Select all
 
#0 is right, 90 is down, 180 is left and 270 is up
 
fix32 get_polar(int8 X, int8 Y) {
    if (Y == 0) {
            if(X < 0) {
                return 180.00;
            }
            else return 0.00;
    }
    fix32 int_temp_ang = rad2deg(atan((fix32) Y / (fix32) X));
    if (Y > 0) {
        if (X > 0) return int_temp_ang;
        return 180.00 + int_temp_ang;
    }
    if (X > 0) return 360.00 + int_temp_ang;
    return 180.00 + int_temp_ang;   
 
}
 
void set_polar(uint8 X, uint8 Y, fix32 ANGLE, fix32 RADIUS){
 
  fix32 int_angle = rad2deg(mod(deg2rad(ANGLE) + PI * 2f, PI * 2f));
 
  fix32 x_Out, y_Out;
 
  if(int_angle > 45.00 && int_angle < 225.00) {
    x_Out = -sin(deg2rad(int_angle) - deg2rad(90.00));
    y_Out = -cos(deg2rad(int_angle) - deg2rad(270.0));
  }
  else {
    x_Out = cos(deg2rad(int_angle));
    y_Out = sin(deg2rad(int_angle));
  }
 
  set_val(X, clamp(x_Out * RADIUS, -100.00, 100.00));
  set_val(Y, clamp(y_Out * RADIUS, -100.00, 100.00));
}
 
 
 
Last edited by osori on Tue Jan 19, 2021 5:31 am, edited 1 time in total.
User avatar
osori
Corporal
Corporal
 
Posts: 4
Joined: Sun Dec 06, 2020 4:51 am

Re: set_polar() - Script Documentation

Postby Mad » Sun Dec 27, 2020 7:53 am

osori wrote:Here is a get_polar function as well.

Awesome, thanks for sharing with us. :joia: :joia:
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord (2K / FPS)
Mad
Major General
Major General
 
Posts: 4533
Joined: Wed May 22, 2019 5:39 am

Re: set_polar() - Script Documentation

Postby Beryl » Thu Sep 30, 2021 4:37 pm

Im new to this how exactly does this polar work? Im trying to understand it but struggling. Does this change the direction of mouse movements? Iv always wondered if there was a way block out un wanted movements for better target tracking? Such as up down left right and diagonal and just block the in betweens movements?
User avatar
Beryl
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 198
Joined: Fri Nov 27, 2020 7:47 pm

Re: set_polar() - Script Documentation can you add it an ads

Postby Beryl » Fri Oct 08, 2021 3:53 pm

bonefisher wrote:
Code: Select all
 
#pragma METAINFO("polar anti recoil", 1, 0, "bonefisher")
 
#define POLAR_RS STICK_1_X, STICK_1_Y
#define POLAR_LS STICK_2_X, STICK_2_Y
 
fix32 anti_recoil = 40.0//--Anti_Recoil strength
fix32 polar_angle = 90.0//--direction of anti_recoil
 
fix32 StickNoise = 8.0;
main {
    if (abs(get_actual(STICK_1_X)) < StickNoise) set_val(STICK_1_X, 0.0);
      if (abs(get_actual(STICK_1_Y)) < StickNoise) set_val(STICK_1_Y, 0.0);
 
    if(get_val(BUTTON_5)) {
        set_polar(POLAR_RS, polar_angle, anti_recoil + .01);
    }
}
 
void set_polar(uint8 X, uint8 Y, fix32 ANGLE, fix32 RADIUS){
 
  fix32 angle = rad2deg(mod(deg2rad(ANGLE) + PI * 2f, PI * 2f));
 
  fix32 x_Out, y_Out;
 
  if(angle > 45.10 && angle < 225.90) {
    x_Out = -sin(deg2rad(angle) - deg2rad(90.02));
    y_Out = -cos(deg2rad(angle) - deg2rad(270.00));
  }
  else {
    x_Out = cos(deg2rad(angle));
    y_Out = sin(deg2rad(angle));
  }
 
  set_val_offset(X, clamp(x_Out * RADIUS, -100.00, 100.00));
  set_val_offset(Y, clamp(y_Out * RADIUS, -100.00, 100.00));
}
void set_val_offset(uint8 axis, fix32 offset_val)
{
    set_val(axis, clamp(offset_val * (100.0 - abs(get_val(axis))) / 100.0 + get_val(axis), -100.0, 100.0));
    return;
}
 

Here!! :smile0517:
90 is straight down 95 is down left 85 is down right example.....


Hey been using this for PUBG and although i dont totally understand it its works, any chance you could add the anti recoil to start ONLY when i ads? left trigger (button 8) Thanks in advance
User avatar
Beryl
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 198
Joined: Fri Nov 27, 2020 7:47 pm

Re: set_polar() - Script Documentation

Postby Herpityderpity » Sat Oct 09, 2021 8:45 pm

has this been working even better than the code that Alan's antirecoil script works on for pubg?
User avatar
Herpityderpity
Staff Sergeant
Staff Sergeant
 
Posts: 15
Joined: Sun May 30, 2021 9:09 pm

Previous

Return to User's Script Documentation

Who is online

Users browsing this forum: No registered users and 96 guests