diff --git a/orx-camera/build.gradle.kts b/orx-camera/build.gradle.kts index e8a732d5..ee3898f7 100644 --- a/orx-camera/build.gradle.kts +++ b/orx-camera/build.gradle.kts @@ -39,6 +39,7 @@ kotlin { dependencies { implementation(project(":orx-camera")) implementation(project(":orx-mesh-generators")) + implementation(project(":orx-jvm:orx-gui")) } } } diff --git a/orx-camera/src/commonMain/kotlin/ParametricOrbital.kt b/orx-camera/src/commonMain/kotlin/ParametricOrbital.kt new file mode 100644 index 00000000..8e23d1dc --- /dev/null +++ b/orx-camera/src/commonMain/kotlin/ParametricOrbital.kt @@ -0,0 +1,77 @@ +package org.openrndr.extra.camera + +import org.openrndr.Extension +import org.openrndr.Program +import org.openrndr.draw.Drawer +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.DoubleParameter +import org.openrndr.extra.parameters.Vector3Parameter +import org.openrndr.math.Spherical +import org.openrndr.math.Vector3 + +/** + * Extension that provides orbital camera through annotated parameters + */ +@Description("Orbital camera") +class ParametricOrbital : Extension { + override var enabled: Boolean = true + + @DoubleParameter("fov", 1.0, 90.0, order = 0) + var fov = 45.0 + set(value) { + field = value + camera.zoomTo(fov) + } + + val camera by lazy { + OrbitalCamera(Spherical(theta, phi, radius).cartesian, center, fov, 0.1, 1000.0, projectionType).apply { + dampingFactor = 0.0 + } + } + + @DoubleParameter("phi", 0.0, 180.0, order = 2) + var phi = 0.0 + set(value) { + field = value + camera.rotateTo(theta, phi.coerceAtLeast(1E-3)) + } + + @DoubleParameter("theta", -180.0, 180.0, order = 1) + var theta = 0.0 + set(value) { + field = value + camera.rotateTo(theta, phi.coerceAtLeast(1E-3)) + } + + + @DoubleParameter("orbit radius", 0.1, 100.0, order = 3) + var radius = 10.0 + set(value) { + field = value + camera.dollyTo(radius) + } + + + @Vector3Parameter("center", order = 4) + var center = Vector3.ZERO + set(value) { + field = value + camera.panTo(value) + } + + + var projectionType = ProjectionType.PERSPECTIVE + + + override fun setup(program: Program) { + + } + + override fun beforeDraw(drawer: Drawer, program: Program) { + camera.beforeDraw(drawer, program) + } + + override fun afterDraw(drawer: Drawer, program: Program) { + camera.afterDraw(drawer, program) + } +} \ No newline at end of file diff --git a/orx-camera/src/demo/kotlin/DemoCamera2D.kt b/orx-camera/src/demo/kotlin/DemoCamera2D01.kt similarity index 100% rename from orx-camera/src/demo/kotlin/DemoCamera2D.kt rename to orx-camera/src/demo/kotlin/DemoCamera2D01.kt diff --git a/orx-camera/src/demo/kotlin/DemoCamera2D_01.kt b/orx-camera/src/demo/kotlin/DemoCamera2D_01.kt deleted file mode 100644 index bf12a1e4..00000000 --- a/orx-camera/src/demo/kotlin/DemoCamera2D_01.kt +++ /dev/null @@ -1,25 +0,0 @@ -import org.openrndr.application -import org.openrndr.color.ColorRGBa -import org.openrndr.draw.loadFont -import org.openrndr.extra.camera.Camera2D - -/** - * # Camera2D demo - * - * click and drag the mouse for panning, use the mouse wheel for zooming - */ -fun main() = application { - program { - val font = loadFont("demo-data/fonts/IBMPlexMono-Regular.ttf", 72.0) - - extend(Camera2D()) - extend { - drawer.circle(drawer.bounds.center, 300.0) - - drawer.fontMap = font - drawer.fill = ColorRGBa.PINK - drawer.text("click and drag mouse", 50.0, 400.0) - drawer.text("use mouse wheel", 50.0, 500.0) - } - } -} \ No newline at end of file diff --git a/orx-camera/src/demo/kotlin/DemoParametricOrbital01.kt b/orx-camera/src/demo/kotlin/DemoParametricOrbital01.kt new file mode 100644 index 00000000..6894cef1 --- /dev/null +++ b/orx-camera/src/demo/kotlin/DemoParametricOrbital01.kt @@ -0,0 +1,37 @@ +import org.openrndr.WindowMultisample +import org.openrndr.application +import org.openrndr.color.ColorRGBa +import org.openrndr.draw.DrawPrimitive +import org.openrndr.draw.shadeStyle +import org.openrndr.extra.camera.* +import org.openrndr.extra.gui.GUI +import org.openrndr.extra.gui.addTo +import org.openrndr.extra.meshgenerators.boxMesh +import org.openrndr.extra.meshgenerators.sphereMesh +import org.openrndr.math.Vector3 + +fun main() = application { + configure { + multisample = WindowMultisample.SampleCount(8) + } + + program { + val gui = GUI() + val po = ParametricOrbital() + po.addTo(gui) + extend(gui) + extend(po) + + val bm = boxMesh() + extend { + drawer.clear(ColorRGBa.PINK) + drawer.shadeStyle = shadeStyle { + fragmentTransform = """ + vec3 n = normalize(v_viewNormal) * 0.5 + 0.5; + x_fill = vec4(n, 1.0); + """.trimIndent() + } + drawer.vertexBuffer(bm, DrawPrimitive.TRIANGLES) + } + } +} \ No newline at end of file