Java OpenGL - spelling truncation calculation for isometric representation

I am trying to figure out how to correctly calculate the truncation boundaries of my openGL scene under orthographic projection. The code I use for this is as follows:

public void setFrustum(GL gl, GLU glu){

    double[] forwardAxis = properties.getForwardAxis();
    double[] leftAxis = VecMath.normalVector(properties.getUpDir(), forwardAxis);
    double[] upAxis = VecMath.normalVector(forwardAxis, leftAxis);

    double[] v = bounds.getWidthVector();

    double width = VecMath.magnitude(VecMath.project(v, leftAxis));
    double height = VecMath.magnitude(VecMath.project(v, upAxis));

    double modelRatio = width / height;
    double canvasRatio = properties.getAspectRatio();
    // -- height bigger than width --
    if (modelRatio < canvasRatio){
        // -- update width --
        width = height * canvasRatio;
    } else{
        // -- update height --
        height = width / canvasRatio;
    }

    double l = width / 2. * 1.15;
    double b = height / 2. * 1.15;
    double n = properties.getNear();
    double f = properties.getFar();
    gl.glOrtho(-l, l, -b, b, n, f);
}

So, as you can see, I get my axes and width vector:

widthVector = (xWidth, yWidth, zWidth)

and then get the width and height of the gl scene by projecting this width vector along leftAxis and upAxis. Then I map aspectRatio to the canvas aspect. I show this scene and use the width and height to calculate the boundaries of the spelling truncation (adding extras using a scale factor of 1.15).

This works well for all sorts except for the isometric representation. Here are some screenshots of this at work:

Bottomview Leftview Frontview

Isometricview

, , . , ( , !). , 1,5 1,15, - .

. !

+4
2

fitAllIn

public void fitAllIn(float[] boundingMinMaxWorldSpace) {

        Vec4 centerWorldSpace = new Vec4((boundingMinMaxWorldSpace[0] + boundingMinMaxWorldSpace[1]) / 2,
                (boundingMinMaxWorldSpace[2] + boundingMinMaxWorldSpace[3]) / 2,
                (boundingMinMaxWorldSpace[4] + boundingMinMaxWorldSpace[5]) / 2, 1f);

        Vec3 min = new Vec3(boundingMinMaxWorldSpace[0], boundingMinMaxWorldSpace[2], boundingMinMaxWorldSpace[4]);
        Vec3 max = new Vec3(boundingMinMaxWorldSpace[1], boundingMinMaxWorldSpace[3], boundingMinMaxWorldSpace[5]);

        float diameter = (float) Math.sqrt(
                (max.x - min.x) * (max.x - min.x)
                + (max.y - min.y) * (max.y - min.y)
                + (max.z - min.z) * (max.z - min.z));

        if (getCurrView().orthographicProj) {

            if (glViewer.getAspect() > 1) {
                // projection * scale = y
                getCurrView().scale = diameter / 2 / projectionSide;

            } else {
                // projection * aspect * scale = x
                getCurrView().scale = diameter / 2 / (projectionSide * glViewer.getAspect());
            }
            getCurrView().scale = viewScale.clampScale(projectionSide, getCurrView().scale);
        }
    getCurrView().targetPos = new Vec3(centerWorldSpace);

    glViewer.refresh();

, , . (minX, minY, minZ) . , .

scale projectionSide

        float x = projectionSide * glViewer.getAspect() * getCurrView().scale;
        float y = projectionSide * getCurrView().scale;
        float z = projectionSide;

        return Jglm.orthographic(-x, x, -y, y, -z, z);
+1

elect, setFrustum:

public void setFrustum(GL gl, GLU glu) {

    double[] widthVec = bounds.getWidthVector();

    double diameter = VecMath.magnitude(widthVec);

    double canvasRatio = properties.getAspectRatio();

    double scale = canvasRatio > 1 ? diameter / 2 : diameter / 2 / canvasRatio;

    double x = canvasRatio * scale;
    double y = scale;

    double n = properties.getNear();
    double f = properties.getFar();
    gl.glOrtho(-x, x, -y, y, n, f);
}

. Elect!

0

Source: https://habr.com/ru/post/1610624/


All Articles