[SOLVED] Chase Camera Hides the surface of terrain

Hi there

i just want to know why chase camera hides the scene(or clipping it ) when i points it to up & forward

code:
only physics code :

    public void addRigidShape(String nodeName, float mass, Vector3f gravity) {
        Spatial spatial = rootNode.getChild(nodeName);
        RigidBodyControl rigidBodyControl = new RigidBodyControl(CollisionShapeFactory.createBoxShape(spatial),mass);
        spatial.addControl(rigidBodyControl);
        physics.getPhysicsSpace().add(rigidBodyControl);
    }

& its scale is :

terrain.setLocalScale( new Vector3f(5f,5f,5f));

I think i need to add thickness to the map

The near plane is probably set to 1.0 which is the default. This means anything less than 1 unit from the camera is not rendered. Set the near plane closer, something small like 0.1f

float fov = 45.0f;
float near = 0.1f;
float far = 1000.0f;

float aspect = (float)camera.getWidth() / (float)camera.getHeight();
camera.setFrustumPerspective(fov, aspect, near, far);

Note that this has an effect on the depth map. Don’t set it too low.

1 Like

I tried this but it didinot work so , i headed to javaDoc & used setFrustumBottom to get the camera renderer state up a little bit (as the default state = -0.4f its down on y-axis i guess) & it works:


Code:

        cam.setFrustumBottom(-0.1f);
        chasecam = new ChaseCamera(cam, roverNode, inputManager);
        chasecam.setEnabled(true);
        chasecam.setDefaultDistance(-12f);

        chasecam.setRotationSpeed(2);
        chasecam.setHideCursorOnRotate(true);
        rootNode.attachChild(roverNode);

but i think it ruined the hovertank render a little bit :
the real hovertank width

If you play with things you don’t understand, you get results you don’t understand.

:man_shrugging:

You should probably add a collision shape, probably a sphere, around your camera so it can’t clip through your terrain.

2 Likes

i was thinking of adding a cube as a base to the terrain but i thought it will cause problems with physics faces , isnot it really ?

Why would that make any difference? The camera still won’t collide with it, because it’s not collidable. Hence I said add a collidable shape around the camera so it can collide. And preferably something circular so it doesn’t get hung up on corners.

1 Like

are frustum planes locations of the renderer cam constant among all moniters or devices?

This is what a viewport is and how it is constructed. The only things I modify are field of view, near and far. The rest should pretty much be left alone unless you have a very good reason not to. And by that I mean you know exactly what it does and why it does it. I can tell you that you do not need to. You need to add a collision shape around the camera so it doesn’t clip through collidable objects.

2 Likes

okay, i figured it out , iknew why the renderer is ruined a little bit , that’s because i have changed the location of the bottom frustum plane only , but it seems i must add that value that’s subtrated to the top frustum so i get my values back again so its like translating the whole image up a little bit by 0.3 of units:


         /**
         * getFrustumBottom -> gets the bottom plane location= -0.4 approx. then adding 0.3 -> -0.1 then we are translating the render 
         * plane upward by 0.1 uints
         * 
         */
        cam.setFrustumBottom(cam.getFrustumBottom()+0.3f);
        /**
         * getFrustumTop -> gets the top plane location = 0.4 approx. then adding 0.2 -> 0.6 then we have compensated whats subtracted from the bottom frustum plane
         */
        cam.setFrustumTop(cam.getFrustumTop()+0.2f);
        chasecam = new ChaseCamera(cam, roverNode, inputManager);
        chasecam.setEnabled(true);
        chasecam.setDefaultDistance(-12f);

        chasecam.setRotationSpeed(2);
        chasecam.setHideCursorOnRotate(true);

@jayfella Thank you , I will try this method in case I faced the clipping problem with other spatials