Skip to content

Commit

Permalink
Closes #175 - More sophisticated axis shaping
Browse files Browse the repository at this point in the history
- Allow exponents between 0.1 and 1
- Extended AxisToAxisAction by a minimum and maximum value property
  (i.e. output value bounds)
- Removed / replaced InitialValueEditorBuilder with AxisValueEditorBuilder (both were identical except for step size)
  • Loading branch information
bwRavencl committed Feb 26, 2024
1 parent ddc2a63 commit aaba66a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@
import de.bwravencl.controllerbuddy.input.action.annotation.Action;
import de.bwravencl.controllerbuddy.input.action.annotation.Action.ActionCategory;
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
import de.bwravencl.controllerbuddy.input.action.gui.AxisValueEditorBuilder;
import de.bwravencl.controllerbuddy.input.action.gui.DeadZoneEditorBuilder;
import de.bwravencl.controllerbuddy.input.action.gui.ExponentEditorBuilder;
import de.bwravencl.controllerbuddy.input.action.gui.InitialValueEditorBuilder;
import de.bwravencl.controllerbuddy.input.action.gui.MaxAxisValueEditorBuilder;
import de.bwravencl.controllerbuddy.input.action.gui.MinAxisValueEditorBuilder;

@Action(label = "TO_AXIS_ACTION", category = ActionCategory.AXIS, order = 10)
public class AxisToAxisAction extends ToAxisAction<Float> implements IAxisToAction, IInitializationAction<Float> {

private static final float DEFAULT_INITIAL_VALUE = 0f;
private static final float DEFAULT_MIN_VALUE = -1f;
private static final float DEFAULT_MAX_VALUE = 1f;
private static final float DEFAULT_DEAD_ZONE = 0f;
private static final float DEFAULT_EXPONENT = 1f;

@ActionProperty(label = "DEAD_ZONE", editorBuilder = DeadZoneEditorBuilder.class, order = 100)
float deadZone = DEFAULT_DEAD_ZONE;

@ActionProperty(label = "EXPONENT", editorBuilder = ExponentEditorBuilder.class, order = 101)
@ActionProperty(label = "MIN_AXIS_VALUE", editorBuilder = MinAxisValueEditorBuilder.class, order = 101)
float minValue = DEFAULT_MIN_VALUE;

@ActionProperty(label = "MAX_AXIS_VALUE", editorBuilder = MaxAxisValueEditorBuilder.class, order = 102)
float maxValue = DEFAULT_MAX_VALUE;

@ActionProperty(label = "EXPONENT", editorBuilder = ExponentEditorBuilder.class, order = 103)
float exponent = DEFAULT_EXPONENT;

@ActionProperty(label = "INITIAL_VALUE", editorBuilder = InitialValueEditorBuilder.class, order = 202)
@ActionProperty(label = "INITIAL_VALUE", editorBuilder = AxisValueEditorBuilder.class, order = 202)
float initialValue = DEFAULT_INITIAL_VALUE;

@Override
Expand All @@ -50,7 +60,7 @@ public void doAction(final Input input, final int component, Float value) {
value = 0f;
} else {
final float inMax;
if (exponent > 1f) {
if (exponent != 0f) {
inMax = (float) Math.pow((1f - deadZone) * 100f, exponent);

value = Math.signum(value) * (float) Math.pow((Math.abs(value) - deadZone) * 100f, exponent);
Expand All @@ -59,9 +69,9 @@ public void doAction(final Input input, final int component, Float value) {
}

if (value >= 0f) {
value = Input.normalize(value, deadZone, inMax, 0f, 1f);
value = Input.normalize(value, deadZone, inMax, 0f, maxValue);
} else {
value = Input.normalize(value, -inMax, -deadZone, -1f, 0f);
value = Input.normalize(value, -inMax, -deadZone, minValue, 0f);
}
}

Expand All @@ -80,6 +90,14 @@ public float getInitialValue() {
return initialValue;
}

public float getMaxValue() {
return maxValue;
}

public float getMinValue() {
return minValue;
}

@Override
public void init(final Input input) {
if (!input.isSkipAxisInitialization()) {
Expand All @@ -98,4 +116,12 @@ public void setExponent(final float exponent) {
public void setInitialValue(final float initialValue) {
this.initialValue = initialValue;
}

public void setMaxValue(final float maxValue) {
this.maxValue = maxValue;
}

public void setMinValue(final float minValue) {
this.minValue = minValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public void doAction(final Input input, final int component, final Float value)

final var runMode = input.getRunMode();
final var oldValue = Input.normalize(
input.getAxes().get(virtualAxis), runMode.getMinAxisValue(), runMode.getMaxAxisValue(), -1f, 1f);
input.getAxes().get(virtualAxis),
runMode.getMinAxisValue(),
runMode.getMaxAxisValue(),
minValue,
maxValue);

input.setAxis(virtualAxis, oldValue + (invert ? -d : d), hapticFeedback, detentValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import de.bwravencl.controllerbuddy.input.action.IAction;
import java.lang.reflect.InvocationTargetException;

public final class AxisValueEditorBuilder extends NumberEditorBuilder<Float> {
public class AxisValueEditorBuilder extends NumberEditorBuilder<Float> {

public AxisValueEditorBuilder(
final EditActionsDialog editActionsDialog,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Comparable<Float> getMaximum() {

@Override
Comparable<Float> getMinimum() {
return 1f;
return 0.1f;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2019 Matteo Hausner
/* Copyright (C) 2024 Matteo Hausner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,9 +20,9 @@
import de.bwravencl.controllerbuddy.input.action.IAction;
import java.lang.reflect.InvocationTargetException;

public final class InitialValueEditorBuilder extends NumberEditorBuilder<Float> {
public final class MaxAxisValueEditorBuilder extends AxisValueEditorBuilder {

public InitialValueEditorBuilder(
public MaxAxisValueEditorBuilder(
final EditActionsDialog editActionsDialog,
final IAction<?> action,
final String fieldName,
Expand All @@ -32,18 +32,8 @@ public InitialValueEditorBuilder(
super(editActionsDialog, action, fieldName, fieldType);
}

@Override
Comparable<Float> getMaximum() {
return 1f;
}

@Override
Comparable<Float> getMinimum() {
return -1f;
}

@Override
Number getStepSize() {
return 0.05f;
return 0f;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (C) 2024 Matteo Hausner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package de.bwravencl.controllerbuddy.input.action.gui;

import de.bwravencl.controllerbuddy.gui.EditActionsDialog;
import de.bwravencl.controllerbuddy.input.action.IAction;
import java.lang.reflect.InvocationTargetException;

public final class MinAxisValueEditorBuilder extends AxisValueEditorBuilder {

public MinAxisValueEditorBuilder(
final EditActionsDialog editActionsDialog,
final IAction<?> action,
final String fieldName,
final Class<?> fieldType)
throws SecurityException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException {
super(editActionsDialog, action, fieldName, fieldType);
}

@Override
Comparable<Float> getMaximum() {
return 0f;
}
}

0 comments on commit aaba66a

Please sign in to comment.