Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Editor/InputSources/TuioInputEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal sealed class TuioInputEditor : InputSourceEditor
private SerializedProperty _connectionType;
private SerializedProperty _port;
private SerializedProperty _ipAddress;
private SerializedProperty _pointerOffset;

protected override void OnEnable()
{
Expand All @@ -24,6 +25,14 @@ protected override void OnEnable()
_connectionType = serializedObject.FindProperty("_connectionType");
_port = serializedObject.FindProperty("_port");
_ipAddress = serializedObject.FindProperty("_ipAddress");
if(target is Tuio20Input)
{
_pointerOffset = serializedObject.FindProperty("_pointerOffset");
}
else
{
_pointerOffset = null;
}
}

public override void OnInspectorGUI()
Expand All @@ -32,6 +41,10 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_connectionType);
EditorGUILayout.PropertyField(_port);
EditorGUILayout.PropertyField(_ipAddress);
if (_pointerOffset != null)
{
EditorGUILayout.PropertyField(_pointerOffset);
}
serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI();
}
Expand Down
18 changes: 13 additions & 5 deletions Runtime/Core/TouchManagerInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,19 @@ public IList<Pointer> PressedPointers
private HashSet<int> pointersRemoved = new HashSet<int>();
private HashSet<int> pointersCancelled = new HashSet<int>();

private static ObjectPool<List<Pointer>> pointerListPool = new ObjectPool<List<Pointer>>(2,
() => new List<Pointer>(10), null, (l) => l.Clear());

private static ObjectPool<List<int>> intListPool = new ObjectPool<List<int>>(3, () => new List<int>(10), null,
(l) => l.Clear());
private static ObjectPool<List<Pointer>> pointerListPool = new ObjectPool<List<Pointer>>(
capacity: 2,
actionNew: () => new List<Pointer>(10),
actionOnGet: null,
actionOnRelease: (l) => l.Clear()
);

private static ObjectPool<List<int>> intListPool = new ObjectPool<List<int>>(
capacity: 3,
actionNew: () => new List<int>(10),
actionOnGet: null,
actionOnRelease: (l) => l.Clear()
);

private int nextPointerId = 0;
private object pointerLock = new object();
Expand Down
26 changes: 23 additions & 3 deletions Runtime/Gestures/TapGesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public float CombinePointersInterval
set { combinePointersInterval = value; }
}

public Vector2 PointerDirection
{
get => direction.Value;
}

public float PointerRotation
{
get
{
return direction.ToAngle();
}
}

#endregion

#region Private variables
Expand Down Expand Up @@ -146,6 +159,7 @@ public float CombinePointersInterval
private TimedSequence<Pointer> pointerSequence = new TimedSequence<Pointer>();

private CustomSampler gestureSampler;
private SmoothedVector2 direction = new(10);

#endregion

Expand Down Expand Up @@ -207,29 +221,35 @@ protected override void pointersPressed(IList<Pointer> pointers)

if (NumPointers == pointers.Count)
{
var pointer = pointers[0];

// the first ever pointer
if (tapsDone == 0)
{
startPosition = pointers[0].Position;
startPosition = pointer.Position;
if (timeLimit < float.PositiveInfinity) StartCoroutine("wait");
direction.Reset();
direction.Update(pointer.Rotation);
}
else if (tapsDone >= numberOfTapsRequired) // Might be delayed and retapped while waiting
{
reset();
startPosition = pointers[0].Position;
startPosition = pointer.Position;
if (timeLimit < float.PositiveInfinity) StartCoroutine("wait");
direction.Update(pointer.Rotation);
}
else
{
if (distanceLimit < float.PositiveInfinity)
{
if ((pointers[0].Position - startPosition).sqrMagnitude > distanceLimitInPixelsSquared)
if ((pointer.Position - startPosition).sqrMagnitude > distanceLimitInPixelsSquared)
{
setState(GestureState.Failed);
gestureSampler.End();
return;
}
}
direction.Update(pointer.Rotation);
}
}
if (pointersNumState == PointersNumState.PassedMinThreshold)
Expand Down
29 changes: 28 additions & 1 deletion Runtime/InputSources/Tuio20Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public sealed class Tuio20Input : TuioInput
{
private TuioClient _client;
private Tuio20Processor _processor;

[SerializeField] private float _pointerOffset = 0;

protected override void Init()
{
if (IsInitialized) return;
Expand Down Expand Up @@ -58,7 +61,9 @@ private void TuioAdd(Tuio20Object tuio20Object)
x = tuioPointer.Position.X * ScreenWidth,
y = (1f - tuioPointer.Position.Y) * ScreenHeight
};
TouchToInternalId.Add(tuioPointer.SessionId, AddTouch(screenPosition));
var touchPointer = AddTouch(screenPosition);
InitPointerProperties(touchPointer, tuioPointer);
TouchToInternalId.Add(tuioPointer.SessionId, touchPointer);
}

if (tuio20Object.ContainsNewTuioToken())
Expand Down Expand Up @@ -91,6 +96,7 @@ private void TuioUpdate(Tuio20Object tuio20Object)
y = (1f - tuioPointer.Position.Y) * ScreenHeight
};
touchPointer.Position = RemapCoordinates(screenPosition);
UpdatePointerProperties(touchPointer, tuioPointer);
UpdatePointer(touchPointer);
}

Expand Down Expand Up @@ -141,5 +147,26 @@ private void UpdateObjectProperties(ObjectPointer pointer, Tuio20Token token)
pointer.ObjectId = (int)token.ComponentId;
pointer.Angle = token.Angle;
}


private void InitPointerProperties(TouchPointer pointer, Tuio20Pointer tuioData)
{
pointer.INTERNAL_InitRotation(ShiftAngle(tuioData.Angle, _pointerOffset));
}

private void UpdatePointerProperties(TouchPointer pointer, Tuio20Pointer tuioData)
{
pointer.Rotation = ShiftAngle(tuioData.Angle, _pointerOffset);
}

private static float ShiftAngle(float angle, float offset)
{
const float TWO_PI = 2 * Mathf.PI;
float result = angle + offset;
result = result % TWO_PI;
if (result < 0)
result += TWO_PI;
return result;
}
}
}
17 changes: 17 additions & 0 deletions Runtime/Pointers/FakePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public class FakePointer : IPointer
/// <inheritdoc />
public Vector2 PreviousPosition { get; private set; }

/// <inheritdoc />
public float Rotation { get; set; }

/// <inheritdoc />
public float PreviousRotation { get; private set; }

#endregion

#region Constructors
Expand All @@ -50,6 +56,17 @@ public FakePointer(Vector2 position) : this()
Position = position;
}

/// <summary>
/// Initializes a new instance of the <see cref="FakePointer"/> class.
/// </summary>
/// <param name="position">The position.</param>
/// <param name="rotation">The rotation in radians.</param>
public FakePointer(Vector2 position, float rotation) : this()
{
Position = PreviousPosition = position;
Rotation = PreviousRotation = rotation;
}

/// <summary>
/// Initializes a new instance of the <see cref="FakePointer"/> class.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Pointers/IPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public interface IPointer
/// </summary>
Vector2 PreviousPosition { get; }

/// <summary>
/// Rotation of the pointer in radians.
/// </summary>
float Rotation { get; set; }

/// <summary>
/// Previous Rotation of the pointer in radians.
/// </summary>
float PreviousRotation { get; }

/// <summary>
/// <para>Gets or sets pointer flags: <see cref="Pointer.FLAG_ARTIFICIAL"/></para>
/// <para>Note: setting this property doesn't immediately change its value, the value actually changes during the next TouchManager update phase.</para>
Expand Down
28 changes: 28 additions & 0 deletions Runtime/Pointers/Pointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ public Vector2 Position
/// <inheritdoc />
public Vector2 PreviousPosition { get; private set; }

public float Rotation
{
get { return rotation; }
set { newRotation = value; }
}

/// <inheritdoc />
public float PreviousRotation { get; private set; }

/// <inheritdoc />
public uint Flags { get; set; }

Expand All @@ -237,6 +246,7 @@ public ProjectionParams ProjectionParams
private LayerManagerInstance layerManager;
private int refCount = 0;
private Vector2 position, newPosition;
private float rotation, newRotation;
private HitData pressData, overData;
private bool overDataIsDirty = true;

Expand Down Expand Up @@ -274,6 +284,8 @@ public virtual void CopyFrom(Pointer target)
Buttons = target.Buttons;
position = target.position;
newPosition = target.newPosition;
rotation = target.rotation;
newRotation = target.newRotation;
PreviousPosition = target.PreviousPosition;
}

Expand Down Expand Up @@ -313,6 +325,8 @@ public override string ToString()
BinaryUtils.ToBinaryString(Flags, builder, 8);
builder.Append(", position: ");
builder.Append(Position);
builder.Append(", rotation: ");
builder.Append(Rotation);
builder.Append(")");
return builder.ToString();
}
Expand Down Expand Up @@ -340,13 +354,15 @@ internal virtual void INTERNAL_Init(int id)
{
Id = id;
PreviousPosition = position = newPosition;
PreviousRotation = rotation = newRotation;
}

internal virtual void INTERNAL_Reset()
{
Id = INVALID_POINTER;
INTERNAL_ClearPressData();
position = newPosition = PreviousPosition = Vector2.zero;
rotation = newRotation = PreviousRotation = 0;
Flags = 0;
Buttons = PointerButtonState.Nothing;
overDataIsDirty = true;
Expand All @@ -362,6 +378,13 @@ internal virtual void INTERNAL_UpdatePosition()
{
PreviousPosition = position;
position = newPosition;
INTERNAL_UpdateRotation();
}

internal virtual void INTERNAL_UpdateRotation()
{
PreviousRotation = rotation;
rotation = newRotation;
}

internal void INTERNAL_Retain()
Expand All @@ -387,6 +410,11 @@ internal void INTERNAL_ClearPressData()
refCount = 0;
}

internal void INTERNAL_InitRotation(float rot)
{
PreviousRotation = rotation = newRotation = rot;
}

#endregion
}
}
6 changes: 0 additions & 6 deletions Runtime/Pointers/TouchPointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ public class TouchPointer : Pointer

#region Public properties

/// <summary>
/// Gets or sets the touch's rotation.
/// </summary>
/// <value> Rotation in radians. </value>
public float Rotation { get; set; }

/// <summary>
/// Gets or sets the touch's pressure.
/// </summary>
Expand Down
Loading