简体   繁体   中英

always rotate an object up in three.js

I am not good at 3d calculation, and I need help here.

I have an earth, which is a sphere in my scene, and I am using OribitControl to "rotate" it (actually OribitControl rotates camera).

I need a function, something would like rotateUp(rad) to rotate the earth up, no matter what's the position of camera.

The problem is, my rotateUp now is:

earth.rotation.x -= rad

This would rotate earth up if camera in the initial position, but if camera rotate 180 deg, this rotateUp function would actually rotates the earth down.

How to implement this function? Thanks

I found a solution myself:

function rotateUp (rad) {
  const v = new THREE.Vector3()
  v.setFromMatrixColumn(camera.matrix, 0 )
  v.multiplyScalar(-rad)
  earth.rotation.x += v.x
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM