Hi everyone, I would like to write a test class to debug the visual cone of the camera as shown in the example image.
I created two views on the test environment by splitting the screen in the following way.
private void splitScreen() {
Camera camera = cam.clone();
camera.setViewPort(0f, 1, .5f, 1f);
camera.setLocation(new Vector3f(-15f, 5f, -10));
camera.lookAt(new Vector3f(1, 1, 0), Vector3f.UNIT_Y);
ViewPort vp = renderManager.createMainView("TopCam", camera);
vp.setClearFlags(true, true, true);
vp.attachScene(rootNode);
}
I created the camera cone shape with the following code.
public static Geometry createViewingFrustum(Camera cam) {
Vector3f[] points = new Vector3f[8];
for (int i = 0; i < 8; i++) {
points[i] = new Vector3f();
}
ShadowUtil.updateFrustumPoints2(cam, points);
WireFrustum wireFrustum = new WireFrustum(points);
Geometry frustumGeo = new Geometry("Camera-Frustum", wireFrustum);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.White);
frustumGeo.setMaterial(mat);
frustumGeo.setCullHint(Spatial.CullHint.Never);
frustumGeo.setShadowMode(RenderQueue.ShadowMode.Off);
return frustumGeo;
}
I would like the cone to follow the position and rotation of the camera during the update cycle, but after many attempts I could not find the solution.
Here is the code and the result i get.
public class AvatarControl extends AbstractControl {
private Camera camera;
private Geometry viewingFrustum;
...
public AvatarControl(Node rootNode, Camera camera) {
this.camera = camera;
this.viewingFrustum = createViewingFrustum(camera);
rootNode.attachChild(viewingFrustum);
}
@Override
protected void controlUpdate(float tpf) {
...
viewingFrustum.setLocalTranslation(camera.getLocation().clone());
viewingFrustum.setLocalRotation(camera.getRotation().clone());
}
}
Could someone help me please?