[orx-camera] Add ParametricOrbital
This commit is contained in:
@@ -39,6 +39,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(project(":orx-camera"))
|
||||
implementation(project(":orx-mesh-generators"))
|
||||
implementation(project(":orx-jvm:orx-gui"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
77
orx-camera/src/commonMain/kotlin/ParametricOrbital.kt
Normal file
77
orx-camera/src/commonMain/kotlin/ParametricOrbital.kt
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
37
orx-camera/src/demo/kotlin/DemoParametricOrbital01.kt
Normal file
37
orx-camera/src/demo/kotlin/DemoParametricOrbital01.kt
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user