From 2677b6cb77c0702a171a9ecc37a9a362f2f3f916 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Tue, 29 Jun 2021 14:10:53 +0200 Subject: [PATCH] [orx-camera] convert to MPP --- build.gradle | 1 + orx-camera/build.gradle.kts | 96 +++++++++++++++++++ .../{main => commonMain}/kotlin/AxisHelper.kt | 0 .../{main => commonMain}/kotlin/GridHelper.kt | 0 .../{main => commonMain}/kotlin/Orbital.kt | 0 .../kotlin/OrbitalCamera.kt | 9 +- .../kotlin/OrbitalControls.kt | 3 +- 7 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 orx-camera/build.gradle.kts rename orx-camera/src/{main => commonMain}/kotlin/AxisHelper.kt (100%) rename orx-camera/src/{main => commonMain}/kotlin/GridHelper.kt (100%) rename orx-camera/src/{main => commonMain}/kotlin/Orbital.kt (100%) rename orx-camera/src/{main => commonMain}/kotlin/OrbitalCamera.kt (97%) rename orx-camera/src/{main => commonMain}/kotlin/OrbitalControls.kt (97%) diff --git a/build.gradle b/build.gradle index e6ba09d5..d6a368cd 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ plugins { } def multiplatformModules = [ + "orx-camera", "orx-noise", "orx-shader-phrases", "orx-parameters", diff --git a/orx-camera/build.gradle.kts b/orx-camera/build.gradle.kts new file mode 100644 index 00000000..6e6dff4c --- /dev/null +++ b/orx-camera/build.gradle.kts @@ -0,0 +1,96 @@ +import Orx_embed_shaders_gradle.EmbedShadersTask + +plugins { + kotlin("multiplatform") + kotlin("plugin.serialization") + id("orx.embed-shaders") +} + +val kotlinxSerializationVersion: String by rootProject.extra +val kotestVersion: String by rootProject.extra +val junitJupiterVersion: String by rootProject.extra +val jvmTarget: String by rootProject.extra +val kotlinApiVersion: String by rootProject.extra +val kotlinVersion: String by rootProject.extra +val kotlinLoggingVersion: String by rootProject.extra +val kluentVersion: String by rootProject.extra +val openrndrVersion: String by rootProject.extra +val openrndrOS: String by rootProject.extra +val spekVersion: String by rootProject.extra + +kotlin { + jvm { + compilations { + val demo by creating { + defaultSourceSet { + kotlin.srcDir("src/demo") + dependencies { + implementation(project(":orx-camera")) + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-extensions:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3:$openrndrVersion") + runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion") + implementation(compilations["main"]!!.output.allOutputs) + } + } + } + } + compilations.all { + kotlinOptions.jvmTarget = jvmTarget + kotlinOptions.apiVersion = kotlinApiVersion + } + testRuns["test"].executionTask.configure { + useJUnitPlatform() + } + } + js(IR) { + browser() + nodejs() + } + + sourceSets { + @Suppress("UNUSED_VARIABLE") + val commonMain by getting { + dependencies { + implementation(project(":orx-parameters")) + implementation(project(":orx-shader-phrases")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion") + implementation("org.openrndr:openrndr-application:$openrndrVersion") + implementation("org.openrndr:openrndr-draw:$openrndrVersion") + implementation("org.openrndr:openrndr-filter:$openrndrVersion") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion") + } + } + @Suppress("UNUSED_VARIABLE") + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + implementation("io.kotest:kotest-assertions-core:$kotestVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jvmTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + implementation(kotlin("test-junit5")) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion") + runtimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") + implementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion") + implementation("org.amshove.kluent:kluent:$kluentVersion") + } + } + + @Suppress("UNUSED_VARIABLE") + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} \ No newline at end of file diff --git a/orx-camera/src/main/kotlin/AxisHelper.kt b/orx-camera/src/commonMain/kotlin/AxisHelper.kt similarity index 100% rename from orx-camera/src/main/kotlin/AxisHelper.kt rename to orx-camera/src/commonMain/kotlin/AxisHelper.kt diff --git a/orx-camera/src/main/kotlin/GridHelper.kt b/orx-camera/src/commonMain/kotlin/GridHelper.kt similarity index 100% rename from orx-camera/src/main/kotlin/GridHelper.kt rename to orx-camera/src/commonMain/kotlin/GridHelper.kt diff --git a/orx-camera/src/main/kotlin/Orbital.kt b/orx-camera/src/commonMain/kotlin/Orbital.kt similarity index 100% rename from orx-camera/src/main/kotlin/Orbital.kt rename to orx-camera/src/commonMain/kotlin/Orbital.kt diff --git a/orx-camera/src/main/kotlin/OrbitalCamera.kt b/orx-camera/src/commonMain/kotlin/OrbitalCamera.kt similarity index 97% rename from orx-camera/src/main/kotlin/OrbitalCamera.kt rename to orx-camera/src/commonMain/kotlin/OrbitalCamera.kt index 9b3ccd80..cf8c3279 100644 --- a/orx-camera/src/main/kotlin/OrbitalCamera.kt +++ b/orx-camera/src/commonMain/kotlin/OrbitalCamera.kt @@ -8,6 +8,7 @@ import org.openrndr.math.Matrix44 import org.openrndr.math.Spherical import org.openrndr.math.Vector3 import kotlin.math.abs +import kotlin.math.pow import org.openrndr.math.transforms.lookAt as lookAt_ enum class ProjectionType { @@ -69,12 +70,12 @@ class OrbitalCamera(eye: Vector3 = Vector3.ZERO, lookAt: Vector3 = Vector3.UNIT_ } fun dollyIn() { - val zoomScale = Math.pow(0.95, zoomSpeed) + val zoomScale = pow(0.95, zoomSpeed) dolly(sphericalEnd.radius * zoomScale - sphericalEnd.radius) } fun dollyOut() { - val zoomScale = Math.pow(0.95, zoomSpeed) + val zoomScale = pow(0.95, zoomSpeed) dolly(sphericalEnd.radius / zoomScale - sphericalEnd.radius) } @@ -218,4 +219,6 @@ fun OrbitalCamera.applyTo(drawer: Drawer) { drawer.drawStyle.depthWrite = true drawer.drawStyle.depthTestPass = DepthTestPass.LESS_OR_EQUAL } -} \ No newline at end of file +} + +private fun pow(a:Double, x:Double): Double = a.pow(x) \ No newline at end of file diff --git a/orx-camera/src/main/kotlin/OrbitalControls.kt b/orx-camera/src/commonMain/kotlin/OrbitalControls.kt similarity index 97% rename from orx-camera/src/main/kotlin/OrbitalControls.kt rename to orx-camera/src/commonMain/kotlin/OrbitalControls.kt index 6f3b387d..684f6468 100644 --- a/orx-camera/src/main/kotlin/OrbitalControls.kt +++ b/orx-camera/src/commonMain/kotlin/OrbitalControls.kt @@ -3,6 +3,7 @@ package org.openrndr.extras.camera import org.openrndr.* import org.openrndr.math.Vector2 import org.openrndr.math.Vector3 +import org.openrndr.math.asRadians import kotlin.math.PI import kotlin.math.abs import kotlin.math.tan @@ -51,7 +52,7 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo val offset = Vector3.fromSpherical(orbitalCamera.spherical) - orbitalCamera.lookAt // half of the fov is center to top of screen - val targetDistance = offset.length * tan((Math.toRadians((fov) / 2))) + val targetDistance = offset.length * tan(fov / 2).asRadians val panX = (2 * delta.x * targetDistance / program.window.size.x) val panY = (2 * delta.y * targetDistance / program.window.size.y)