简体   繁体   中英

three.js How to rotate an object around the camera coordinate?

var object = new THREE.CSS3DObject(element);

object.matrix=camera.matrix.clone();

object.matrix.setPosition(new THREE.Vector3(tarx,tary,tarz));

//object.applyMatrix(new THREE.Matrix4().makeRotationY(rY));
//object.applyMatrix(new THREE.Matrix4().makeRotationZ(rX));

It will rotate about the world coordinate Y,but I just want to rotate about the camera

1 - Create an object who copy camera.position (like you have done)
2 - Add a satellite to this object

var orbit = 100;

var geometry = new THREE.BoxGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial( { color: 0xffff00, side: THREE.DoubleSide } );
satellite = new THREE.Mesh( geometry, material );
satellite.position.set(orbit,0,0);

Add satellite to object

object.add( satellite );

If you rotate object
the satellite rotate around the camera coordinate.

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