v0.2.0-dev-22 #47

Merged
altavir merged 158 commits from dev into master 2021-07-17 11:04:22 +03:00
Showing only changes of commit fb358dbc8e - Show all commits

View File

@ -39,7 +39,7 @@ public class OrbitControls internal constructor(camera: Camera, canvas: SubScene
public val baseZProperty: SimpleDoubleProperty = SimpleDoubleProperty(0.0) public val baseZProperty: SimpleDoubleProperty = SimpleDoubleProperty(0.0)
public var z: Double by baseZProperty public var z: Double by baseZProperty
private val baseTranslate = Translate() private val baseTranslate = Translate(0.0, 0.0, 0.0)
// val basePositionProperty: ObjectBinding<Point3D> = // val basePositionProperty: ObjectBinding<Point3D> =
// nonNullObjectBinding(baseXProperty, baseYProperty, baseZProperty) { // nonNullObjectBinding(baseXProperty, baseYProperty, baseZProperty) {
@ -62,13 +62,14 @@ public class OrbitControls internal constructor(camera: Camera, canvas: SubScene
private val ry = Rotate(0.0, Rotate.Y_AXIS) private val ry = Rotate(0.0, Rotate.Y_AXIS)
private val rz = Rotate(0.0, Rotate.Z_AXIS) private val translate = Translate(0.0, 0.0, 0.0)
private val translate = Translate() //private val rz = Rotate(0.0, Rotate.Z_AXIS)
init { init {
camera.transforms.setAll(rx, ry, rz, baseTranslate, translate) camera.transforms.setAll(baseTranslate, ry, rx, translate)
update() update()
val listener = InvalidationListener { val listener = InvalidationListener {
update() update()
@ -81,8 +82,8 @@ public class OrbitControls internal constructor(camera: Camera, canvas: SubScene
baseZProperty.addListener(listener) baseZProperty.addListener(listener)
canvas.apply { canvas.apply {
// center.xProperty().bind(widthProperty().divide(2)) //center.xProperty().bind(widthProperty().divide(2))
// center.zProperty().bind(heightProperty().divide(2)) //center.zProperty().bind(heightProperty().divide(2))
handleMouse() handleMouse()
} }
// coordinateContainer?.vbox { // coordinateContainer?.vbox {
@ -96,32 +97,32 @@ public class OrbitControls internal constructor(camera: Camera, canvas: SubScene
val spherePosition = Point3D( val spherePosition = Point3D(
sin(zenith) * sin(azimuth), sin(zenith) * sin(azimuth),
cos(zenith), cos(zenith),
sin(zenith) * cos(azimuth) sin(zenith) * cos(azimuth),
).times(distance) ).times(distance)
val basePosition = Point3D(x, y, z) val basePosition = Point3D(x, y, z)
baseTranslate.x = x baseTranslate.x = x
baseTranslate.y = y baseTranslate.y = y
baseTranslate.z = z baseTranslate.z = z
//Create direction vector //Create direction vector
val cameraPosition = basePosition + spherePosition val camPosition = basePosition+spherePosition
val camDirection: Point3D = (-spherePosition).normalize() val camDirection: Point3D = (-spherePosition).normalize()
val xRotation = Math.toDegrees(asin(-camDirection.y)) val xRotation = Math.toDegrees(asin(-camDirection.y))
val yRotation = Math.toDegrees(atan2(camDirection.x, camDirection.z)) val yRotation = Math.toDegrees(atan2(camDirection.x, camDirection.z))
rx.pivotX = cameraPosition.x rx.pivotX = camPosition.x
rx.pivotY = cameraPosition.y rx.pivotY = camPosition.y
rx.pivotZ = cameraPosition.z rx.pivotZ = camPosition.z
rx.angle = xRotation rx.angle = xRotation
ry.pivotX = cameraPosition.x ry.pivotX = camPosition.x
ry.pivotY = cameraPosition.y ry.pivotY = camPosition.y
ry.pivotZ = cameraPosition.z ry.pivotZ = camPosition.z
ry.angle = yRotation ry.angle = yRotation
translate.x = cameraPosition.x translate.x = camPosition.x
translate.y = cameraPosition.y translate.y = camPosition.y
translate.z = cameraPosition.z translate.z = camPosition.z
} }