Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to scale a Box with gaze and air-tap

Discussion in 'VR' started by DragonValor, Sep 17, 2016.

  1. DragonValor

    DragonValor

    Joined:
    Jul 27, 2014
    Posts:
    7
    Hi,
    today I want create a bounding box like in the normal hologram app from the hololens. On the edges are cubes to scale the holograms. But how can I reconstruct that?

    Is there anybody how can explain that to me?

    Thanks.

    Pad
     
  2. KarlosZafra

    KarlosZafra

    Joined:
    Sep 8, 2016
    Posts:
    18
    Basically each controls will change the scale from each of the coordinates of the Transform component of the 3D model.
     
  3. DragonValor

    DragonValor

    Joined:
    Jul 27, 2014
    Posts:
    7
    I understand what you say but how can I scale the object without to change the pivot point. Actually its in the center but when I use a handle on the top so the pivot point has to be on the bottom. That it only grow upwards.
     
  4. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Are you using the manipulation APIs from Gesture Recognizer?
     
  5. DragonValor

    DragonValor

    Joined:
    Jul 27, 2014
    Posts:
    7
    Hi, which methode do you mean? I can not find anything within the Gesture Recognizer.
     
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    In GestureRecogtnizer there are a few different things you can try, there is the manipulation events, and also one that might be worth exploring is the navigation on the rails.

    You can see example code using GestureRecognizer in the documentation.

    Here is a snippet

    m_GestureRecognizer = new GestureRecognizer();

    m_GestureRecognizer.SetRecognizableGestures(GestureSettings.ManipulationTranslate
    | GestureSettings.Tap);
    m_GestureRecognizer.ManipulationStartedEvent += M_GestureRecognizer_ManipulationStartedEvent;
    m_GestureRecognizer.ManipulationUpdatedEvent += M_GestureRecognizer_ManipulationUpdatedEvent;
    m_GestureRecognizer.ManipulationCompletedEvent += M_GestureRecognizer_ManipulationCompletedEvent;
    m_GestureRecognizer.ManipulationCanceledEvent += M_GestureRecognizer_ManipulationCanceledEvent;

    m_GestureRecognizer.StartCapturingGestures();
     
  7. DragonValor

    DragonValor

    Joined:
    Jul 27, 2014
    Posts:
    7
    GestureRecognizer methods only realise a methode or what you are doing with your hands... but there is nothing to manipulate the size.

    The main question is "how to scale the object in one direction" and to link this to the view and hit point of it.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ScaleQuad : MonoBehaviour
    5. {
    6.  
    7. public GameObject master; //Empty before the Quad
    8. public GameObject quad; //The Quad I want to scale
    9. Raycast hitInfo;
    10. private Vector3 offsetOld;
    11.  
    12.  
    13. void Update()
    14. {
    15.     var headPosition = Camera.main.transform.position;
    16.     var gazeDirection = Camera.main.transform.forward;
    17.  
    18.     if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
    19.     {
    20.         //Create the offset
    21.         offset = hitInfo.point - master.transform.position;
    22.        
    23.         // To get the new offset between hitpoint and master.transform.position for the new size
    24.         Vector3 diff = offset - offsetOld;
    25.  
    26.         vFBMaster.transform.position = new Vector3((diff.x + master.transform.position.x), (diff.y + master.transform.position.y), master.transform.position.z);
    27.         quad.transform.localScale = new Vector3((diff.x / 2) + quad.transform.localScale.x, (diff.y / 2) + quad.transform.localScale.y, quad.transform.localScale.z);
    28.  
    29.         Debug.Log(diff);
    30.  
    31.         //To save the old offset
    32.         offsetOld = offset;
    33.  
    34.         Debug.Log("Old Offset = " + offsetOld);
    35.         Debug.Log("new Offset = " + offset);
    36.     }
    37. }
    38. }
     
  8. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Hello,

    There is a way to manipulate size, you look at event navigation or manipulation using gesture there is a Vector3 relativePosition or cumulativeDelta in the function. You can use the Vector3 to transform position, local scale, etc... You can use only the x, y, or z coordinates if you desire.

    Example:
    public class GestureManipulation : MonoBehaviour {

    GestureRecognizer m_GestureRecognizer = null;
    public GameObject Go;

    void Start()
    {
    m_GestureRecognizer = new GestureRecognizer();

    m_GestureRecognizer.SetRecognizableGestures(GestureSettings.ManipulationTranslate
    | GestureSettings.Tap);
    m_GestureRecognizer.ManipulationStartedEvent += M_GestureRecognizer_ManipulationStartedEvent;
    m_GestureRecognizer.ManipulationUpdatedEvent += M_GestureRecognizer_ManipulationUpdatedEvent;
    m_GestureRecognizer.ManipulationCompletedEvent += M_GestureRecognizer_ManipulationCompletedEvent;
    m_GestureRecognizer.ManipulationCanceledEvent += M_GestureRecognizer_ManipulationCanceledEvent;

    m_GestureRecognizer.StartCapturingGestures();
    }

    private void M_GestureRecognizer_ManipulationCanceledEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    Debug.Log("Manipulation Canceled");
    }

    private void M_GestureRecognizer_ManipulationCompletedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    Go.transform.localScale = cumulativeDelta;
    Debug.Log("Manipulation Complete");
    }

    private void M_GestureRecognizer_ManipulationUpdatedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    Go.transform.localScale = cumulativeDelta;
    Debug.Log("Manipulation Update");
    }

    private void M_GestureRecognizer_ManipulationStartedEvent(InteractionSourceKind source, Vector3 cumulativeDelta, Ray headRay)
    {
    Go.transform.localScale = cumulativeDelta;
    Debug.Log("Manipulation Started");
    }

    void OnDestroy()
    {
    m_GestureRecognizer.ManipulationStartedEvent -= M_GestureRecognizer_ManipulationStartedEvent;
    m_GestureRecognizer.ManipulationUpdatedEvent -= M_GestureRecognizer_ManipulationUpdatedEvent;
    m_GestureRecognizer.ManipulationCompletedEvent -= M_GestureRecognizer_ManipulationCompletedEvent;
    m_GestureRecognizer.ManipulationCanceledEvent -= M_GestureRecognizer_ManipulationCanceledEvent;

    m_GestureRecognizer.StopCapturingGestures();
    m_GestureRecognizer.Dispose();
    }

    }


    Thank you,
    Wesley