Documentation
Libraries
Related
Documentation
Libraries
Related
Many applications use fixed cameras with touch object’s moving a constant factor in relation to touch drag. But this does not give good results in cases where the camera moves frequently or moving objects are varying distances from the camera. This tutorial discusses using the TouchObject method MoveObjectInCameraPlane to handle these cases.
For this tutorial you will need the http://gestureworks.com/coreGestureworks Core multitouch framework; a free trial is available.
Download the code for all of the C# & Unity multitouch tutorials here: gestureworks-unity on GitHub.
Estimated time to complete: 10 minutes
This tutorial assumes a basic understanding of GestureWorks setup in Unity as described in the HelloMultitouch tutorials and the Interactive Bitmap tutorial. The project MiniTutorial_MovementFollowingCamera is also required.
Copy your GestureWorks dlls to the Assets/GestureWorks/Core directory of MiniTutorial_MovementFollowingCamera (more discussion of the process is in a previous tutorial.)
The project contains many touch objects around the camera. Open MyScene.unity and build and run. The objects will be visible and responsive to touch, and using the mouse will orbit the camera:
Note the boxes will move following the touch even if they are at a different camera angle and varying distances.
The code for the boxes is in Assets/Scripts/TouchBox.cs and is as follows:
using UnityEngine; using System.Collections; using GestureWorksCoreNET; using GestureWorksCoreNET.Unity; public class TouchBox : TouchObject { public void NDrag(GestureEvent gEvent){ MoveObjectInCameraPlane(gEvent); } }
The movement is handled by calling the base method TouchObject MoveObjectInCameraPlane.
Many drag methods use a constant factor across a set of axes, such as:
public void NDrag(GestureEvent gEvent){ float dX = gEvent.Values["drag_dx"]; float dY = gEvent.Values["drag_dy"]*Flipped; const float factor = 10.0f; transform.Translate(dX * factor, dY * factor, 0.0f); }
But this only works well for fixed cameras and resolutions. A better technique is to move the object in a plane parallel to the current camera by an amount relative to the change on screen. This is what MoveObjectInCameraPlane does, and can be used by calling it in response to a drag event. Further details can be found by looking at the code in Assets/GestureWorks/Unity/TouchObject.cs.
It is the intention of this and the other GestureWorks Core tutorials to get the programmer started using the GestureWorks core framework, and is by no means an exhaustive explanation of all of the features of Gestureworks Core; in fact, we’ve only barely scratched the surface!
Additional tutorials for learning more about GestureWorks Unity:
There is also FAQ here:
For more information on GestureWorks Core, GestureML, and CreativeML, please visit the following sites: