Topic: Rotating at center of the fingers' rotation?

I got a bug fix request, where one of the issues were:

"When rotating, it rotates around the center of the screen instead of the center of the fingers' rotation."

So far I've attempted to use a Rectangle Transform and change the pivot values, in an attempt to rotate the map at other than the center pivot. However it always appears to pivot from the center of the map regardless of what values I try.

Since your asset is driving the transform pivot, is this even possible?

If so, how can I override the default behavior to use a custom pivot point?

Any help will be greatly appreciated.

Re: Rotating at center of the fingers' rotation?

Hello.

You can implement rotation around custom pivot.
But the correct way to implement such a rotation highly depends on how you implemented the map rotation.
If you explain in detail the settings of the map and how the rotation is implemented in your application, I will try to help.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

3 (edited by Lurch 2019-04-17 18:33:17)

Re: Rotating at center of the fingers' rotation?

Thanks for the update. The gesture code, which includes rotation, was done via your "Fingers Script" and "Online Maps Fingers Touch Gestures Connector" scripts. There is no custom code of my own to control map movement via gestures.

It sounds like that if I wanted to rotate around a custom pivot point, I would need to write my own gesture functions, not using your supplied scripts?

Post's attachments

Attachment icon inspector.png 81.77 kb, 1 downloads since 2019-04-17 

Re: Rotating at center of the fingers' rotation?

Something like that:

using System.Reflection;
using UnityEngine;

#if FINGERS_TG
using DigitalRubyShared;
#endif

#if FINGERS_TG
[RequireComponent(typeof(FingersScript))]
#endif
[AddComponentMenu("Infinity Code/Online Maps/Plugins/Fingers - Touch Gestures Connector")]
[OnlineMapsPlugin("Fingers - Touch Gestures Connector", typeof(OnlineMapsControlBase))]
public class OnlineMapsFingersTouchGesturesConnector2 : MonoBehaviour
{
#if FINGERS_TG
    public float scaleSpeed = 0.1f;
    public Vector2 speed = Vector2.one;

    private ScaleGestureRecognizer scaleGesture;
    private RotateGestureRecognizer rotateGesture;
    private OnlineMapsControlBase control;
    private OnlineMapsCameraOrbit cameraOrbit;
    private MethodInfo updateCameraPosition;
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsControlBase.instance;
        cameraOrbit = OnlineMapsCameraOrbit.instance;

        scaleGesture = new ScaleGestureRecognizer();
        scaleGesture.StateUpdated += ScaleGestureCallback;
        FingersScript.Instance.AddGesture(scaleGesture);

        updateCameraPosition = typeof(OnlineMapsCameraOrbit).GetMethod("UpdateCameraPosition", BindingFlags.Instance | BindingFlags.NonPublic);

        if (cameraOrbit != null)
        {
            rotateGesture = new RotateGestureRecognizer();
            rotateGesture.StateUpdated += RotateGestureCallback;
            FingersScript.Instance.AddGesture(rotateGesture);
        }
    }

    private void ScaleGestureCallback(GestureRecognizer gesture)
    {
        if (gesture.State == GestureRecognizerState.Executing)
        {
            map.floatZoom *= (scaleGesture.ScaleMultiplier - 1) * scaleSpeed + 1;
        }
    }

    private void RotateGestureCallback(GestureRecognizer gesture)
    {
        if (gesture.State == GestureRecognizerState.Executing)
        {
            control.isMapDrag = false;
            double lng1, lat1, lng2, lat2;
            control.GetCoords(out lng1, out lat1);
            cameraOrbit.rotation.y += rotateGesture.RotationDegreesDelta * speed.y;
            if (cameraOrbit != null) updateCameraPosition.Invoke(cameraOrbit, null);
            control.GetCoords(out lng2, out lat2);

            double tx1, ty1, tx2, ty2;
            map.projection.CoordinatesToTile(lng1, lat1, map.zoom, out tx1, out ty1);
            map.projection.CoordinatesToTile(lng2, lat2, map.zoom, out tx2, out ty2);

            double ctx, cty;
            map.GetTilePosition(out ctx, out cty);

            ctx -= tx2 - tx1;
            cty -= ty2 - ty1;

            map.SetTilePosition(ctx, cty);
        }
    }
#endif
}
Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: Rotating at center of the fingers' rotation?

Thanks, that looks impressive.

I see from the add component menu annotation, that this code appears to go into the OnlineMapsFingersTouchGesturesConnector.cs file? Is this correct?

If so, would this code replace what is currently within the file? Or would it be included within the current code?

6 (edited by Lurch 2019-04-18 13:50:56)

Re: Rotating at center of the fingers' rotation?

UPDATE: After reviewing the code, I found that a slight tweaking of the sequence and adding in some additional selection logic, I was able to add both code paths for rotating around the center or at pivot. In essence taking what you've done above and merging it with the current code, creating a component that can be used in either mode, with the click of a check box in the inspector.

The code is still all yours, just a minor re-mixing.

I have to say well done on the turn around and performance of the rotation around pivot. Works a treat on the iPhone. big_smile

The re-mix file is attached. Feel free to use it as you see fit.

Post's attachments

Attachment icon OnlineMapsFingersTouchGesturesConnector.cs 4.11 kb, 2 downloads since 2019-04-18 

Re: Rotating at center of the fingers' rotation?

Also, while ReSharper was having it's way applying it's code optimizations on the client script, I also made sure the Editor file was likewise ReSharpered. File attached.

Post's attachments

Attachment icon OnlineMapsFingersTouchGesturesConnectorEditor.cs 1.67 kb, 2 downloads since 2019-04-18