Add dynamic rotation example

This commit is contained in:
Alexander Nozik 2023-06-07 21:29:40 +03:00
parent 07b54fde51
commit f2d7e20fd3
2 changed files with 14 additions and 4 deletions

View File

@ -4,6 +4,8 @@ import kotlinx.coroutines.*
import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.invoke import space.kscience.dataforge.meta.invoke
import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.Name
import space.kscience.kmath.geometry.Euclidean3DSpace
import space.kscience.kmath.geometry.radians
import space.kscience.visionforge.Colors import space.kscience.visionforge.Colors
import space.kscience.visionforge.solid.* import space.kscience.visionforge.solid.*
import space.kscience.visionforge.solid.specifications.Canvas3DOptions import space.kscience.visionforge.solid.specifications.Canvas3DOptions
@ -103,8 +105,15 @@ fun VisionLayout<Solid>.showcase() {
solidGroup { solidGroup {
x = 200 x = 200
rotationY = PI / 4 rotationY = PI / 4
axes(200)
box(100, 100, 100) { box(100, 100, 100) {
rotationZ = PI / 4 rotate((PI / 4).radians, Euclidean3DSpace.zAxis)
GlobalScope.launch(Dispatchers.Main) {
while (isActive) {
delay(100)
rotate((PI/20).radians,Euclidean3DSpace.yAxis)
}
}
color.set(Colors.red) color.set(Colors.red)
} }
} }
@ -151,7 +160,7 @@ fun VisionLayout<Solid>.showcase() {
} }
} }
demo("STL", "STL loaded from URL"){ demo("STL", "STL loaded from URL") {
stl("https://ozeki.hu/attachments/116/Menger_sponge_sample.stl") stl("https://ozeki.hu/attachments/116/Menger_sponge_sample.stl")
} }
} }

View File

@ -9,6 +9,7 @@ import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus import space.kscience.dataforge.names.plus
import space.kscience.kmath.complex.Quaternion import space.kscience.kmath.complex.Quaternion
import space.kscience.kmath.complex.QuaternionField
import space.kscience.kmath.geometry.* import space.kscience.kmath.geometry.*
import space.kscience.visionforge.* import space.kscience.visionforge.*
import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY
@ -245,6 +246,6 @@ public var Solid.scaleZ: Number by float(Z_SCALE_KEY, 1f)
/** /**
* Add rotation with given [angle] relative to given [axis] * Add rotation with given [angle] relative to given [axis]
*/ */
public fun Solid.rotate(angle: Angle, axis: DoubleVector3D) { public fun Solid.rotate(angle: Angle, axis: DoubleVector3D) = with(QuaternionField) {
quaternion = Quaternion.fromRotation(angle, axis) quaternion = Quaternion.fromRotation(angle, axis)*quaternion
} }