Implement custom map model with navigation handling 1 finger, 2 finger gestures

Started by Gopinath, January 06, 2014, 07:06:44 PM

Previous topic - Next topic

Gopinath

Hi,

I have a landscape map model with streets name boards all in separate models. I have now loaded it successfully and could rotate the map with all objects. Now the camera is placed with cameraDistance = 135, cameraAngle = 1.18f.

Now customer is expecting to navigate it like google maps where the vertical gesture (1 finger) should move the map object similar to road navigation (in 3D). I have now made the camera to look at the center of the map.

Any suggestion on how to achieve this. Also for single finger the map has to be navigated and with double finger gesture the map has to rotate. Zoom and Pan option with 2 fingers are already taken care from cube sample. Pls help !!

EgonOlsen

Sooo...basically, the camera should move to (or at least close to) where the user has touched the map?

Gopinath

May be yes. It should be like dragging the map based on the vertical swipe

Gopinath

Hi EgonOlsen,

Need your support for me to move forward on this. Pls help me.

EgonOlsen

So you want to move the camera if the user drags on screens? That's not too hard. You just have to implement a touch event listener in your Activity and evaluate action_up, _down and _move you calculate the current delta between the initial touch point and the position to which the user moved his finger. You can then move the camera according to this value (i.e. divide it or multiply it by some magic value). There's also some helper class in Android that eases handling of gestures IIRC, but i've never used it.

Wyatt

About those Android helper classes:

http://www.vogella.com/tutorials/AndroidTouch/article.html

From those you can extract the amount of movement.

Do your zoom and pan with Camera.setPosition, changing the X, Y, and Z values based on the movement.

Gopinath

Thank you EgonOlsen for your inputs. Instead of moving the camera, I have moved the landscape where all the other elements were added as child to it. Also I had created a dummy object and initialized with the center of the map. Then I made the camera to look up the dummy object so I got the map moved properly.

Thanks wyatt. I have modified the code that had the zoom effect included to track the differential movement in x axis. Using that I have updated the onDrawFrame method to rotate the landscape inside necessary condition so that only when 2 finger gesture is made, the rotation happens.

Thanks again all for your inputs.

Gopinath

As both the map rotation as well as zoom effect is handled in the 2 finger gesture, even the slight change in the fingers movements between during the rotation, it tries to zoom also. So both these actions interchange during the any of the activity. Pls suggest on how to avoid it

EgonOlsen

Just add some dead zone, so that minimal changes don't cause a zoom effect.

Gopinath

Thanks for your suggestion. I tried to change the code in onTouch event by adding a condition that the zoomvalue is updated only if its value is beyond certain difference with the previous value. But it impacts the zooming. So either I don't know about dead zone properly or I am missing somewhere. Pls help EgonOlsen.

EgonOlsen

I meant something a little different...only start zooming if the pinch value surpasses some value. After it does, zoom like usual until the pinching stops. Then apply the threshold again. I'm not sure if that works in this case though. It's just an idea.

Gopinath

I tried to include your suggestion. Based on that in the setCameraPosition() function, I tried to include if condition to know the diff in the cameraDistance with that of previous value and set the camera position if it is beyond 2.0f or similar value. But this does not apply properly as the initial value itself is not applied. So not sure what else to be done for this to fix. Need help.

kkl

Hi,

You may wanna try GestureDetector for panning and ScaleGestureDetector for zooming.
GestureDetector gives you the values of the moved distance. Multiply the values by a constant to fit to your camera moving distance.

Hope that helps ;)

EgonOlsen

Quote from: Gopinath on January 16, 2014, 06:15:34 PM
I tried to include your suggestion. Based on that in the setCameraPosition() function, I tried to include if condition to know the diff in the cameraDistance with that of previous value and set the camera position if it is beyond 2.0f or similar value. But this does not apply properly as the initial value itself is not applied. So not sure what else to be done for this to fix. Need help.
I actually meant to apply the threshold to the values from pinch gesture, not to the camera movement.

Gopinath