User Tools

Site Tools


tutorials:net_unity:unity_mini_tutorial_movement_related_to_camera

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tutorials:net_unity:unity_mini_tutorial_movement_related_to_camera [2015/09/09 15:52]
glass [Continuing Education]
tutorials:net_unity:unity_mini_tutorial_movement_related_to_camera [2019/01/21 19:24] (current)
Line 1: Line 1:
 +[[tutorials/​net_unity|{{ :​unity_3d_logo.png }}]]
  
 +====== Unity Mini Tutorial: Movement Related to Camera ======
 +
 +===== Introduction =====
 +
 +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 [[http://​files.gestureworks.com/​downloads/​Core/​Trial/​GestureworksCoreTrialSetup.exe|free trial]] is available.
 +
 +Download the code for all of the C# & Unity multitouch tutorials here: [[https://​github.com/​ideum/​gestureworks-unity/​|gestureworks-unity on GitHub]].
 +
 +----
 +
 +
 +===== Requirements =====
 +
 +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.
 +
 +----
 +
 +
 +===== Process Overview =====
 +
 +  - [[tutorials:​net_unity:​unity_mini_tutorial_movement_related_to_camera#​example_of_using_MoveObjectInCameraPlane|Example of using MoveObjectInCameraPlane]]
 +  - [[tutorials:​net_unity:​unity_mini_tutorial_movement_related_to_camera#​discussion_of_MoveObjectInCameraPlane|Discussion of MoveObjectInCameraPlane]]
 +
 +----
 +
 +
 +===== Process Detail =====
 +
 +==== 1. Example of using MoveObjectInCameraPlane ====
 +
 +Copy your GestureWorks dlls to the <​html><​font face="​Courier New">​Assets/​GestureWorks/​Core</​font></​html>​ directory of MiniTutorial_MovementFollowingCamera (more discussion of the process is in a previous tutorial.)
 +
 +The project contains many touch objects around the camera. Open <​html><​font face="​Courier New">​MyScene.unity</​font></​html>​ and build and run. The objects will be visible and responsive to touch, and using the mouse will orbit the camera:
 +
 +{{ :​tutorials:​net_unity:​777px-unity_mini_camera.1_a.png?​direct |}}
 +
 +Note the boxes will move following the touch even if they are at a different camera angle and varying distances.
 +
 +{{ :​tutorials:​net_unity:​777px-unity_mini_camera.1_b.png?​direct |}}
 +
 +The code for the boxes is in <​html><​font face="​Courier New">​Assets/​Scripts/​TouchBox.cs</​font></​html>​ and is as follows:
 +
 +<​code:​xml linenums:1 |TouchBox // TouchBox.cs //>
 +using UnityEngine;​
 +using System.Collections;​
 +using GestureWorksCoreNET;​
 +using GestureWorksCoreNET.Unity;​
 +
 +public class TouchBox : TouchObject {
 +        ​
 +    public void NDrag(GestureEvent gEvent){
 +        MoveObjectInCameraPlane(gEvent); ​       ​
 +    }
 +}
 +</​code>​
 +
 +The movement is handled by calling the base method TouchObject MoveObjectInCameraPlane.
 +
 +
 +==== 2. Discussion of MoveObjectInCameraPlane ====
 +
 +Many drag methods use a constant factor across a set of axes, such as:
 +
 +<​code:​xml linenums:1 |Switching Screens // SwitchScenes.cs //>
 +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);
 +}
 +</​code>​
 +
 +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 <​html><​font face="​Courier New">​Assets/​GestureWorks/​Unity/​TouchObject.cs</​font></​html>​.
 +
 +----
 +
 +
 +===== Continuing Education =====
 +
 +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:
 +
 +  * [[tutorials:​net_unity:​unity_mini_tutorial_switching_scenes|Unity Mini Tutorial: Switching Scenes]]
 +  * [[tutorials:​net_unity:​unity_mini_tutorial_registering_touch_objects|Unity Mini Tutorial: Registering Touch Objects]]
 +
 +There is also FAQ here:
 +
 +  * [[tutorials:​net_unity:​gestureworks_faq|Unity GestureWorks FAQ]]
 +
 +For more information on GestureWorks Core, GestureML, and CreativeML, please visit the following sites:
 +
 +  * [[http://​wiki.gestureworks.com]]
 +  * [[http://​gestureml.org]]
 +  * [[http://​creativeml.org]]