I’ve made a test page that uses a dat.GUI to edit various properties of a PerspectiveCamera.
The PerspectiveCamera has a helper so I can see what’s going on, plus the scene has xyz axes in RGB colours.
Using the gui to update near, far, aspect & fov all work fine.
The problem is with testPerspectiveCamera.position.x
My code to update from the gui is as follows
function initGui(){
const controls = {
get near(){return testPerspectiveCamera.near;},
set near(value){
testPerspectiveCamera.near = value;
testPerspectiveCamera.updateProjectionMatrix();
testPerspectiveCameraHelper.update();
},
get far(){return testPerspectiveCamera.far;},
set far(value){
testPerspectiveCamera.far = value;
testPerspectiveCamera.updateProjectionMatrix();
testPerspectiveCameraHelper.update();
},
get aspect(){return testPerspectiveCamera.aspect;},
set aspect(value){
testPerspectiveCamera.aspect = value;
testPerspectiveCamera.updateProjectionMatrix();
testPerspectiveCameraHelper.update();
},
get fov(){return testPerspectiveCamera.fov;},
set fov(value){
testPerspectiveCamera.fov = value;
testPerspectiveCamera.updateProjectionMatrix();
testPerspectiveCameraHelper.update();
},
get positionX(){return testPerspectiveCamera.position.x;},
set positionX(value){
testPerspectiveCamera.position.x = value;
scene.updateMatrixWorld(); //?
testPerspectiveCamera.updateProjectionMatrix(); //?
testPerspectiveCameraHelper.update(); //?
}
};
const gui = new dat.GUI();
const perspectiveCameraFolder = gui.addFolder('testPerspectiveCamera');
perspectiveCameraFolder.add(controls, 'near', 0, 50);
perspectiveCameraFolder.add(controls, 'far', 0, 200);
perspectiveCameraFolder.add(controls, 'aspect', 0, 4);
perspectiveCameraFolder.add(controls, 'fov', 0, 100);
perspectiveCameraFolder.add(controls, 'positionX', -LIMIT, LIMIT);
}
On attempting to change testPerspectiveCamera.position.x, I see no change in the scene. I’m wondering if the matrix operations after updating x are wrong.
Could anyone tell me what I’m doing wrong?
Fiddle here: https://jsfiddle.net/fiddleuser01/0fsqogb1/49/
Using the same technique to control the position of a cube via a gui seems to work fine: https://jsfiddle.net/fiddleuser01/rezcpgh4/7/