Question

Setup a simple scene here:

http://jsfiddle.net/majman/Sps3c/

I was initially trying to demonstrate a problem I was having with rotating a parent container while having the camera maintain it's relative offset position, but when setting up this example I couldn't even adjust the camera's initial position.

Current Problem:

// camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 5, 150);
camera.position.z = 50; // this doesn't work?

// object to contain camera & helper
cameraContainer = new THREE.Object3D();
cameraContainer.rotation.order = "YXZ"; // maybe not necessary

// add to container
cameraContainer.add(camera);
scene.add(cameraContainer);

Now when rotating the cameraContainer, the camera's rotation follows - but I'd like the camera's position to be offset from the cameraContainer. I'm unable to modify any position properties for some reason.

Was it helpful?

Solution

Your code is working fine. You are confused because the CameraHelper is not displaying the camera in its actual position. You need to add the CameraHelper as a child of the scene.

// camera helper
cameraHelper = new THREE.CameraHelper( camera2 );
scene.add( cameraHelper );

updated fiddle: http://jsfiddle.net/Sps3c/1/

Tip: I added an OrbitController to your demo for a better view of the situation.

three.js r.66

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top