在Babylon.js中,我如何获取/设置FreeCamera的旋转或平移角度?(In Babylon.js how can I get/set a FreeCamera's rotatio

编程入门 行业动态 更新时间:2024-10-24 18:27:21
在Babylon.js中,我如何获取/设置FreeCamera的旋转或平移角度?(In Babylon.js how can I get/set a FreeCamera's rotation or pan angle?)

我试图捕捉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); }

更多推荐

本文发布于:2023-08-05 08:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角度   FreeCamera   js   Babylon   angle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!