User Tools

Site Tools


unity_clock

Differences

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

Link to this comparison view

unity_clock [2017/05/09 15:37]
unity_clock [2019/01/21 16:34] (current)
Line 23: Line 23:
   * Create Bell Script   * Create Bell Script
   * Create Clock Script   * Create Clock Script
 +  * Minute Hand Script
 +  * Second Hand Script (Optional)
 +  * Review ​
  
 ===== Setup the Project ===== ===== Setup the Project =====
Line 141: Line 144:
  
 </​code>​ </​code>​
 +
 +Note we are doing two things different here, using MoveObjectInCameraPlane to handle dragging and basic transforms for the other gestures. MoveObjectInCameraPlane is a helper method inside of GestureWorks/​Unity/​TouchObject.cs that in response to touch drags the object parallel to the current camera plane. This has the effect of keeping the Clock dragging consistent in response to user touch regardless of the current camera position and orientation.
 +Boundary checking is included in this script and is used to limit to how far the clock may be scaled and dragged. We use the clamp method to achieve this functionality.
 +Be sure to click and drag this script to the Clock > Clock object with the the collider box. Increase the supported gestures to 3 and type in the supported elements as follows:
 +
 +Element 0: ndrag
 +Element 1: nrotate
 +Element 2: nscale
 +
 +If you build and run at this point, you should be able to manipulate the clock in all the ways defined.
 +
 +===== Minute Hand Script =====
 +
 +We will now add a script that will allow you to rotate the minute hand around the center point of the clock. This rotational gesture will require that two fingers are touching the minute hand at the same time (as defined in the gml). Create a new C# script called TouchMinuteHand.
 +
 +NOTE: the clock.fbx file was designed to contain properly registered pivot points for the clock hands. If you would like to achieve the same effect with a different model, you will need to also set registration points properly in the 3D authoring program.
 +
 +<​code>​
 +using System.Collections;​
 +using System.Collections.Generic;​
 +using UnityEngine;​
 +
 +public class TouchMinuteHand : TouchObject ​
 +{
 +    public Transform SecondsHand;​
 +    public Transform HourHand;
 +
 +    public void nrotate (GestureWorks.GestureInfo gesture) ​
 +    {
 + float dTheta = gesture.value("​rotate_dtheta"​);​
 + transform.Rotate(0f,​ 0f, dTheta);
 + SecondsHand.Rotate(0f,​ 0f, dTheta * 60f);
 + HourHand.transform.Rotate(0f,​ 0f, dTheta / 12);
 +    }
 +}
 +</​code>​
 +
 +Attach this script to the MinuteHand object in the Hierarchy and increase supported gestures to 1 with nrotate as the supported gesture.
 +This particular script also has a public Transform property that is used in the nrotate method. The rotate method will also affect the HourHand object and rotate it based on the revolutions the minute hand makes. It is important that you click and drag the HourHand object onto the Hour Hand transform target in the script. The following is a screenshot of what it should look like when done properly:
 +{{:​hourhandsetup.png?​600|}}
 +
 +===== Second Hand Script (Optional) =====
 +If you would like to make the clock look like it has a good wind up (time keeping power), add this script to the SecondHand object:
 +
 +<​code>​
 +using System.Collections;​
 +using System.Collections.Generic;​
 +using UnityEngine;​
 +
 +public class SecondHand : MonoBehaviour ​
 +{
 +    void Update () 
 +    {
 +        transform.Rotate(new Vector3(0.0f,​ 0.0f, Time.deltaTime * 6.0f));
 +    }
 +}
 +</​code>​
 +
 +===== Review =====
 +In this tutorial we expanded on the knowledge gained in Tutorial #3 by manipulating on-screen bitmaps using gesture data obtained from GestureWorks. This tutorial covers a number of concepts that are central to the usage of GestureWorks:​
 +
 +  * Fine tuned control over touchable objects
 +  * Adding unique gestures to the registered touch objects
 +  * Manipulating object instances based on data obtained from GestureWorks
  
unity_clock.1494344275.txt.gz ยท Last modified: 2019/01/21 16:35 (external edit)