1

I am trying to have the camera orbit around an arbitrary axis in world space. I've already spent so many hours trying to solve this issue without luck. I do not want to add a library like THREE.OrbitControls just to have this feature. Can anyone tell me what I'm doing wrong in the following code?

Camera.prototype.orbit = function(axis, spd, pt) {
    var axis = axis.normalize(),
        currCamQuaternion = new THREE.Quaternion(this.position.x, this.position.y, this.position.z, 0),
        rotQuaternion = new THREE.Quaternion();

    rotQuaternion.setFromAxisAngle(axis, spd);
    var halfCamQuaternion = rotQuaternion.clone().multiply(currCamQuaternion),
        fullCamQuaternion = halfCamQuaternion.clone().multiply(rotQuaternion.clone().conjugate());

    this.position.copy(new THREE.Vector3(fullCamQuaternion.x, fullCamQuaternion.y, fullCamQuaternion.z));
    this.lookAt(pt);
}
Ice101781
  • 105
  • 10
  • 2
    http://stackoverflow.com/questions/31953608/rotate-object-on-specific-axis-anywhere-in-three-js-including-outside-of-mesh/32038265#32038265 – WestLangley May 04 '17 at 06:00
  • It seems like my original implementation (as well as your own, thank you @WestLangley) works...I found out that the problem is the camera.lookAt() function. Is there anyway to use the lookAt() function without causing unintended motion? Please see: https://jsfiddle.net/3svxpkv6/16/. – Ice101781 May 04 '17 at 16:39
  • 2
    One option: https://jsfiddle.net/3svxpkv6/19/. Also, do not call "new" unnecessarily in tight loops. Create one instance and reuse it. – WestLangley May 04 '17 at 19:17

0 Answers0