我试图捕捉FreeCamera的位置和平移角度或旋转角度,以便稍后可以使用完全相同的视图重新定位相机。
(我正在使用http://www.babylonjs-playground.com/上的碰撞示例的改变版本)
我似乎能够得到camera.position.x,camera.position.y和camera.position.z确定但是camera.cameraRotation.y总是得到零。
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.
最满意答案
根据http://www.html5gamedevs.com/topic/11380-rotate-camera-around-z-axis/与upVector:
camera.noRotationConstraint=true; camera.upVector = new BABYLON.Vector3(1, 0.2, -1);游乐场示例: http : //www.babylonjs-playground.com/#2FNBTG#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); }更多推荐
发布评论