I’m trying to get OrthographicTrackballControls to rotate around a raycasted point without the OrthographicCamera directly looking at it. So, I changed the mouse down event’s rotate part to this:
if (this.state === STATE.ROTATE && !this.noRotate)
{
const mX = (event.offsetX / this.screen.width) * 2 - 1;
const mY = -(event.offsetY / this.screen.height) * 2 + 1;
this._raycaster.setFromCamera(new THREE.Vector2(mX, mY), this.object);
let intersects = this._raycaster.intersectObjects(this._scene.children);
console.log("intersects: " + intersects.length);
if (intersects.length > 0)
{
let intersect = intersects[0];
let point = intersect.point;
console.log(point);
this.target.copy(point);
}
else
{
this.target.copy(this.center);
}
this.rotateStart.copy(this.getMouseProjectionOnBall(event.pageX, event.pageY));
this.rotateEnd.copy(this.rotateStart);
}
This successfully rotates around the point. However, on the initial button press, the camera jumps and looks at the point and the cursor becomes offset. Not only is this jarring, but the rotation feels odd.
Is there anyway to get it to rotate around a point without the camera jumping and looking at the point?
Um, you are modifying the target vector of the controls in mousedown(). This vector is actually used at the following place in order to orient the camera:
So, OrthographicTrackballControls ensures by default to orient the camera towards the defined target. I guess you have to make sure to decouple this vector from the rest of the logic.
Couldn’t you expose an additional 3D vector called OrthographicTrackballControls.lookAtTarget? You use it only for the lookAt() call and define an arbitrary value in your application.
I’ve tried that before, but the rotation code seems to rely on the target vector being set as the lookAt, it just rotates around what the camera’s lookAt is. I know a way to do it with a perspective camera but not orthographic.