1

I'm looking to model actual distances say measured in centimeters. So the following SubScene containing a simple rectangle has width & height associated with my model distance in cm. The code renders correctly for certain and rectangle size (100 cm) but not others (200 cm). When I say it works, I see the red rectangle with 1/3 the size of the window pane... that is the field of view. When it does not work, the pane is blank. Strangely, I arranged the scaling so all the ratios are fixed by positioning the camera and fieldOfView angle from the size_cm parameter. So I'm confused why changing this absolute scaling should matter. I'm using Kotlin here, but I expect the same for straight up Java. I appreciate any thoughts.

class Scale3D : View("My View") {
val size_cm = 100.0 //works,  200.0 //fails
val cameraFOV_pix = 600.0
val cameraFOV_cm = 3.0 * size_cm
val cameraZOffset_cm = 1.0 * size_cm

val testBox = Rectangle(size_cm, size_cm).apply{
    fill= Color.RED
    translateX = -size_cm / 2.0
    translateY = -size_cm / 2.0
}

val vCamera = PerspectiveCamera(true).apply{
    translateZ = -cameraZOffset_cm
    fieldOfView = 2.0*Math.toDegrees(Math.atan2(cameraFOV_cm/2.0, cameraZOffset_cm))
    println("angle=%.1f deg".format(fieldOfView))
}

override val root = anchorpane {
    val rootVx = Group(vCamera,testBox)
    val subScene = SubScene(rootVx, cameraFOV_pix, cameraFOV_pix,true, SceneAntialiasing.BALANCED).apply {
        fill = Color.ALICEBLUE
        camera = vCamera
    }
    children.addAll(subScene)
}

}

J.E.Tkaczyk
  • 557
  • 1
  • 8
  • 19

1 Answers1

1

I guess you have to consider the clip planes. There is a near clip plane and a far clip plane. The near/far clip plane defines the closest/furthest point relative to the camera that objects will be rendered (e.g. https://docs.oracle.com/javafx/8/3d_graphics/camera.htm). The default value for the near clip plane is 0.1 and for the far clip plane 100.0 (https://docs.oracle.com/javase/9/docs/api/javafx/scene/Camera.html#farClipProperty). In your scenario the object is located BEHIND the far clip plane for all distances cameraZOffset_cm > 100.0 (= far clip default value). Because of cameraZOffset_cm = 1.0 * size_cm this corresponds to size_cm > 100.0. Thus, your object is not rendered for all sizes larger 100.0. You have simply to increase the far clip to AT LEAST cameraZOffset_cm with camera.setFarClip(cameraZOffset_cm) or rather the corresponding Kotlin-command.

Topaco
  • 40,594
  • 4
  • 35
  • 62