Fix clipping planes in EmulGL

This commit is contained in:
martin 2022-09-01 17:02:49 +02:00
parent 7f7d56d710
commit 8fdd651bff
7 changed files with 50 additions and 9 deletions

View File

@ -47,8 +47,7 @@ public class AWTCameraMouseController extends AbstractCameraController
MousePosition mousePosition = new MousePosition();
MouseSelectionSettings selectionSettings = new MouseSelectionSettings();
public AWTCameraMouseController() {}
public AWTCameraMouseController(Chart chart) {
@ -154,6 +153,7 @@ public class AWTCameraMouseController extends AbstractCameraController
// 2D mode
else {
// stop displaying mouse position on roll over
mousePosition = new MousePosition();
@ -344,9 +344,10 @@ public class AWTCameraMouseController extends AbstractCameraController
mouseSelection = new MouseSelection();
// Crop and zoom
if (allowCrop)
getChart().getScene().getGraph().setClipBox(bounds, true, false);
if (allowCrop) {
boolean includeLimits = false; // to avoid inacurrate box scale
getChart().getScene().getGraph().setClipBox(bounds, includeLimits, false);
}
view.setBoundsManual(bounds);

View File

@ -625,6 +625,13 @@ public class Array {
System.out.println("");
}
public static void print(boolean input[]) {
for (int i = 0; i < input.length; i++) {
System.out.print(input[i] + "|");
}
System.out.println("");
}
public static void print(double input[][]) {
for (int i = 0; i < input.length; i++) {
for (int j = 0; j < input[i].length; j++) {
@ -663,7 +670,12 @@ public class Array {
System.out.print(info);
print(input);
}
public static void print(String info, boolean input[]) {
System.out.print(info);
print(input);
}
public static void print(String info, int input[]) {
System.out.print(info);
print(input);

View File

@ -222,6 +222,20 @@ public abstract class AbstractPainter implements IPainter {
glDisable_ClipPlane(4);
glDisable_ClipPlane(5);
}
@Override
public boolean[] clipStatus() {
boolean[] status = new boolean[6];
int[] v = {-1};
for(int i=0; i<6; i++) {
glGetIntegerv(clipPlaneId(i), v, 0);
status[i] = (v[0]==1);
}
return status;
}
/**
* A convenient shortcut to invoke a clipping plane using an ID in [0;5] instead of the original

View File

@ -193,6 +193,9 @@ public interface IPainter {
/** Disable all clipping planes */
public void clipOff();
/** Indicates status of clipping planes (on/off) */
public boolean[] clipStatus();
/**
* A convenient shortcut to glColor4f which overrides the color's alpha channel
*/

View File

@ -2,6 +2,7 @@ package org.jzy3d.plot3d.rendering.scene;
import java.util.ArrayList;
import java.util.List;
import org.jzy3d.maths.Array;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot3d.primitives.Composite;
@ -205,6 +206,8 @@ public class Graph {
painter.clipOn();
}
//Array.print("Clipping planes : ", painter.clipStatus());
// draw
draw(painter, components, sort);

View File

@ -983,7 +983,7 @@ public class EmulGLPainter extends AbstractPainter implements IPainter {
@Override
public void glClipPlane(int plane, double[] equation) {
gl.glClipPlane(GL.GL_CLIP_PLANE0, equation);
gl.glClipPlane(plane, equation);
}
@Override
@ -1013,10 +1013,10 @@ public class EmulGLPainter extends AbstractPainter implements IPainter {
case 5:
return GL.GL_CLIP_PLANE5;
default:
throw new IllegalArgumentException("Expect a plane ID in [0;5]");
throw new IllegalArgumentException("Expect a plane ID in [0;5], received " + id);
}
}
@Override
public boolean gluUnProject(float winX, float winY, float winZ, float[] model, int model_offset,

View File

@ -1323,6 +1323,14 @@ public abstract class GL<ImageType, FontType> {
case GL_MAX_CLIP_PLANES:
params[0] = Context.MAX_CLIP_PLANES;
break;
case GL_CLIP_PLANE0:
case GL_CLIP_PLANE1:
case GL_CLIP_PLANE2:
case GL_CLIP_PLANE3:
case GL_CLIP_PLANE4:
case GL_CLIP_PLANE5:
params[0] = Context.Transform.ClipEnable[pname - GL_CLIP_PLANE0]?1:0;
break;
case GL_MAX_MODELVIEW_STACK_DEPTH:
case GL_MAX_PROJECTION_STACK_DEPTH:
case GL_MAX_TEXTURE_STACK_DEPTH: