Created
December 4, 2019 21:37
-
-
Save WhiteMagic/873f1eb45517dd52973df19477e09671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
import gremlin | |
from gremlin.user_plugin import * | |
mode = ModeVariable("Mode", "The mode in which to use this mapping") | |
input_1 = PhysicalInputVariable( | |
"Input axis 1", | |
"Input axis 1", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
input_2 = PhysicalInputVariable( | |
"Input axis 2", | |
"Input axis 2", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
output_1 = VirtualInputVariable( | |
"Aligned output axis", | |
"Aligned output axis", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
output_2 = VirtualInputVariable( | |
"Opposed output axis", | |
"Opposed output axis", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
invert_1 = BoolVariable( | |
"Invert aligned axis", | |
"Invert aligned axis" | |
) | |
invert_2 = BoolVariable( | |
"Invert opposed axis", | |
"Invert opposed axis" | |
) | |
# Decorators for the two physical axes | |
dec_1 = input_1.create_decorator(mode.value) | |
dec_2 = input_2.create_decorator(mode.value) | |
# Storage for axis values | |
g_axis_1_value = 0.0 | |
g_axis_2_value = 0.0 | |
def update_axis(vjoy): | |
aligned = (g_axis_1_value * g_axis_2_value) >= 0 | |
if aligned: | |
value = (g_axis_1_value + g_axis_2_value) / 2 | |
if invert_1.value: | |
vjoy[output_1.vjoy_id].axis(output_1.input_id).value = -value | |
else: | |
vjoy[output_1.vjoy_id].axis(output_1.input_id).value = value | |
vjoy[output_2.vjoy_id].axis(output_2.input_id).value = 0.0 | |
else: | |
value = math.copysign( | |
(abs(g_axis_1_value) + abs(g_axis_2_value)) / 2, | |
g_axis_1_value | |
) | |
vjoy[output_1.vjoy_id].axis(output_1.input_id).value = 0.0 | |
if invert_2.value: | |
vjoy[output_2.vjoy_id].axis(output_2.input_id).value = -value | |
else: | |
vjoy[output_2.vjoy_id].axis(output_2.input_id).value = value | |
@dec_1.axis(input_1.input_id) | |
def axis1(event, vjoy): | |
global g_axis_1_value | |
g_axis_1_value = event.value | |
update_axis(vjoy) | |
@dec_2.axis(input_2.input_id) | |
def axis1(event, vjoy): | |
global g_axis_2_value | |
g_axis_2_value = event.value | |
update_axis(vjoy) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment