Reputation: 67
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?
Upvotes: 5
Views: 1541
Reputation: 4010
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
.
Upvotes: 0
Reputation: 41
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.
Upvotes: 4