Pitch camera while zooming - mapbox-gl-js

I'm trying to change the pitch of the mapbox camera while zooming. I know I can set a default/max pitch level and that the user is able to change the pitch of the camera by themselves, I'm however looking for a way to map a zoom level range to a pitch range. While scrolling/zooming I want the pitch to change according to this range.
I've tried the following:
function onMapboxZoom(e: MapboxEvent) {
const zoom = e.target.getZoom();
const pitch = mapRange(zoom, 6, 10, 0, 65);
e.target.setPitch(pitch);
}
The problem I'm having with this approach is that I think the zoom interpolation that mapbox uses to create a smooth zooming effect is cancelled by my manual pitch change. The result is that the smoothness of zooming is gone and that it requires a lot of scroll events to zoom in properly. Which makes sense I guess. I was wondering if anyone has tackled this problem before and if/how this can be achieved while maintaining a smooth zoom behavior.
Thanks!

Related

How to adjust max render distance in SceneKit

Currently in my SceneKit scene for a game in iOS using Swift the render distance is very limited, there is a noticeable cutoff in the terrain
of the players perspective, i cant find a "max render distance" setting anywhere and the only option ive seen so far is to just cover it with fog, im clearly missing something as ive seen plenty of games with larger render distances but after searching across google, documentation and stack overflow i cant seem to get an answer, can anyone help?
Camera Far Clipping Plane
To adjust a max distance between the camera and a visible surface, use zFar instance property. If a 3D object's surface is farther from the camera than this distance, the surface is clipped and does not appear. The default value in SceneKit is 100.0 meters.
arscnView.pointOfView?.camera?.zFar = 500.0
Im a dingdong and figured out what i was missing.
What i was looking for was a setting in the camera that your scene is using as the point of view, theres a setting called 'Z clipping" which clips out anything closer then the "near" value or further then the "far" value, and by default far is set to 100 units. just adjust that setting either in code or within XCODE and set it to a higher value to view the entire scene.

MapBox - link zoom level to pitch

I am trying to have a fixed relationship between zoom level and camera pitch.
No matter how we zoom (by scroll, touch, flyTo() or fitBounds()), I would like to always have the same pitch at the same zoom level.
This would probably require disabling manual pitching, but this is fine.
Currently, I can only do this with the flyTo() method (which allows me to enter a value for the pitch.
map.flyTo({
center,
zoom,
speed: 1.2,
pitch: Scales.pitchScale(zoom),
easing(t) {
return t;
},
essential: true,
});
If I try to add the same call to my scale function
Scales.pitchScale(zoom),
on a zoom event, it makes zooming on mobile devices really slow.
Is there anything built into Mapbox?

Detecting Zoom Level on iPhone

I'm using the UIImagePickerController to control the camera and overlay millimeter tick marks in preview for measuring closeup macro shots, and I'd like to be able to detect the current zoom level and scale it properly.
Is there any way to determine the current zoom level in camera preview?
Unfortunately no, since the UIImagePickerController API doesn't give you access to the camera zoom level, nor to any subviews or other properties that might have access to that information.
As Michael Dautermann points out, based on the answer to this question, you could use the cameraViewTransform property of UIImagePickerController to implement your own zoom by setting up the right CGAffineTransform and also the right pinch gesture to zoom in/out. Since you'd be controlling the zoom yourself, you'd always know the zoom level and be able to use it to adjust the tick marks.

Zooming in/out and painting in openGL

I've recently had some issues implementing a zooming feature into a painting application. Please let me start off by giving you some background information.
First, I started off by modifying Apple's glPaint demo app. I think it's a great source, since it shows you how to set up the EAGLView, etc...
Now, what I wanted to do next, was to implement zooming functionality. After doing some research, I tried two different approaches.
1) use glOrthof
2) change the frame size of my EAGLView.
While both ways allow me to perfectly zoom in / out, I experience different problems, when it actually comes to painting while zoomed in.
When I use (1), I have to render the view like this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(left, right, bottom, top, -1.0f, 1.0f); //those values have been previously calculated
glDisable(GL_BLEND);
//I'm using Apple's Texture2D class here to render an image
[_textures[kTexture_MyImage] drawInRect:[self bounds]];
glEnable(GL_BLEND);
[self swapBuffers];
Now, let's assume I zoom in a little, THEN I paint and after that, I want to zoom out again. In order to get this to work, I need to make sure that "kTexture_MyImage" always contains the latest changes. In order to do that, I need to capture the screen contents after changes have been made and merge them with the original image. The problem here is, that when I zoom in, my screen only shows part of the image (enlarged) and I haven't found a proper way to deal with this yet.
I tried to calculate which part of the screen was enlarged, then do the capturing. After that I'd resize this part to its original size and use yet another method to paste it into the original image at the correct position.
Now, I could go more into detail on how I achieved this, but it's really complicated and I figured, there has to be an easier way. There are already several apps out there, that perfectly do, what I'm trying to achieve, so it must be possible.
As far as approach (2) goes, I can avoid most of the above, since I only change the size of my EAGLView window. However, when painting, the strokes are way off their expected position. I probably need take the zoom level into account when painting and re-calculate the CGPoints in a different way.
However, if you have done similar things in the past or can give me a hint, how I could implement zooming into my painting app, I'd really appreciate it.
Thanks in advance.
Yes, it is definitely possible.
When it comes to paint programs, you should be keeping a linked list or tree of objects to draw for easy insertion / removal. When the user stops painting, (i.e. touchesEnded), you add objects to the data structure containing your scene.
When your user zooms you need to modulate the coordinates of the objects you are drawing with respect to the current viewport, projection, and modelview transforms. In your case, you're not changing the viewport or the modelview transforms so you need only account for the projection transform. You could also implement your zoom using a translation and scale on the modelview matrix but I'll ignore that case for simplicity because it involves inverting the transforms.
The good news is that you are using an orthographic projection so world coordinates correspond to window coordinates when no zooming is in effect. The "world" in your case is a simple canvas that probably corresponds to the size of the device in window coordinates.
Before you add an object to your scene data structure, convert all of the coordinates, using the current projection transform (i.e. the parameters to the glOrthof() call) to world coordinates (i.e. full canvas coordinates). You'll only remain sane if you keep all things in your model in the same coordinate space.
To convert the coordinates, assuming you can never zoom out past full device dimensions in your glOrtho() call, you'll have to scale them down proportional to the ratios of your zoomed ortho dimensions to your unzoomed ortho dimensions then bias them by the difference between your zoomed ortho bottom, left values and those of the original unzoomed ortho values.

preventing zooming at some limit

In my ipad openGL based application I am drawing a 2D and 3D object and rotating it according to the user's finger motion....On pinching the screen user is enable to zoom those objects...But what I want is to prevent zooming the object at some limit, say more than 2x of the object size user cannot zoom in and user cannot zoom out more than object's original size
I am zooming the object with help of "CATransform3DScale"
Any hint please....
Thanks in advance and help appreciated.
If you are using the UIPinchGestureRecognizer and setting the scale value of it directly as your 3D scale value then just do something like
if(scale >= 2.0f){
scale = 2.0f;
}
that's basically what i do.