Oribit camera to a specific position?

Dear forum, I have looked all over for this. I am creating a globe with clickable points that should cause the camera to rotate around the globe so that he clicked position is in the center. I can’t wrap my head around it. Is there an example of this out there that anyone can recommend? I am currently using the orbitCamera and am trying to build the functionality.

I am getting the position of the point from rayCasting. The point is inside a parent node that contains the globe. I am not sure if I need to convert the raycast position to a global position, and then I am using a fromToRotation method to get the difference in location. I am converting the quaterion to pitch and yaw. But I am not getting the result I want.

I am sure this has been done before, is there an example?

Hey Brian. I’ve made this little demo by adding one additional method to the OrbitCamera demo. Starting on line 307 of orbit-camera.js

OrbitCamera.prototype._setRotationTarget = function (entity) {
    entity.lookAt(this._modelsAabb.center);
    var quat = entity.getRotation();

    this.yaw = this._calcYaw(quat);
    this.pitch = this._clampPitchAngle(this._calcPitch(quat, this._targetYaw));
};

This is wired up on line 239 to listen to an event: orbitcamera:lookat, which I dispatch on raycast on line 42 in the shape-picker.js file.

Look At Point On Sphere

Let me know if this helps at all!

4 Likes