# Tilt

it is possible to set a maximum and minimum value for the tilt?

Just to verify: by tilt you mean angle between the forward vector and the http://en.wikipedia.org/wiki/Nadir ? Tilt of the camera? Using what system to change the tilt?

then when I move the camera in 3D with the wheel I need to lock in a certain angle for example the value tilt of the camera fixed a maximum at 1.5 and a minimum 1 ...

When you say with the wheel I’m assuming when you press the mousewheel = middlebutton or press ctrl-leftbutton while moving the mouse forward and backward. I probably should have assumed that, though the camera tutorial app does provide another method.

1.5 radians tilt ~= 86 degrees tilt ~= -4 degrees pitch

1.0 radians tilt ~= 57 degrees tilt ~= -33 degrees pitch

I usually move around with a 3DMouse so I’m just now looking at the default controls. In Scene/ScreenSpaceCameraController.js function rotate3D if you disable the statement camera.rotateUp(deltaTheta); you will disable tilt control. So what you could do is:

get the pitch of the camera

find out how much the result exceeds the bounds (if at all)

add or subtract that amount from deltaTheta to get it in bounds

then do the rotate.

does not have a solution that does not have to change the source code but rewrite some method or use a feature that controls that limit?

I understand your idea, but as I to using compact file cesium would be in the best interest of a rewrite method or use something ready in the latter case I'll have to really change the source folder file.

Thank U

Well Camera.prototype.rotateUp calls function rotateVertical which uses constrainedAxis to prevent the camera from rotating past vertical.

What you could do without modifying the source code is rotate the camera back to within limits if it rotates out of limits. To obtain the vector to rotate around cross camera.direction with the nadir vector. I’d assume the camera retains the same transform if you didn’t let go of the button yet.

Actually with the negation of Nadir (up), although you could alternatively cross with Nadir then simply rotate in the opposite direction.

you could not do a simple example, modifying the source code in the file Camera.js, rotatevertical method? I could not set a minimum and maximum size because if it passes the specified size, the view is locked ... basically I tried to put an if with the pitch property, such as:

https://github.com/AnalyticalGraphicsInc/cesium/blob/1.6/Source/Scene/Camera.js#L1399

to lock the screen, but not back it exceeds the size.

If you wanted to do it by modifying Camera.prototype.rotateUp you could modify this section

var dot = Cartesian3.dot(p, constrainedAxis);
var angleToAxis = CesiumMath.acosClamped(dot);
if (angle > 0 && angle > angleToAxis) {
angle = angleToAxis - CesiumMath.EPSILON4;
}

dot = Cartesian3.dot(p, Cartesian3.negate(constrainedAxis, rotateVertScratchNegate));
angleToAxis = CesiumMath.acosClamped(dot);
if (angle < 0 && -angle > angleToAxis) {
angle = -angleToAxis + CesiumMath.EPSILON4;
}

``

The first angleToAxis is the angle from camera.position to the ‘rotational north pole’. This angle is also tilt (angle between camera.direction and ‘rotational south pole’.) You don’t want this to go lower than 1.0 radians, so on the top section

var angleToAxis = CesiumMath.acosClamped(dot);
if(angleToAxis < 1.0){angleToAxis=0;} //add this line

``

The 2nd angleToAxis is the angle from camera.position to the ‘rotational south pole’. Math.PI-angleToAxis is tilt (angle between camera.direction and ‘rotational south pole’.) You don’t want this to go higher than 1.5 radians, so on the bottom section

angleToAxis = CesiumMath.acosClamped(dot);
if((Math.PI-angleToAxis) > 1.5){angleToAxis=0;} //add this line

``

I just tested it and it seems to work just fine.

Actually this is modifying rotateVertical, which is called by Camera.prototype.rotateUp.

While this works, it might mess up other stuff that uses this function for other things that might not want this constraint. If it does I’d just modify deltaTheta in Scene/ScreenSpaceCameraController.js function rotate3D mentioned on one of my previous post. Or just rotate it back if you don’t want to modify the source, but that would have an annoying bounce back effect.

if ((Math.PI-angleToAxis)> 1.5) {angleToAxis = 0;} // add this line

This line of code, solve my problem. Thank U. this helped me a lot!

You’re welcome, I’m glad I could help. There are some js files that end in Spec such as GeometryRenderingSpec.js that do use rotateUp hence rotateVertical, I’m not sure what affect this will have on them. Perhaps tilt constraints could be added in future versions of Cesium, maybe using optional additional parameters.

is working in parts because ta not rotating the world. The slope is the expected!

Ha! It traps you between northern latitudes 4 to 33 when you leftclick pan. Well I guess that unless you want to keep the camera in that latitude range you’ll have to do the other method instead. Apparently panning also uses this function.

var deltaPhi = rotateRate * phiWindowRatio * Math.PI * 2.0;
var deltaTheta = rotateRate * thetaWindowRatio * Math.PI;
//start code injection
if(defined(constrainedAxis))
{
var starttilt = Cartesian3.dot(camera.direction,constrainedAxis);
starttilt = Math.PI-Math.acos(starttilt);
var endtilt = starttilt+deltaTheta;
if(endtilt<1.0){deltaTheta += 1.0 - endtilt;}
if(endtilt>1.5){deltaTheta -= endtilt - 1.5;}
}
//end code injection

``

Here’s working code for the other method. This is in Scene/ScreenSpaceCameraController.js function rotate3D. Sometimes constrainedAxis isn’t defined so I added the if.

should not be the same as mine, it was not cool.
function rotate3D(controller, startPosition, movement, constrainedAxis, rotateOnlyVertical, rotateOnlyHorizontal) {

rotateOnlyVertical = defaultValue(rotateOnlyVertical, false);
rotateOnlyHorizontal = defaultValue(rotateOnlyHorizontal, false);

var scene = controller._scene;
var camera = scene.camera;
var canvas = scene.canvas;

var oldAxis = camera.constrainedAxis;
if (defined(constrainedAxis)) {
camera.constrainedAxis = constrainedAxis;
}

var rho = Cartesian3.magnitude(camera.position);
var rotateRate = controller._rotateFactor * (rho - controller._rotateRateRangeAdjustment);

if (rotateRate > controller._maximumRotateRate) {
rotateRate = controller._maximumRotateRate;
}

if (rotateRate < controller._minimumRotateRate) {
rotateRate = controller._minimumRotateRate;
}

var phiWindowRatio = (movement.startPosition.x - movement.endPosition.x) / canvas.clientWidth;
var thetaWindowRatio = (movement.startPosition.y - movement.endPosition.y) / canvas.clientHeight;
phiWindowRatio = Math.min(phiWindowRatio, controller.maximumMovementRatio);
thetaWindowRatio = Math.min(thetaWindowRatio, controller.maximumMovementRatio);

var deltaPhi = rotateRate * phiWindowRatio * Math.PI * 2.0;
var deltaTheta = rotateRate * thetaWindowRatio * Math.PI;

//start code injection
if(defined(constrainedAxis))
{
var starttilt = Cartesian3.dot(camera.direction,constrainedAxis);
starttilt = Math.PI-Math.acos(starttilt);
var endtilt = starttilt+deltaTheta;
if(endtilt<1.0){deltaTheta += 1.0 - endtilt;}
if(endtilt>1.5){deltaTheta -= endtilt - 1.5;}
}
//end code injection

if (!rotateOnlyVertical) {
camera.rotateRight(deltaPhi);
}

if (!rotateOnlyHorizontal) {
camera.rotateUp(deltaTheta);
}

camera.constrainedAxis = oldAxis;
}

I’m not sure I know what you mean.

i need vision equals:

but is not rotating properly up and down when the vision is far, I would have fixase slope at an angle like the image ...

thks

So you want a different tilt range? I modified the code so you can enter in degrees and it will convert to radians. Here’s 10 to 60 degrees tilt range, which you can easily modify:
if(defined(constrainedAxis))
{
var minTilt=10/180Math.PI;var maxTilt=60/180Math.PI;
var tilt = Cartesian3.dot(camera.direction,constrainedAxis);
tilt = Math.PI-Math.acos(tilt);
tilt += deltaTheta;
if(tilt<minTilt){deltaTheta += minTilt - tilt;}
if(tilt>maxTilt){deltaTheta -= tilt - maxTilt;}
}

``