Creating a sensitivity curve for an analogue stick?

GPC2 script programming for Titan Two. Code examples, questions, requests.

Re: Creating a sensitivity curve for an analogue stick?

Postby teddy18 » Tue Nov 10, 2020 12:57 pm

Good question
I think i need both


Second question
Is it possible to set input Translater not mouse to right stick
I want to use gyro Nintendo Joy con
With Deadzone and curve
User avatar
teddy18
Lieutenant
Lieutenant
 
Posts: 346
Joined: Sun Jul 19, 2015 4:18 pm

Re: Creating a sensitivity curve for an analogue stick?

Postby J2Kbr » Tue Nov 10, 2020 9:18 pm

teddy18 wrote:Second question Is it possible to set input Translater not mouse to right stick
I want to use gyro Nintendo Joy con With Deadzone and curve

For this purpose a GPC script is needed. Here is a script I coded while ago for motion aiming:
Code: Select all
#pragma METAINFO("Motion Aiming", 1, 0, "J2Kbr")
 
#define SENSITIVITY_X   5.0
#define SENSITIVITY_Y   5.0
 
#define DEADZONE_X      20.0
#define DEADZONE_Y      20.0
#define DEADZONE_D      1.0
 
main {
    if(get_val(BUTTON_8)) {
        static fix32 offset_x;
        static fix32 offset_y;
        if(event_active(BUTTON_8)) {
            offset_x = get_val(ACCEL_1_X);
            offset_y = get_val(ACCEL_1_Y);
        }
        if(abs(get_val(STICK_1_X)) <= DEADZONE_X && abs(get_val(STICK_1_Y)) <= DEADZONE_Y) {
            motion_aiming(offset_x, offset_y);
        }
    }
}
 
void motion_aiming(fix32 offset_x, fix32 offset_y) {
    static fix32 accel_x, accel_y;
    static fix32 stick_x, stick_y;
    if(accel_x != get_actual(ACCEL_1_X) || accel_y != get_actual(ACCEL_1_Y)) {
        accel_x = get_actual(ACCEL_1_X);
        accel_y = get_actual(ACCEL_1_Y);
        stick_x = (accel_x - offset_x) * SENSITIVITY_X;
        stick_y = (accel_y - offset_y) * SENSITIVITY_Y;
 
        fix32 signal_x = (stick_x < 0.0) ? (stick_x = inv(stick_x), -1.0) : (stick_x > 0.0) ? 1.0 : 0.0;
        fix32 signal_y = (stick_y < 0.0) ? (stick_y = inv(stick_y), -1.0) : (stick_y > 0.0) ? 1.0 : 0.0;
        fix32 angle = atan2(stick_y, stick_x);
 
        stick_x = clamp(((DEADZONE_X * pow(cos(angle), DEADZONE_D)) + stick_x) * signal_x, -100.0, 100.0);
        stick_y = clamp(((DEADZONE_Y * pow(sin(angle), DEADZONE_D)) + stick_y) * signal_y, -100.0, 100.0);
    }
    set_val(STICK_1_X, stick_x);
    set_val(STICK_1_Y, stick_y);
    return;
}
 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Creating a sensitivity curve for an analogue stick?

Postby fdg0d » Fri Dec 25, 2020 7:48 am

is there a guide on how to convert a curve to the gpc version? id like to convert this

GIVMXYC:001820262C3135383B3E404346494B4E5052555759
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Creating a sensitivity curve for an analogue stick?

Postby Mad » Fri Dec 25, 2020 8:07 am

fdg0d wrote:is there a guide on how to convert a curve to the gpc version?

Alt + click copy.
to gpc.png
to gpc.png (10.91 KiB) Viewed 875 times
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am

Re: Creating a sensitivity curve for an analogue stick?

Postby fdg0d » Fri Dec 25, 2020 9:06 am

i understand that but how do i make it into something like this
Code: Select all
main {
    set_val(STICK_1_X, stick_response(STICK_1_X));
    set_val(STICK_1_Y, stick_response(STICK_1_Y));
}
 
fix32 stick_response(uint8 idx) {
    const uint8 base[] = {
        0x00, 0x05, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x23, 0x28, 0x2D, 0x32, 0x37,
        0x3C, 0x41, 0x46, 0x4B, 0x50, 0x55, 0x5A, 0x5F, 0x64
    };
    const uint8 cc[] = {
        0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x24, 0x27, 0x2A,
        0x2D, 0x2F, 0x32, 0x35, 0x38, 0x40, 0x49, 0x52, 0x64
    };
 
    fix32 value = get_actual(idx);
    fix32 signal = (value >= 0.0 ? 1.0 : -1.0);
    value = abs(value);
 
    uint8 i = min((uint8)value / 5, 19);
    value = lerp((fix32)cc[i], (fix32)cc[i+1], (value - (fix32)base[i]) / 5.0);
 
    return(value * signal);
}
 
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Creating a sensitivity curve for an analogue stick?

Postby J2Kbr » Sat Dec 26, 2020 10:30 pm

fdg0d wrote:i understand that but how do i make it into something like this

Here is the script with your conversion curve.
Code: Select all
main {
    set_val(STICK_1_X, stick_response(STICK_1_X));
    set_val(STICK_1_Y, stick_response(STICK_1_Y));
}
 
fix32 stick_response(uint8 idx) {
    const uint8 base[] = {
        0x00, 0x05, 0x0A, 0x0F, 0x14, 0x19, 0x1E, 0x23, 0x28, 0x2D, 0x32, 0x37,
        0x3C, 0x41, 0x46, 0x4B, 0x50, 0x55, 0x5A, 0x5F, 0x64
    };
    const uint8 cc[] = {
        0x00, 0x18, 0x20, 0x26, 0x2C, 0x31, 0x35, 0x38, 0x3B, 0x3E, 0x40, 0x43,
        0x46, 0x49, 0x4B, 0x4E, 0x50, 0x52, 0x55, 0x57, 0x59
    };
 
    fix32 value = get_actual(idx);
    fix32 signal = (value >= 0.0 ? 1.0 : -1.0);
    value = abs(value);
 
    uint8 i = min((uint8)value / 5, 19);
    value = lerp((fix32)cc[i], (fix32)cc[i+1], (value - (fix32)base[i]) / 5.0);
 
    return(value * signal);
}
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: Creating a sensitivity curve for an analogue stick?

Postby fdg0d » Sun Dec 27, 2020 2:38 pm

TY
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Previous

Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 166 guests