Three.js Device Orientation Controls to point at a specific target on load

无人久伴 提交于 2020-01-23 10:39:51

问题


I'm using the Device Orientation Controls in Three.js to set up a web application for Google Cardboard. When I load the scene, the default target of the camera is the Y direction (Z on the phone) where there might not be any objects. I'd like to define a direction before loading. Does anyone have any suggestions on how to do this without the need to rotate the objects in the scene?

Thanks in advance for your help!


回答1:


Add your camera to a THREE.Object3D(). Rotate the parent object.




回答2:


I just had the same problem as well, and the problem seemed to be due to my outdated JS files that I just copy&pasted from the zip file downloaded from https://vr.chromeexperiments.com.

Replace:

  <script src="js/third-party/threejs/three.js"></script>
  <script src="js/third-party/threejs/StereoEffect.js"></script>
  <script src="js/third-party/threejs/DeviceOrientationControls.js"></script>
  <script src="js/third-party/threejs/OrbitControls.js"></script>

with:

<script src="https://cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script> 
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/controls/OrbitControls.js"></script> 
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/effects/StereoEffect.js"></script> 
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/controls/DeviceOrientationControls.js"></script> 

solved my problem.




回答3:


Use the lookat funcion

var vector = new THREE.Vector3( 1, 0, 0 );
camera.lookAt ( vector );


来源:https://stackoverflow.com/questions/35441349/three-js-device-orientation-controls-to-point-at-a-specific-target-on-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!