简体   繁体   中英

LibGDX Orthographic camera not rendering at certain angles

I'm currently experimenting with different cameras in libgdx (using ShapeRenderer). However I've found that at certain rotations it stops rendering segments of the shape.

For example the normal shape with camera Position: (8.999996,7.699995,5.599995) Direction: (0.04838332,-0.60004705,-0.7576189):

normal_shape

However with camera Position: (8.999996,7.699995,5.0999956) Direction: (0.6789076,-0.57323986,-0.38322547):

cutoff_shape

As far as I'm aware this does not occur on PerspectiveCamera (I haven't tested it extensively though so I might be wrong).

Code snippets

Aux. Info:

VIEWPORT_WIDTH = 20;
VIEWPORT_HEIGHT = 13;
gridDist = 1.2f;

The x and y for each tile is an Integer (like a grid).

Setting up camera (I am using Scene2D.Stage):

public MainStage(){

        super(new ScalingViewport(Scaling.stretch, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())));
        camera = (OrthographicCamera) this.getCamera();
        camera.direction.set(0f, 0.3f,-0.92f);
        camera.position.set(10f,0f,10f);
        camera.update();
}

Drawing Tiles (X/Y coordinates) :

renderer.setProjectionMatrix(camera.combined);

renderer.begin(ShapeType.Line);
renderer.setColor(1, 1, 0, 1);
for(GridTile[] trow: room.tiles){
    for(GridTile tile: trow){

        if(tile.status != EMPTY){


            if(tile.status == FULL){
                renderer.rect(tile.x*gridDist, tile.y*gridDist, gridDist, gridDist);

            }
            else if(tile.status == UP_RIGHT){
                renderer.triangle((tile.x+1)*gridDist, tile.y*gridDist, (tile.x+1)*gridDist, (tile.y+1)*gridDist, (tile.x)*gridDist, (tile.y+1)*gridDist);

            }
            else if(tile.status == DOWN_RIGHT){
                renderer.triangle((tile.x)*gridDist, tile.y*gridDist, (tile.x+1)*gridDist, (tile.y)*gridDist, (tile.x+1)*gridDist, (tile.y+1)*gridDist);
            }
            else if(tile.status == DOWN_LEFT){
                renderer.triangle((tile.x)*gridDist, tile.y*gridDist, (tile.x+1)*gridDist, (tile.y)*gridDist, (tile.x)*gridDist, (tile.y+1)*gridDist);
            }
            else if(tile.status == UP_LEFT){
                renderer.triangle((tile.x)*gridDist, tile.y*gridDist, (tile.x+1)*gridDist, (tile.y+1)*gridDist, (tile.x)*gridDist, (tile.y+1)*gridDist);
            }
        }     
    }
}
renderer.end();

Does anyone know why this occurs and if it is possible to prevent?

Thanks in advance.

The camera only renders elements between the near and far planes. OpenGL远近平面

The default values are 0 (near) and 100 (far) in a orthographic camera , the values correspond to the distance between the plane and the camera, according to the documentation they must be positive https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/graphics/Camera.html#near but I have tried negative values without problems (plane located behind the camera)

The far and near values can be easily modified

camera.near = 1f;
camera.far = 50f;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM