Example #1
0
    // Update is called once per frame
    void Update()
    {
        foreach(SteamVR_LaserPointer pointer in FindObjectsOfType<SteamVR_LaserPointer>())
        {
            Ray r = new Ray(pointer.transform.position, pointer.transform.forward);
            Plane p = new Plane(transform.forward, transform.position);
            float enter;
            if (p.Raycast(r, out enter))
            {
                Vector3 target = pointer.transform.position + enter * pointer.transform.forward;
                Vector3 localTarget = ((RectTransform)transform).InverseTransformPoint(target);
                bool hit = ((RectTransform)transform).rect.Contains(new Vector2(localTarget.x, localTarget.y));

                uint controllerIndex = (uint)pointer.GetComponent<SteamVR_TrackedObject>().index;
                Valve.VR.VRControllerState_t controllerState = new Valve.VR.VRControllerState_t();
                if (SteamVR.instance.hmd.GetControllerState(controllerIndex, ref controllerState))
                {
                    bool trigger = (controllerState.ulButtonPressed & (1UL << ((int)Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) > 0;
                    if (hit && Clicked != null && trigger)
                    {
                        Clicked();
                    }
                }
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        foreach (SteamVR_LaserPointer pointer in FindObjectsOfType <SteamVR_LaserPointer>())
        {
            Ray   r = new Ray(pointer.transform.position, pointer.transform.forward);
            Plane p = new Plane(transform.forward, transform.position);
            float enter;
            if (p.Raycast(r, out enter))
            {
                Vector3 target      = pointer.transform.position + enter * pointer.transform.forward;
                Vector3 localTarget = ((RectTransform)transform).InverseTransformPoint(target);
                bool    hit         = ((RectTransform)transform).rect.Contains(new Vector2(localTarget.x, localTarget.y));


                uint controllerIndex = (uint)pointer.GetComponent <SteamVR_TrackedObject>().index;
                Valve.VR.VRControllerState_t controllerState = new Valve.VR.VRControllerState_t();
                if (SteamVR.instance.hmd.GetControllerState(controllerIndex, ref controllerState))
                {
                    bool trigger = (controllerState.ulButtonPressed & (1UL << ((int)Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger))) > 0;
                    if (hit && Clicked != null && trigger)
                    {
                        Clicked();
                    }
                }
            }
        }
    }
Example #3
0
 bool GetIsPressed(SteamVR vr, uint controller)
 {
     if (controller == 0)
         return false;
     var state = new VRControllerState_t();
     var success = vr.hmd.GetControllerState(controller, ref state);
     return (state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0;
 }
        public VRControllerAxis_t rAxis4;          // 0x34

        // Constructors
        public VRControllerState_t_Packed(VRControllerState_t unpacked)
        {
            unPacketNum     = default;
            ulButtonPressed = default;
            ulButtonTouched = default;
            rAxis0          = default;
            rAxis1          = default;
            rAxis2          = default;
            rAxis3          = default;
            rAxis4          = default;
        }         // 0x00000001801DA3F0-0x00000001801DA490
Example #5
0
 // Token: 0x0600200A RID: 8202 RVA: 0x0009E5EC File Offset: 0x0009C7EC
 public void Unpack(ref VRControllerState_t unpacked)
 {
     unpacked.unPacketNum     = this.unPacketNum;
     unpacked.ulButtonPressed = this.ulButtonPressed;
     unpacked.ulButtonTouched = this.ulButtonTouched;
     unpacked.rAxis0          = this.rAxis0;
     unpacked.rAxis1          = this.rAxis1;
     unpacked.rAxis2          = this.rAxis2;
     unpacked.rAxis3          = this.rAxis3;
     unpacked.rAxis4          = this.rAxis4;
 }
		public bool Connect(IMoCapClient_ConnectionInfo connectionInfo)
		{
			connected = VRDevice.isPresent;

			if (connected)
			{
				system = OpenVR.System;
				if (system == null)
				{
					connected = false;
					Debug.LogWarning("Could not find OpenVR System instance.");
				}
				compositor = OpenVR.Compositor;
				if (compositor == null)
				{
					connected = false;
					Debug.LogWarning("Could not find OpenVR Compositor instance.");
				}
			}

			if (connected)
			{
				poses     = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
				gamePoses = new TrackedDevicePose_t[0];

				FindControllerIndices();
				scene.actors  = new Actor[controllerIndices.Length];
				scene.devices = new Device[controllerIndices.Length];
				states        = new VRControllerState_t[controllerIndices.Length];

				for (int idx = 0; idx < controllerIndices.Length; idx++)
				{
					string name = "Controller" + (idx + 1);

					Actor actor        = new Actor(scene, name, idx);
					actor.bones        = new Bone[1];
					actor.bones[0]     = new Bone(actor, "root", 0);
					scene.actors[idx]  = actor;

					Device device      = new Device(scene, name, idx);
					device.channels    = new Channel[7];
					device.channels[0] = new Channel(device, "button1");  // fire
					device.channels[1] = new Channel(device, "button2");  // menu
					device.channels[2] = new Channel(device, "button3");  // grip
					device.channels[3] = new Channel(device, "axis1");    // touchpad + press
					device.channels[4] = new Channel(device, "axis2");
					device.channels[5] = new Channel(device, "axis1raw"); // touchpad touch
					device.channels[6] = new Channel(device, "axis2raw");

					scene.devices[idx] = device;
				}
			}
			return connected;
		}
Example #7
0
 // Token: 0x06002009 RID: 8201 RVA: 0x0009E57C File Offset: 0x0009C77C
 public VRControllerState_t_Packed(VRControllerState_t unpacked)
 {
     this.unPacketNum     = unpacked.unPacketNum;
     this.ulButtonPressed = unpacked.ulButtonPressed;
     this.ulButtonTouched = unpacked.ulButtonTouched;
     this.rAxis0          = unpacked.rAxis0;
     this.rAxis1          = unpacked.rAxis1;
     this.rAxis2          = unpacked.rAxis2;
     this.rAxis3          = unpacked.rAxis3;
     this.rAxis4          = unpacked.rAxis4;
 }
Example #8
0
 // Token: 0x06001EF7 RID: 7927 RVA: 0x0009CBA0 File Offset: 0x0009ADA0
 public bool GetControllerState(uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, uint unControllerStateSize)
 {
     if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
     {
         VRControllerState_t_Packed        vrcontrollerState_t_Packed = new VRControllerState_t_Packed(pControllerState);
         CVRSystem.GetControllerStateUnion getControllerStateUnion;
         getControllerStateUnion.pGetControllerStatePacked = null;
         getControllerStateUnion.pGetControllerState       = this.FnTable.GetControllerState;
         bool result = getControllerStateUnion.pGetControllerStatePacked(unControllerDeviceIndex, ref vrcontrollerState_t_Packed, (uint)Marshal.SizeOf(typeof(VRControllerState_t_Packed)));
         vrcontrollerState_t_Packed.Unpack(ref pControllerState);
         return(result);
     }
     return(this.FnTable.GetControllerState(unControllerDeviceIndex, ref pControllerState, unControllerStateSize));
 }
    // Update is called once per frame
    private void Update()
    {
        VRControllerState_t state = new VRControllerState_t();
        bool success = SteamVR.instance.hmd.GetControllerState((uint)trackedObject.index, ref state);

        if (success == true)
        {
            //SteamVR_Controller.Device device = SteamVR_Controller.Input((int)deviceID);
            //if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger) == true)
            if (SteamVR_Controller.Input((int)trackedObject.index).GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger))
            {
                OnTriggerPressed();
            }

            bool triggerPressed = (state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0;

            if (triggerPressed == true)
            {
                if (triggerIsPressed == false)
                {
                    OnTriggerPressed();
                    triggerIsPressed = true;
                }
            }
            else if (triggerIsPressed == true)
            {
                OnTriggerReleased();
                triggerIsPressed = false;
            }
        }

        if (HeldObject != null)
        {
            if (heldJoint == null)
            {
                Rigidbody rb = HeldObject.GetComponentInParent<Rigidbody>() ?? HeldObject.GetComponentInChildren<Rigidbody>();

                if (rb != null)
                {
                    rb.AddForceAtPosition(Velocity, HeldObject.transform.position);
                }
            }
        }

        if (debug == true)
        {
            Debug.Log(name + " velocity = " + Velocity);
        }
    }
Example #10
0
        public static VRControllerState_t ControllerState(this CVRSystem hmd, int contIndex)
        {
            if (hmd == null) throw new ArgumentNullException(nameof(hmd));
            if (contIndex < 0 || contIndex > OpenVR.k_unMaxTrackedDeviceCount) throw new ArgumentOutOfRangeException(nameof(contIndex));

            VRControllerState_t state = new VRControllerState_t();
            bool success = hmd.GetControllerState((uint)contIndex, ref state);
            if (!success) throw new InvalidOperationException("Unable to retrieve controller state");
            return state;
        }
Example #11
0
 public bool GetControllerStateWithPose(ETrackingUniverseOrigin eOrigin, uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, ref TrackedDevicePose_t pTrackedDevicePose)
 {
     return(this.FnTable.GetControllerStateWithPose(eOrigin, unControllerDeviceIndex, ref pControllerState, ref pTrackedDevicePose));
 }
Example #12
0
	public abstract bool GetControllerStateWithPose(ETrackingUniverseOrigin eOrigin,uint unControllerDeviceIndex,ref VRControllerState_t pControllerState,ref TrackedDevicePose_t pTrackedDevicePose);
Example #13
0
	internal static extern bool VR_IVRRenderModels_GetComponentState(IntPtr instancePtr, string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ComponentState_t pComponentState);
Example #14
0
	public bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ControllerMode_State_t pState,ref RenderModel_ComponentState_t pComponentState)
	{
		bool result = FnTable.GetComponentState(pchRenderModelName,pchComponentName,ref pControllerState,ref pState,ref pComponentState);
		return result;
	}
Example #15
0
 // Token: 0x06001FDB RID: 8155 RVA: 0x0009E15C File Offset: 0x0009C35C
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState)
 {
     if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
     {
         VRControllerState_t_Packed             vrcontrollerState_t_Packed = new VRControllerState_t_Packed(pControllerState);
         CVRRenderModels.GetComponentStateUnion getComponentStateUnion;
         getComponentStateUnion.pGetComponentStatePacked = null;
         getComponentStateUnion.pGetComponentState       = this.FnTable.GetComponentState;
         bool result = getComponentStateUnion.pGetComponentStatePacked(pchRenderModelName, pchComponentName, ref vrcontrollerState_t_Packed, ref pState, ref pComponentState);
         vrcontrollerState_t_Packed.Unpack(ref pControllerState);
         return(result);
     }
     return(this.FnTable.GetComponentState(pchRenderModelName, pchComponentName, ref pControllerState, ref pState, ref pComponentState));
 }
Example #16
0
 public uint GetComponentRenderModelName(string pchRenderModelName, string pchComponentName, StringBuilder pchComponentRenderModelName, uint unComponentRenderModelNameLen) => default;                                                   // 0x00000001811DF2F0-0x00000001811DF320
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState) => default; // 0x00000001811DF320-0x00000001811DF4C0
    private void OnNewPoses(params object[] args)
    {
        if (index == EIndex.None)
            return;

        var i = (int)index;

        isValid = false;
        var poses = (Valve.VR.TrackedDevicePose_t[])args[0];
        if (poses.Length <= i)
            return;

        if (!poses[i].bDeviceIsConnected)
            return;

        if (!poses[i].bPoseIsValid)
            return;

        isValid = true;

        var pose = new SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking);

        if (origin != null)
        {
            pose = new SteamVR_Utils.RigidTransform(origin) * pose;
            pose.pos.x *= origin.localScale.x;
            pose.pos.y *= origin.localScale.y;
            pose.pos.z *= origin.localScale.z;
            transform.position = pose.pos;
            transform.rotation = pose.rot;
        }
        else
        {
            transform.localPosition = pose.pos + pose.rot*offset;
            transform.localRotation = pose.rot*angles;

        }

        var vr = SteamVR.instance;
        var isController = (vr.hmd.GetTrackedDeviceClass((uint)i) == ETrackedDeviceClass.Controller);
        var state = new VRControllerState_t();
        var success = vr.hmd.GetControllerState((uint)i, ref state);
        var triggerPressed = (state.ulButtonPressed & SteamVR_Controller.ButtonMask.Trigger) != 0;

        if (Time.time >= cooldown) {
            if (triggerPressed) {
                Debug.Log ("trigger pressed");
                GameObject bPrefab = Instantiate(bulletPrefab, pose.pos, pose.rot) as GameObject;
                Rigidbody rb = bPrefab.AddComponent<Rigidbody>(); // Add the rigidbody.
                rb.mass = 1; // Set the GO's mass to 5 via the Rigidbody.
                rb.AddForce (pose.rot*Vector3.down * 3000f);
                cooldown = Time.time + attackSpeed;
            }
        }
    }
Example #18
0
 public bool GetComponentState(string pchRenderModelName, string pchComponentName, ref VRControllerState_t pControllerState, ref RenderModel_ControllerMode_State_t pState, ref RenderModel_ComponentState_t pComponentState)
 {
     return(this.FnTable.GetComponentState(pchRenderModelName, pchComponentName, ref pControllerState, ref pState, ref pComponentState));
 }
Example #19
0
	public bool GetControllerState(uint unControllerDeviceIndex,ref VRControllerState_t pControllerState)
	{
		bool result = FnTable.GetControllerState(unControllerDeviceIndex,ref pControllerState);
		return result;
	}
Example #20
0
	public bool GetControllerStateWithPose(ETrackingUniverseOrigin eOrigin,uint unControllerDeviceIndex,ref VRControllerState_t pControllerState,ref TrackedDevicePose_t pTrackedDevicePose)
	{
		bool result = FnTable.GetControllerStateWithPose(eOrigin,unControllerDeviceIndex,ref pControllerState,ref pTrackedDevicePose);
		return result;
	}
Example #21
0
	internal static extern bool VR_IVRSystem_GetControllerState(IntPtr instancePtr, uint unControllerDeviceIndex, ref VRControllerState_t pControllerState);
Example #22
0
	public override bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ComponentState_t pComponentState)
	{
		CheckIfUsable();
		bool result = VRNativeEntrypoints.VR_IVRRenderModels_GetComponentState(m_pVRRenderModels,pchRenderModelName,pchComponentName,ref pControllerState,ref pComponentState);
		return result;
	}
Example #23
0
	public override bool GetControllerState(uint unControllerDeviceIndex,ref VRControllerState_t pControllerState)
	{
		CheckIfUsable();
		bool result = VRNativeEntrypoints.VR_IVRSystem_GetControllerState(m_pVRSystem,unControllerDeviceIndex,ref pControllerState);
		return result;
	}
Example #24
0
	public abstract bool GetControllerState(uint unControllerDeviceIndex,ref VRControllerState_t pControllerState);
        }         // 0x00000001801DA3F0-0x00000001801DA490

        // Methods
        public void Unpack(ref VRControllerState_t unpacked)
        {
        }                                                               // 0x00000001801DA370-0x00000001801DA3F0
Example #26
0
	public abstract bool GetComponentState(string pchRenderModelName,string pchComponentName,ref VRControllerState_t pControllerState,ref RenderModel_ComponentState_t pComponentState);
Example #27
0
 public bool GetControllerState(uint unControllerDeviceIndex, ref VRControllerState_t pControllerState)
 {
     return(this.FnTable.GetControllerState(unControllerDeviceIndex, ref pControllerState));
 }
Example #28
0
	internal static extern bool VR_IVRSystem_GetControllerStateWithPose(IntPtr instancePtr, ETrackingUniverseOrigin eOrigin, uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, ref TrackedDevicePose_t pTrackedDevicePose);
Example #29
0
 public HiddenAreaMesh_t GetHiddenAreaMesh(EVREye eEye, EHiddenAreaMeshType type) => default;                                                                                                                                        // 0x00000001811E06C0-0x00000001811E0700
 public bool GetControllerState(uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, uint unControllerStateSize) => default;                                                                                      // 0x00000001811E0340-0x00000001811E0530
Example #30
0
	public override bool GetControllerStateWithPose(ETrackingUniverseOrigin eOrigin,uint unControllerDeviceIndex,ref VRControllerState_t pControllerState,ref TrackedDevicePose_t pTrackedDevicePose)
	{
		CheckIfUsable();
		bool result = VRNativeEntrypoints.VR_IVRSystem_GetControllerStateWithPose(m_pVRSystem,eOrigin,unControllerDeviceIndex,ref pControllerState,ref pTrackedDevicePose);
		return result;
	}
Example #31
0
 public bool GetControllerState(uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, uint unControllerStateSize) => default;                                                                                      // 0x00000001811E0340-0x00000001811E0530
 public bool GetControllerStateWithPose(ETrackingUniverseOrigin eOrigin, uint unControllerDeviceIndex, ref VRControllerState_t pControllerState, uint unControllerStateSize, ref TrackedDevicePose_t pTrackedDevicePose) => default; // 0x00000001811E0120-0x00000001811E0340