void SetVelocity(NVRHand hand)
    {
        _origin.position = _originPosition;
        _origin.rotation = _originRotation;

        if (!movementLock)
        {
            Vector3 velocity = _origin.InverseTransformPoint(hand.transform.position) - _attachementPoint;
            velocity = (velocity - transform.localPosition) * 10;
            GetComponent <Rigidbody>().velocity = transform.TransformVector(velocity);
        }

        if (!rotationLock)
        {
            Vector3 forward   = hand.transform.position - transform.position;
            Vector3 localHand = _origin.InverseTransformPoint(hand.transform.position);
            Vector3 torque    = Quaternion.LookRotation(forward, transform.up).eulerAngles - transform.eulerAngles;
            if (blockMirorMovement && localHand.z < 0)
            {
                torque.x = torque.x >= 0 ? -torque.x : torque.x;
            }

            torque.x = Math.Abs(torque.x) > 180 ? torque.x - 360 * Math.Sign(torque.x) : torque.x;
            torque.y = Math.Abs(torque.y) > 180 ? torque.y - 360 * Math.Sign(torque.y) : torque.y;
            torque.z = Math.Abs(torque.z) > 180 ? torque.z - 360 * Math.Sign(torque.z) : torque.z;
            torque   = new Vector3(_joint.axis.x != 0 ? torque.x : 0,
                                   _joint.axis.y != 0 ? torque.y : 0,
                                   _joint.axis.z != 0 ? torque.z : 0);
            torque *= Mathf.Deg2Rad * 100;

            GetComponent <Rigidbody>().angularVelocity = transform.TransformVector(torque);
        }
    }
Example #2
0
 public void Start()
 {
     if (this.head == null)
     {
         this.head = this.GetComponent <Camera>();
         if (this.head == null)
         {
             Debug.LogError("Could not find a Camera object from this: " + this);
         }
     }
     if (this.hand == null)
     {
         this.hand = this.GetComponent <NVRHand>();
         if (this.hand == null)
         {
             Debug.LogError("Could not find an NVRHand object from this: " + this);
         }
     }
     if (this.elementToTrack != null)
     {
         this.animToTrigger = elementToTrack.GetComponent <Animator>();
         if (this.animToTrigger == null)
         {
             Debug.LogError("Could not find an Animator object from element: " + this.elementToTrack);
         }
     }
     this.appMenuWasPressed = false;
     this.triggerWasPressed = false;
     ActivateMenu(false);
     if (floatingSpheres == null)
     {
         this.floatingSpheres = Component.FindObjectOfType <FloatingSpheres>();
     }
 }
Example #3
0
    public override NVRButtonInputs GetButtonState(NVRHand hand, NVRButtonID button)
    {
        SteamVR_Controller.Device controller;
        if (hand == LeftHand)
        {
            controller = SteamVR_Controller.Input((int)LeftHandTracker.index);
        }
        else
        {
            controller = SteamVR_Controller.Input((int)RightHandTracker.index);
        }

        NVRButtonInputs buttonState = new NVRButtonInputs();

        buttonState.Axis       = controller.GetAxis(InputMap[button]);
        buttonState.SingleAxis = buttonState.Axis.x;
        buttonState.PressDown  = controller.GetPressDown(InputMap[button]);
        buttonState.PressUp    = controller.GetPressUp(InputMap[button]);
        buttonState.IsPressed  = controller.GetPress(InputMap[button]);
        buttonState.TouchDown  = controller.GetTouchDown(InputMap[button]);
        buttonState.TouchUp    = controller.GetTouchUp(InputMap[button]);
        buttonState.IsTouched  = controller.GetTouch(InputMap[button]);

        return(buttonState);
    }
Example #4
0
 private void SpawnObjectInHand(NVRHand hand)
 {
     if (hand.Inputs[NVRButtons.Grip].PressDown)
     {
         if (inevtoryController.RemovefromInventory(typeToRemove))
         {
             Debug.Log("Successfully removed item");
             //Spawn an object and make the hand interact with it
             GameObject       spawnedObject = (GameObject)Instantiate(prefabToSpawn, transform.position, transform.rotation);
             ExplosionEnabler rocket        = prefabToSpawn.GetComponent <ExplosionEnabler>();
             if (rocket)
             {
                 rocket.playerHealth = leftHand.GetComponent <HealthBarController>();
             }
             Medicine med = prefabToSpawn.GetComponent <Medicine>();
             if (med)
             {
                 Debug.Log("Spawned Medicine in hand");
                 med.health = leftHand.GetComponent <HealthBarController>();
                 med.head   = GameObject.Find("Head").GetComponent <NVRHead>();
             }
             PickableItem item = spawnedObject.GetComponent <PickableItem>();
             if (item != null)
             {
                 hand.BeginInteraction(item);
                 //TODO: Remove velocity
                 item.gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0.0f, 0.0f, 0.0f);
             }
             else
             {
                 hand.BeginInteraction(spawnedObject.GetComponent <NVRExampleGun>());
             }
         }
     }
 }
 public override void SetButtonStates(NVRHand hand)
 {
     foreach (NVRButtonID button in hand.Inputs.Keys.ToList())
     {
         hand.Inputs[button] = GetButtonState(hand, button);
     }
 }
        private void Awake()
        {
            line = this.GetComponent <LineRenderer>();
            hand = this.GetComponent <NVRHand>();
            Debug.Log("awake");

            /*
             * rd = reachableArea.GetComponentsInChildren<Renderer>();
             * foreach (Renderer renderer in rd)
             *      renderer.enabled = false;
             */

            if (line == null)
            {
                line = this.gameObject.AddComponent <LineRenderer>();
            }

            if (line.sharedMaterial == null)
            {
                line.material = new Material(Shader.Find("Unlit/Color"));
                line.material.SetColor("_Color", lineColor);
                line.SetColors(lineColor, lineColor);
            }

            line.useWorldSpace = true;
        }
Example #7
0
    private IEnumerator DoInitSteamVRModels(NVRHand hand)
    {
        Debug.Log("Waiting for models to load... ");

        // Check to see if models have already been loaded for the controllers.
        // This is the case if a custom model was provided, or if we're loading a new
        // scene after the SteamVR models were loaded in a previous scene.
        if (hand.CustomModel == null)
        {
            var handModel = hand.GetComponentInChildren <SteamVR_RenderModel>();
            if (handModel.renderModelName != null)
            {
                Debug.Log("Hand already initialized");
            }
            else
            {
                modelsToInitialize.Add(handModel);
                do
                {
                    Debug.Log("Waiting for hand model...");
                    yield return(null); //wait for steamvr render model to be initialized
                } while (modelsToInitialize.Contains(handModel));
                Debug.Log("Initialized " + handModel.renderModelName);
            }
        }

        Debug.Log("RenderModels initialized!");

        // configure colliders
        InitColliders(hand);

        hand.DoInitialize();
    }
Example #8
0
 private void OnTriggerExit(Collider other)
 {
     if (!_initialized && other.transform.tag == "Hand" && (object)_hand != null)
     {
         _hand = null;
     }
 }
Example #9
0
    /*
     *  You might expect that pressing one of the edges of the SteamVR controller touchpad could
     *  be detected with a call to device.GetPress( EVRButtonId.k_EButton_DPad_* ), but currently this always returns false.
     *  Not sure whether this is SteamVR's design intent, not yet implemented, or a bug.
     *  The expected behaviour can be achieved by detecting overall Touchpad press, with Touch-Axis comparison to an edge threshold.
     */

    public static NVRButtons?GetDPadPress(NVRHand hand)
    {
        if (hand.Inputs[NVRButtons.Touchpad].PressDown)
        {
            var touchpad_axis = hand.Inputs[NVRButtons.Touchpad].Axis;
            var angle         = Mathf.Rad2Deg * Mathf.Atan2(touchpad_axis.y, touchpad_axis.x);

            if (NumUtils.DistanceInModulo(angle, 0, 360) < 45)
            {
                return(NVRButtons.DPad_Right);
            }
            if (NumUtils.DistanceInModulo(angle, 90, 360) < 45)
            {
                return(NVRButtons.DPad_Up);
            }
            if (NumUtils.DistanceInModulo(angle, 180, 360) < 45)
            {
                return(NVRButtons.DPad_Left);
            }
            if (NumUtils.DistanceInModulo(angle, 270, 360) < 45)
            {
                return(NVRButtons.DPad_Down);
            }
            Debug.LogError("Error: DPAD Press Math is wrong. Angle did not register with any specified direction.");
        }

        return(null);
    }
Example #10
0
        //-------------------------------------------------
        public bool IsEligibleForTeleport(NVRHand hand)
        {
            if (hand == null)
            {
                return(false);
            }

            if (!hand.gameObject.activeInHierarchy)
            {
                return(false);
            }

            if (hand.CurrentlyInteracting != null)
            {
                AllowTeleportWhileAttachedToHand allowTeleportWhileAttachedToHand = hand.CurrentlyInteracting.GetComponent <AllowTeleportWhileAttachedToHand>();

                if (allowTeleportWhileAttachedToHand != null && allowTeleportWhileAttachedToHand.teleportAllowed == true)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Example #11
0
    /// <summary>
    ///   Saves a new snapshot of the inputs values for the current recording.
    /// </summary>
    private void SaveNewRecordingSnapshot(NVRHand hand)
    {
        Snapshot snap = new Snapshot {
            position  = transform.position,
            rotation  = transform.rotation,
            timestamp = Time.realtimeSinceStartup,
            pressed   =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].IsPressed),
            press_down =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].PressDown),
            press_up =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].PressUp),
            touched =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].IsTouched),
            touch_down =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].TouchDown),
            touch_up =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, bool>(),
                                           (inputs_dict, button) => inputs_dict[button].TouchUp),
            axis =
                RecordButtonsForInputState(hand.Inputs, new Dictionary <NVRButtons, Vector2>(),
                                           (inputs_dict, button) => inputs_dict[button].Axis)
        };

        snapshots.Add(snap);
    }
Example #12
0
        //-------------------------------------------------
        private void ShowPointer(NVRHand newPointerHand, NVRHand oldPointerHand)
        {
            if (!visible)
            {
                pointedAtTeleportMarker = null;
                pointerShowStartTime    = Time.time;
                visible    = true;
                meshFading = true;

                teleportPointerObject.SetActive(false);
                teleportArc.Show();

                foreach (TeleportMarkerBase teleportMarker in teleportMarkers)
                {
                    if (teleportMarker.markerActive && teleportMarker.ShouldActivate(FeetPositionEstimate()))
                    {
                        teleportMarker.gameObject.SetActive(true);
                        teleportMarker.Highlight(false);
                    }
                }

                startingFeetOffset = player.transform.position - FeetPositionEstimate();
                movedFeetFarEnough = false;

                if (onDeactivateObjectTransform.gameObject.activeSelf)
                {
                    onDeactivateObjectTransform.gameObject.SetActive(false);
                }
                onActivateObjectTransform.gameObject.SetActive(true);

                loopingAudioSource.clip = pointerLoopSound;
                loopingAudioSource.loop = true;
                loopingAudioSource.Play();
                loopingAudioSource.volume = 0.0f;
            }

            pointerHand = newPointerHand;

            if (visible && oldPointerHand != pointerHand)
            {
                PlayAudioClip(pointerAudioSource, pointerStartSound);
            }

            if (pointerHand)
            {
                pointerStartTransform = pointerHand.transform;

                if (pointerHand.CurrentlyInteracting != null)
                {
                    allowTeleportWhileAttached = pointerHand.CurrentlyInteracting.GetComponent <AllowTeleportWhileAttachedToHand>();
                }

                pointerAudioSource.transform.SetParent(pointerStartTransform);
                pointerAudioSource.transform.localPosition = Vector3.zero;

                loopingAudioSource.transform.SetParent(pointerStartTransform);
                loopingAudioSource.transform.localPosition = Vector3.zero;
            }
        }
Example #13
0
 void Start()
 {
     hand = GetComponent <NVRHand>();
     if (StartEnabled)
     {
         Enable();
     }
 }
Example #14
0
 // Use this for initialization
 void Start()
 {
     while (rightHand == null || leftHand == null)
     {
         leftHand  = NVRPlayer.Instance.LeftHand;
         rightHand = NVRPlayer.Instance.RightHand;
     }
 }
Example #15
0
 public override void EndInteraction(NVRHand hand)
 {
     base.EndInteraction(hand);
     itemHolder.ResetItemPosition();
     customHand.terraformController.SetObjectType(TerrainObjectType.Missing);
     customHand.terraformController.SetCellType(CellType.Missing);
     customHand.terraformController.enabled = false;
 }
Example #16
0
 public override void ChangeAwayFrom(NVRHand hand)
 {
     if (current_hover != null)
     {
         current_hover.line_renderer.material.color = nonhover_color;
     }
     current_hover = null;
 }
Example #17
0
    private void OnTriggerEnter(Collider other)
    {
        Hit(other);

        if (!_initialized && other.transform.tag == "Hand")
        {
            _hand = other.attachedRigidbody.GetComponent <NVRHand>();
        }
    }
Example #18
0
 public void FixedUpdate()
 {
     /*if (record_toggle) {
      * NVRHand hand = GetComponent<NVRHand>();
      * SaveNewRecordingSnapshot(hand);
      * }*/
     NVRHand hand = GetComponent <NVRHand>();
     //Debug.Log("Frame " + Time.frameCount + " FixedUpdate " + hand.transform.position.x);
 }
 public override void BeginInteraction(NVRHand hand)
 {
     base.BeginInteraction(hand);
     if (!movementLock)
     {
         _origin.position  = transform.position;
         _origin.rotation  = _originRotation;
         _attachementPoint = _origin.InverseTransformPoint(hand.transform.position);
     }
 }
        //public static object Deserialize(byte[] data)
        //{
        //    var result = new NVRHandData();
        //    result.Name = data[0].ToString();
        //    return result;
        //}

        //public static byte[] Serialize(object customType)
        //{
        //    var c = (NVRHandData)customType;
        //    return new byte[] { c.Id };
        //}

        public void Start()
        {
            this.photonView = this.GetComponent <PhotonView>();

            this.nvrHand = this.GetComponent <NVRHand>();

//            this.punRpcManager = this.GetComponent<PunRpcManager2>();

//            this.preNvrHandData = new NVRHandData();
        }
Example #21
0
 public override void BeginInteraction(NVRHand hand)
 {
     base.BeginInteraction(hand);
     if (firstTime)
     {
         ForceDetach(hand);
         wires.SetActive(true);
     }
     firstTime = false;
 }
Example #22
0
 public void OnBeginInteraction(NVRHand hand)
 {
     if (myJoint != null)
     {
         myJoint.connectedBody.SendMessageUpwards("OnStickyDetached", transform);
         Destroy(myJoint);
         myJoint = null;
     }
     canAttach = true;
 }
Example #23
0
    public override void InteractingUpdate(NVRHand hand)
    {
        if (hand.UseButtonUp == true)
        {
            UseButtonUp();
        }

        if (hand.UseButtonDown == true)
        {
            UseButtonDown();
        }
    }
        public override void HoveringUpdate(NVRHand hand, float forTime)
        {
            base.HoveringUpdate(hand, forTime);

            if (IsAttached == false)
            {
                if (forTime > PickupAfterSeconds)
                {
                    hand.BeginInteraction(this);
                }
            }
        }
Example #25
0
    private IEnumerator DoLongHapticPulse(NVRHand hand, float seconds)
    {
        float startTime  = Time.time;
        float endTime    = startTime + seconds;
        var   controller = SteamVR_Controller.Input((int)hand.GetComponentInChildren <SteamVR_TrackedObject>().index);

        while (Time.time < endTime)
        {
            controller.TriggerHapticPulse(100);
            yield return(null);
        }
    }
Example #26
0
    public override Vector3 GetVelocity(NVRHand hand)
    {
        Rigidbody rb = hand.gameObject.GetComponent <Rigidbody>();

        if (rb != null)
        {
            return(rb.velocity);
        }
        else
        {
            return(new Vector3(0, 0, 0));
        }
    }
    public override void BeginInteraction(NVRHand hand)
    {
        if (hand.IsLeft)
        {
            InteractionPoint = LeftHandInteractionPoint;
        }
        else
        {
            InteractionPoint = RightHandInteractionPoint;
        }

        base.BeginInteraction(hand);
    }
Example #28
0
    public override void InteractingUpdate(NVRHand hand)
    {
        base.InteractingUpdate(hand);
        //Debug.Log("Interacting: numhands: " + AttachedHands.Count);

        if (AttachedHands.Count == 2)
        {
            if (mTransformer != null)
            {
                mTransformer.OnSecondHandHold(this);
            }
        }
    }
Example #29
0
    public override string GetDeviceName(NVRHand hand)
    {
        var renderModel = hand.GetComponentInChildren <SteamVR_RenderModel>();

        if (renderModel != null)
        {
            return(hand.GetComponentInChildren <SteamVR_RenderModel>().renderModelName);
        }
        else
        {
            return("Custom");
        }
    }
Example #30
0
    public override Vector3 GetVelocity(NVRHand hand)
    {
        var controller = SteamVR_Controller.Input((int)hand.GetComponentInChildren <SteamVR_TrackedObject>().index);

        if (controller != null)
        {
            return(controller.velocity);
        }
        else
        {
            return(Vector3.zero);
        }
    }
        private void Awake()
        {
            Line = this.GetComponent<LineRenderer>();
            Hand = this.GetComponent<NVRHand>();

            if (Line == null)
            {
                Line = this.gameObject.AddComponent<LineRenderer>();
            }

            if (Line.sharedMaterial == null)
            {
                Line.material = new Material(Shader.Find("Unlit/Color"));
                Line.material.SetColor("_Color", LineColor);
                Line.SetColors(LineColor, LineColor);
            }

            Line.useWorldSpace = true;
        }