Updated OrbitControls #44
@ -38,7 +38,7 @@ class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec:
|
|||||||
val baseZProperty = SimpleDoubleProperty(0.0)
|
val baseZProperty = SimpleDoubleProperty(0.0)
|
||||||
var z by baseZProperty
|
var z 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) {
|
||||||
@ -59,13 +59,13 @@ class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec:
|
|||||||
|
|
||||||
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, translate)
|
camera.transforms.setAll(baseTranslate, ry, rx, translate)
|
||||||
update()
|
update()
|
||||||
val listener = InvalidationListener {
|
val listener = InvalidationListener {
|
||||||
update()
|
update()
|
||||||
@ -78,8 +78,8 @@ class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec:
|
|||||||
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 {
|
||||||
@ -93,32 +93,32 @@ class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec:
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user