5

I am part of a team building an application that manipulates a visual model using JavaFX 8 3D. We use both a Perspective Camera and a Parallel Camera. The Perspective Camera is working as expected. It is currently working with isEyeAtCameraZero false. This was done for maximum compatibility with the Parallel Camera.

The Perspective Camera behaves correctly when camera.setNearClip() and camera.setFarClip() are called.

The Parallel Camera does not appear to respond to camera.setNearClip() and camera.setFarClip(). The Parallel Camera does perform near and far clipping, but I have been unable to change the Parallel Camera clipping range.

I am using an algorithm based on the pseudo code on the JavaFX 8 Camera javadocs page to calculate the values passed into camera.setNearClip() and camera.setFarClip(). This appears to work correctly with the Perspective Camera but not the Parallel Camera.

Can anyone offer advice on how to manage the clipping range of the Parallel Camera?

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 1
    I am a little late!; but I would like to thank InteractiveMesh. As a result we simulated a ParallelCamera by setting Persective field of view to a very small angle and calculating the camera to target distance required to fill the view with the target object. It is a bit of a kludge, but the end users are happy and it does produce a respectable orthographic view of the scene. – Dennis Mackay-Fisher Nov 24 '15 at 12:49
  • yours should be the correct answer as it seems possible to simulate a ParallelCamera. i have just tried values of `camera.setFieldOfView(1);camera.setTranslateZ(-26*cameraDistance);` with cameraDistance being the distance i used for a "normal" perspectiveCamera. and it looks pretty ok having lost its z depth – MitchBroadhead May 31 '18 at 21:48

2 Answers2

2

The ParallelCamera seems to ignore the clipping distances when calculating the orthogonal projection. Instead the Scene/SubScene's width or height determines the far and near clipping planes according to the package private method:

void computeProjectionTransform(GeneralTransform3D proj) {
    final double viewWidth = getViewWidth();
    final double viewHeight = getViewHeight();
    final double halfDepth = (viewWidth > viewHeight) ? viewWidth / 2.0 : viewHeight / 2.0;

    proj.ortho(0.0, viewWidth, viewHeight, 0.0, -halfDepth, halfDepth);
}

This makes the ParallelCamera quite useless for 3D rendering in JavaFX.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

As InnteractiveMesh says, this isn't supported out of the box, but it is possible to override it:

package javafx.scene

import com.sun.javafx.geom.transform.GeneralTransform3D

public class BetterOrthoCamera extends ParallelCamera
{
    public double orthoDepth = 1000.0;

    @Override
    void computeProjectionTransform(GeneralTransform3D var1) {
        double var2 = this.getViewWidth();
        double var4 = this.getViewHeight();
        double var6 = orthoDepth;
        var1.ortho(0.0, var2, var4, 0.0, -var6, var6);
    }

}

Note that you may encounter module issues because the method is package private, so we must define our subclass in javafx.scene, but running in UNNAMED seems to work for me.

It's also possible to adjust it to be non-symmetric, just change -var6 and var6.

byteit101
  • 3,910
  • 2
  • 20
  • 29