From a4cab620129a52ff83d5051af193373742e433bb Mon Sep 17 00:00:00 2001 From: Steven van den Broek <30909373+Yvee1@users.noreply.github.com> Date: Tue, 21 Sep 2021 08:17:29 +0200 Subject: [PATCH] [orx-gui] Functionality for randomizing vectors (#195) * [orx-gui] Randomize vectors * [orx-gui] Remove redundant import --- orx-jvm/orx-gui/src/main/kotlin/Gui.kt | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/orx-jvm/orx-gui/src/main/kotlin/Gui.kt b/orx-jvm/orx-gui/src/main/kotlin/Gui.kt index bc6d5cd6..0bb7e2eb 100644 --- a/orx-jvm/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-jvm/orx-gui/src/main/kotlin/Gui.kt @@ -844,6 +844,38 @@ class GUI : Extension { (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) } + ParameterType.Vector2 -> { + val min = parameter.doubleRange!!.start + val max = parameter.doubleRange!!.endInclusive + val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) + val randomValue = Vector2(Math.random(), Math.random()) * (max - min) + min + val newValue = currentValue * (1.0 - strength) + randomValue * strength + (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) + } + ParameterType.XY -> { + val min = parameter.vectorRange!!.first + val max = parameter.vectorRange!!.second + val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) + val randomValue = Vector2(Math.random() * (max.x - min.x) + min.x, Math.random() * (max.y - min.y) + min.y) + val newValue = currentValue * (1.0 - strength) + randomValue * strength + (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) + } + ParameterType.Vector3 -> { + val min = parameter.doubleRange!!.start + val max = parameter.doubleRange!!.endInclusive + val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) + val randomValue = Vector3(Math.random(), Math.random(), Math.random()) * (max - min) + min + val newValue = currentValue * (1.0 - strength) + randomValue * strength + (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) + } + ParameterType.Vector4 -> { + val min = parameter.doubleRange!!.start + val max = parameter.doubleRange!!.endInclusive + val currentValue = (parameter.property as KMutableProperty1).get(labeledObject.obj) + val randomValue = Vector4(Math.random(), Math.random(), Math.random(), Math.random()) * (max - min) + min + val newValue = currentValue * (1.0 - strength) + randomValue * strength + (parameter.property as KMutableProperty1).set(labeledObject.obj, newValue) + } else -> { // intentionally do nothing }