Problem with camera frustum [SOLVED]

Hello everyone,

I have a problem with the intersection with the frustum of the camera

I want to use the camera’s frustum to determine whether objects are inside or outside of the camera.

I created a camera by specifying the following values:

 Camera cam = new Camera (1024,768);
 cam.setLocation (_positionLight);
 Float near = (pVoxel.distance (_positionLight)) - 0.5f;
 Cam.setFrustum (near, _distanceMax, -0.5f, 0.5f, 0.5f, -0.5f);
 Cam.lookAt (pVoxel, new Vector3f (0,1,0));

PVoxel : is the position of my cube that must block light
Near : is the distance between my light and the cube, it is the place of the plane of the frustum

I do this to determine if an object is behind a cube that is illuminated by a light source. If the object is in the frustum, I generate the mesh with a suitable vertexcolor (simulation of the shadow).

In order to verify that my frustum corresponds well to the projection of my light, I have drawn lines from my position of light to the nearest points between the voxel and the frustum planes.

Everything seems correct.

I then use a boudingBox or a boundingSphere to test whether the object behind my voxel is inside the frustum or not.

I save the state of the plan of the boudingvolume before testing whether it is contained in the frustum as indicated in the documentation

Unfortunately, the method contained in the camera object does not seem to work.

Can you help me ?

Here below a video showing what I try to do, cubes are shaded while their boudingbox is not in the frustum

https://youtu.be/APKFJb9lYE8

Given your description I’m not entirely sure what the video is supposed to be showing.

That being said, can you explain what you are actually trying to do? It seems like the super expensive way to do anything lighting related considering your whole world is on a grid.

I will try to explain what I am trying to do, unfortunately English is not my native language.

I program a cube display demo (Style MineCraft)

The world is composed of a grid including a set of chunk.

Each chunk is composed of a size of 16 * 16 * 256.

A custom mesh is generated for each chunk. Then the mesh is attached to a Node.

When adding a cube (voxel) or deleting a cube, the custom mesh of the chunk is recreated.

The empty or filled spaces (voxel) are included in a grid vector [256 * 256 * 256]

It works very well.

I am now trying to find a technique to generate light.

When I add a light, (I do not use pointlight). I want the blocks (voxel) to light up. This works fine, I modify the VertexColor cubes and I recreate the mesh. This simulates light.

Now I try to simulate the shadow.

I have tried several different techniques but they have not been conclusive.

Now I test a new technique where I would like to use the frustum of a camera to determine what is in the frustum.

The camera is generated based on the position of the light. The Near Plan is located near the cube that will generate the shadow.

The next step is to check if the empty slots are included in the generated frustum.

To do this, I create a boundingbox or a boundinsphere for each empty slot located at a distance greater than that of the distance between the cube and the light.

I then check if the boudingbox is contained in the frustum

If it’s in it, then it’s in the shade.

I only notice that when I create a boudingbox that is not included in the frustum.

The Camera.contains (boudingbox) method returns Camera.FrustumIntersect.Inside.

I most likely have to misconfigure my frustum.

I hope my explanations are clear.

thank you in advance

PS: Still sorry for my English, I use a translator

Thoced

What i’m trying to do :

What happens, the boundingbox generated for the empty slots that should be outside the frustum, are considered during the test as inside.:

I found my problem, before the intersection test, I had to call the method: getPlaneState()

Int ps = camera.getPlaneState ();

// then force the plane state to 0
Camera.setPlaneState (0)

// Intersection calculation
Camera.contains (…) == Camera.FrustumIntersect (Outside))
{

}

// reset the plane state
Camera.setPlaneState (ps)