2

I am trying to capture a FreeCamera's location and pan angle or rotation so I can reposition the camera later with the exact same view.

(I am working with an altered version of the Collision example at http://www.babylonjs-playground.com/)

I seem to be able to get camera.position.x, camera.position.y and camera.position.z ok but camera.cameraRotation.y always yields zero.

user2016210
  • 119
  • 4
  • 13

2 Answers2

1

According to http://www.html5gamedevs.com/topic/11380-rotate-camera-around-z-axis/ with upVector:

camera.noRotationConstraint=true;
camera.upVector = new BABYLON.Vector3(1, 0.2, -1);

Playground example: http://www.babylonjs-playground.com/#2FNBTG#1

Alqin
  • 1,305
  • 3
  • 16
  • 35
1

The method I've come up with that seems to work reliably is to first collect the various camera stats:

var firstPosition=camera.position.x.toFixed(2)+"/"+camera.position.z.toFixed(2)+"/"+camera.rotation.x.toFixed(2)+"/"+camera.rotation.y.toFixed(2)+"/"+camera.rotation.z.toFixed(2);

which I store in a database. Then, when needed, I get the camera position by:

var firstArray=firstPositionL.split("/");
var firstX=Number(firstArray[0]);
var firstZ=Number(firstArray[1]);
var firstRx=Number(firstArray[2]);
var firstRy=Number(firstArray[3]);
var firstRz=Number(firstArray[4]);

Then when recreating the scene I add this just at the last of the scene creation. I put it into a delay function to give the scene time to establish itself:

var myVar = setInterval(function(){ myTimer() }, 1000);
function myTimer() {            
  camera.position.x=firstX;
  camera.position.z=firstZ;
  camera.rotation.x=firstRx;
  camera.rotation.y=firstRy;
  camera.rotation.z=firstRz;
  clearInterval(myVar);
}
user2016210
  • 119
  • 4
  • 13