Difference between target accessor and position accessor of arcRotate camera

Hello everyone,
I’m using arcRotate camera.
I’m trying to set the initial view/position of my mesh on the first render.
I want when my mesh renders it shows the front side of the mesh. I have tried a lot with position and target accessors of camera.
It works only when I don’t set following limits .
camera.upperAlphaLimit = -1.291982048345054;
camera.lowerAlphaLimit = -3.991982048345054;
camera.upperBetaLimit = 1.339665111804426;
camera.lowerBetaLimit = 0.339665111804426;
But when I set these limits, the camera displays the least right-side limit of mesh, up to which we can rotate or we have set limit .

My question is how to set the initial position of the mesh along with the alpha and beta limits.

camera settings are as following:

this.camera = new BABYLON.ArcRotateCamera(
“ArcCamera”,
Math.PI / 2,
Math.PI / 2,
2,
new BABYLON.Vector3(0, 0, 0),
this.scene
);

this.camera.panningInertia = 0.1;
camera.position = new BABYLON.Vector3(-374.60124575144977, 127.46023266658037, -156.14309287648427);
camera.target = new BABYLON.Vector3(-111.92360792644455, 58.820861573678755, -29.381458352302957);

camera.upperRadiusLimit = 350;
camera.lowerRadiusLimit = 100;
camera.wheelPrecision = 5;

camera.upperAlphaLimit = -1.291982048345054;
camera.lowerAlphaLimit = -3.991982048345054;
camera.upperBetaLimit = 1.339665111804426;
camera.lowerBetaLimit = 0.339665111804426;

camera.panningSensibility = 10;
camera.panningDistanceLimit = 50;
camera.panningOriginTarget = new BABYLON.Vector3(-111.92360792644455, 58.820861573678755, -29.381458352302957);

camera.fov = 0.5;
camera.attachControl(canvas, true);
this.cameraAttachToCanvas = true;

Thank you

There is a difference between setting a mesh’s position and changing the view of the camera which produces a relative change of mesh position in the viewing space rather than the world space.

Hope this playground offers an explanation

Play around with it by commenting different lines and changing values.

More description at

and

Thanks for a quick reply.
I understand there is difference between mesh’s position and view of camera.
I have a glb file which I load with assetManager. I don’t want to change any mesh position, I want to set view of camera and I have done that by writing following two lines of code

camera.position = new BABYLON.Vector3(-374.60124575144977, 127.46023266658037, -156.14309287648427);
camera.target = new BABYLON.Vector3(-111.92360792644455, 58.820861573678755, -29.381458352302957);

But when I define Alpha and beta limits by writing following lines
It changes the camera’s inital view.

    // camera.upperAlphaLimit = -1.291982048345054;
    // camera.lowerAlphaLimit = -3.991982048345054;
    // camera.upperBetaLimit = 1.339665111804426;
    // camera.lowerBetaLimit = 0.339665111804426;

Need help in setting camera’s view along with the setting of upper and lower alpha and beta limits.

As you can see here, when you set the position and target, the alpha of the camera is calculated by acos which will return a value from 0 to pi, so you should add pi * 2 to your upperAlphaLimit and lowerAlphaLimit.

1 Like

As you are using alpha and beta my assumption was that you are using an ArcRotateCamera, you cannot change the position of such a camera you can only change target, radius, alpha, beta and their limits as in the first playground (PG) I gave in my first post.

Also, as I did in that PG, setting limits on alpha and beta using + and - offsets on their values should not affect the other parameters.

Here is a similar PG with an imported model. You can also play around with the camera settings using the inspector and selecting the default camera.

EDIT Apologies you can set the position of an ArcRotate Camera, it does then change the radius, alpha and beta.

Here is a PG changing the position and setting limits

Thank you so much.
Your PG worked for me.
I set camera view by using
camera.alpha = -2.5707963267948966;
camera.beta = Math.PI / 2;
I had tried this before also. But surely was making some mistake.

But I have still a question that if we are setting camera view by using alpha and beta accessors, then by removing camera.position property why it affects my camera view ?

camera.position = new BABYLON.Vector3(x,y,z);
camera.target = new BABYLON.Vector3(x,y,z);
I have searched and gone through documentation also but can’t understand how it affects our camera view

There are two ways to set up the camera view for a given target.

  1. Set the radius, this gives a sphere around the target with the camera on the surface of the sphere. The angles alpha and beta position the camera on the surface of the sphere with the camera pointing towards the target.

  2. Set a camera position, the distance between the camera position and the target gives the radius for the sphere. Knowing the center of the sphere (ie the target’s position) and the radius and camera position then trigonometry is used to calculate the angles alpha and beta.

Having set a camera’s position altering the radius will move the camera towards or away from the target, changing alpha or beta will rotate the camera around the surface of the sphere.

Having set the radius and alpha and beta changing the position is likely to change the radius and alpha and beta. Alpha and beta will only remain the same if the change in position is along a vector parallel to the line joining the camera to the target…

Hope that answers you question

1 Like