Author Topic: Implement custom map model with navigation handling 1 finger, 2 finger gestures  (Read 5878 times)

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
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 !!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Sooo...basically, the camera should move to (or at least close to) where the user has touched the map?

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
May be yes. It should be like dragging the map based on the vertical swipe

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
Hi EgonOlsen,

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline Wyatt

  • byte
  • *
  • Posts: 5
    • View Profile
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.
« Last Edit: January 08, 2014, 09:51:50 pm by Wyatt »

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
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.

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Just add some dead zone, so that minimal changes don't cause a zoom effect.

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
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.

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
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 ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline Gopinath

  • byte
  • *
  • Posts: 22
    • View Profile
Thank you so much and i had included to resolve the issue