Exemplo n.º 1
0
    public override void OnFrame(InteractionController controller)
    {
        if (IsGrabbed)
        {
            //disable interaction once the hand leaves the region of interest
            //var hand = controller.GetHand();
            //float distance = MathUtil.Distance(controller.Target.transform.position, gameObject.transform.position);
            //if (distance > MAX_INTERACTION_DISTANCE)
            //{
            //    controller.Drop();
            //    return;
            //}

            //rotate the oven door such that it is as close to the hand as possible
            //this motion is described by finding the point closest to another (on a circle)
            var hand         = controller.GetHand();
            var closestPoint = MathUtil.ClosestPointOnCircle(hand.transform.position, DoorHingeLocation, DoorHingeToHandleRadius);

            //if the hand is too far from that point, drop the door
            float distanceFromHandToHandle = MathUtil.Distance(hand.transform.position, closestPoint);
            if (distanceFromHandToHandle > MAX_INTERACTION_DISTANCE)
            {
                controller.Drop();
                return;
            }

            //calculate door rotation angle
            float diffZ = (closestPoint.z - DoorHingeLocation.z) / DoorHingeToHandleRadius;
            float angle = Mathf.Asin(diffZ);

            //perform rotation
            Door.transform.rotation = Quaternion.Euler(angle, 0f, 0f);

            //hide hand
            var handRenderer = hand.GetComponent <MeshRenderer>();
            handRenderer.enabled = false;


            ////rotate the dial as the hand rotates
            //float targetAngle = controller.Target.transform.rotation.eulerAngles.z - StartEulerRotation.z;
            //targetAngle *= -1;
            //targetAngle = Mathf.DeltaAngle(0f, targetAngle);                            // converts to -180..180
            //float originalAngle = Mathf.DeltaAngle(0f, StartEulerRotation.z);           // converts to -180..180
            //float diffAngle = Mathf.DeltaAngle(originalAngle, targetAngle);             // total diff

            //if (targetAngle > ANGLE_ZERO_DEADBAND && targetAngle < 0)
            //{
            //    //round to zero
            //    targetAngle = 0;
            //}
            //if (targetAngle > 0 && targetAngle < ANGLE_MAX)
            //{
            //    //round to nearest
            //    if (ANGLE_MAX - targetAngle > targetAngle) targetAngle = 0;
            //    else targetAngle = ANGLE_MAX;
            //}

            //gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, targetAngle));
        }
    }
    public override void OnDrop(InteractionController controller)
    {
        var hand         = controller.GetHand();
        var handRenderer = hand.GetComponent <MeshRenderer>();

        //remove food item
        IsGrabbed            = false;
        handRenderer.enabled = true;
    }
Exemplo n.º 3
0
        public override void OnFrame(InteractionController controller)
        {
            base.OnFrame(controller);

            if (isGrabbed)
            {
                var hand = controller.GetHand();
                OnFrameWhenGrabbed(controller, hand);
            }
        }
Exemplo n.º 4
0
    public override void OnGrab(InteractionController controller)
    {
        var hand         = controller.GetHand();
        var handRenderer = hand.GetComponent <MeshRenderer>();

        //make the hand mesh invisible
        IsGrabbed            = true;
        handRenderer.enabled = false;
        rb.isKinematic       = true;
    }
Exemplo n.º 5
0
 public override void OnFrame(InteractionController controller)
 {
     //attach food item position to hand mesh's position and rotation every frame if grabbed
     if (IsGrabbed)
     {
         var hand         = controller.GetHand();
         var handRenderer = hand.GetComponent <MeshRenderer>();
         gameObject.transform.position = controller.Target.transform.position;
         handRenderer.enabled          = false;
     }
 }
    public override void OnGrab(InteractionController controller)
    {
        var hand         = controller.GetHand();
        var handRenderer = hand.GetComponent <MeshRenderer>();

        //make the hand mesh invisible
        IsGrabbed            = true;
        handRenderer.enabled = false;

        //get initial rotation of the hand
        StartEulerRotation = controller.Target.transform.rotation.eulerAngles +
                             gameObject.transform.rotation.eulerAngles;
    }
    public override void OnDrop(InteractionController controller)
    {
        var hand         = controller.GetHand();
        var handRenderer = hand.GetComponent <MeshRenderer>();

        //remove food item
        IsGrabbed             = false;
        handRenderer.enabled  = true;
        RigidBody.isKinematic = false;

        //use a mesh collider
        MeshCollider.enabled = true;
        BoxCollider.enabled  = false;
    }
 public override void OnFrame(InteractionController controller)
 {
     //attach food item position to hand mesh's position and rotation every frame if grabbed
     if (IsGrabbed)
     {
         var hand         = controller.GetHand();
         var handRenderer = hand.GetComponent <MeshRenderer>();
         gameObject.transform.position = controller.Target.transform.position;
         gameObject.transform.rotation = controller.Target.transform.rotation;
         handRenderer.enabled          = false;
         //print("Knife: " + gameObject.transform.rotation);
         //print("Hand: " + controller.Target.transform.rotation);
         if (controller.Name.Equals("Left"))
         {
             gameObject.transform.Rotate(controller.transform.rotation.x + 45, controller.transform.rotation.y + 45, controller.transform.rotation.z + 45);
         }
         else if (controller.Name.Equals("Right"))
         {
             gameObject.transform.Rotate(controller.transform.rotation.x + 45, controller.transform.rotation.y - 45, controller.transform.rotation.z + 45);
         }
         //print("Knife: " + gameObject.transform.position);
         timeSpan = System.DateTime.UtcNow - startTime;
         //print("Elasped MS: " + timeSpan.TotalMilliseconds);
         double timeThreshold = 1000;
         if (timeSpan.TotalMilliseconds >= timeThreshold)
         {
             currentY = gameObject.transform.position.y;
             double diff = currentY - prevY;
             print("DIFF: " + diff.ToString());
             ObjectRenderer.materials = OriginalMaterials;
             IsChopping = false;
             if (diff <= -0.15)
             {
                 print("Chopped Down");
                 IsChopping = true;
                 Material[] materials2 = new Material[ObjectRenderer.materials.Length];
                 for (int i = 0; i < materials2.Length; i++)
                 {
                     materials2[i] = ChoppedMaterial;
                 }
                 ObjectRenderer.materials = materials2;
             }
             prevY     = currentY;
             startTime = System.DateTime.UtcNow;
         }
     }
 }
Exemplo n.º 9
0
        public override void OnFrame(InteractionController controller)
        {
            base.OnFrame(controller);

            if (isGrabbed)
            {
                var hand = controller.GetHand();
                OnFrameWhenGrabbed(controller, hand);
            }

            // re-enable colliders if time arrived
            if ((timesDropped.ContainsKey(controller)) && (Time.time - timesDropped[controller] >= GRAB_COLLIDER_DISABLE_TIMEOUT))
            {
                timesDropped.Remove(controller);
                ToggleHandCollisions(controller, true);
            }
        }
Exemplo n.º 10
0
    public override void OnGrab(InteractionController controller)
    {
        var hand         = controller.GetHand();
        var handRenderer = hand.GetComponent <MeshRenderer>();

        //make the hand mesh invisible
        IsGrabbed             = true;
        handRenderer.enabled  = false;
        RigidBody.isKinematic = true;
        startTime             = System.DateTime.UtcNow;
        currentY = gameObject.transform.position.y;
        prevY    = currentY;

        //use a box collider
        BoxCollider.enabled  = true;
        MeshCollider.enabled = false;
    }
Exemplo n.º 11
0
    public override void OnFrame(InteractionController controller)
    {
        if (IsGrabbed)
        {
            //disable interaction once the hand leaves the region of interest
            var   hand     = controller.GetHand();
            float distance = MathUtil.Distance(controller.Target.transform.position, gameObject.transform.position);
            if (distance > MAX_INTERACTION_DISTANCE)
            {
                controller.Drop();
                return;
            }

            //hide hand
            var handRenderer = hand.GetComponent <MeshRenderer>();
            handRenderer.enabled = false;

            //rotate the dial as the hand rotates
            float targetAngle = controller.Target.transform.rotation.eulerAngles.z - StartEulerRotation.z;
            targetAngle *= -1;
            targetAngle  = Mathf.DeltaAngle(0f, targetAngle);                           // converts to -180..180
            float originalAngle = Mathf.DeltaAngle(0f, StartEulerRotation.z);           // converts to -180..180
            float diffAngle     = Mathf.DeltaAngle(originalAngle, targetAngle);         // total diff

            if (targetAngle > ANGLE_ZERO_DEADBAND && targetAngle < 0)
            {
                //round to zero
                targetAngle = 0;
            }
            if (targetAngle > 0 && targetAngle < ANGLE_MAX)
            {
                //round to nearest
                if (ANGLE_MAX - targetAngle > targetAngle)
                {
                    targetAngle = 0;
                }
                else
                {
                    targetAngle = ANGLE_MAX;
                }
            }

            gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, targetAngle));
        }
    }