Ejemplo n.º 1
0
        public RigidTransform(SteamVR.HmdMatrix34_t pose)
        {
            var m = Matrix4x4.identity;

            m[0, 0] = pose.m[0 * 4 + 0];
            m[1, 0] = pose.m[1 * 4 + 0];
            m[2, 0] = -pose.m[2 * 4 + 0];

            m[0, 1] = pose.m[0 * 4 + 1];
            m[1, 1] = pose.m[1 * 4 + 1];
            m[2, 1] = -pose.m[2 * 4 + 1];

            m[0, 2] = -pose.m[0 * 4 + 2];
            m[1, 2] = -pose.m[1 * 4 + 2];
            m[2, 2] = pose.m[2 * 4 + 2];

            m[0, 3] = pose.m[0 * 4 + 3];
            m[1, 3] = pose.m[1 * 4 + 3];
            m[2, 3] = -pose.m[2 * 4 + 3];

            this.pos = m.GetPosition();
            this.rot = m.GetRotation();
        }
Ejemplo n.º 2
0
    void Start()
    {
        Debug.Log("Testing SteamVR...");

        var hmd = SteamVR.IHmd.instance;

        if (hmd == null)
        {
            return;
        }

        int  x = 0, y = 0;
        uint w = 0, h = 0;

        hmd.GetWindowBounds(ref x, ref y, ref w, ref h);
        Debug.Log(string.Format("GetWindowBounds: {0} {1} {2} {3}", x, y, w, h));

        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        Debug.Log(string.Format("GetRecommendedRenderTargetSize: {0} {1}", w, h));

        uint X = 0, Y = 0;

        hmd.GetEyeOutputViewport(SteamVR.Hmd_Eye.Eye_Left, ref X, ref Y, ref w, ref h);
        Debug.Log(string.Format("GetEyeOutputViewport:L {0} {1} {2} {3}", X, Y, w, h));

        hmd.GetEyeOutputViewport(SteamVR.Hmd_Eye.Eye_Right, ref X, ref Y, ref w, ref h);
        Debug.Log(string.Format("GetEyeOutputViewport:R {0} {1} {2} {3}", X, Y, w, h));

        var m = hmd.GetProjectionMatrix(SteamVR.Hmd_Eye.Eye_Left, 1.0f, 1000.0f, SteamVR.GraphicsAPIConvention.API_DirectX);

        Debug.Log(string.Format("GetProjectionMatrix: {0}", m));

        float left = 0.0f, right = 0.0f, top = 0.0f, bottom = 0.0f;

        hmd.GetProjectionRaw(SteamVR.Hmd_Eye.Eye_Left, ref left, ref right, ref top, ref bottom);
        Debug.Log(string.Format("GetProjectionRaw: {0} {1} {2} {3}", left, right, top, bottom));

        var coords = hmd.ComputeDistortion(SteamVR.Hmd_Eye.Eye_Left, 0.5f, 0.5f);

        Debug.Log(string.Format("ComputeDistortion: {0}", coords));

        var eye = hmd.GetHeadFromEyePose(SteamVR.Hmd_Eye.Eye_Left);

        Debug.Log(string.Format("GetHeadFromEyePose: {0}", eye));

        var result = SteamVR.HmdTrackingResult.TrackingResult_Uninitialized;

        SteamVR.HmdMatrix44_t mL = new SteamVR.HmdMatrix44_t(), mR = new SteamVR.HmdMatrix44_t();
        if (hmd.GetViewMatrix(0.0f, ref mL, ref mR, ref result))
        {
            Debug.Log(string.Format("GetViewMatrix: {0} {1}", mL, mR));
        }
        else
        {
            Debug.Log(string.Format("GetViewMatrix: {0}", result));
        }

        var adapter = hmd.GetD3D9AdapterIndex();

        Debug.Log("GetD3D9AdapterIndex: " + adapter);

        var pose    = new SteamVR.HmdMatrix34_t();

        if (hmd.GetTrackerFromHeadPose(0.0f, ref pose, ref result))
        {
            Debug.Log("GetTrackerFromHeadPose: " + pose);
        }
        else
        {
            Debug.Log("GetTrackerFromHeadPose: " + result);
        }

        if (hmd.WillDriftInYaw())
        {
            Debug.Log("WillDriftInYaw:yes");
        }
        else
        {
            Debug.Log("WillDriftInYaw:no");
        }

        hmd.ZeroTracker();

        var zero    = hmd.GetTrackerZeroPose();

        Debug.Log("GetTrackerZeroPose: " + zero);

        var driverId = hmd.GetDriverId();

        Debug.Log("DriverId: " + driverId);

        var displayId = hmd.GetDisplayId();

        Debug.Log("DisplayId: " + displayId);

        var version = SteamVR.IHmd_Version();

        Debug.Log("IHmd_Version: " + version);
    }
Ejemplo n.º 3
0
    public void UpdateTracking()
    {
        var head = SteamVR_Utils.RigidTransform.identity;

        if (!disableTracking)
        {
            var hmd  = SteamVR.IHmd.instance;
            var pose = new SteamVR.HmdMatrix34_t();
            if (Time.renderedFrameCount != renderedFrameCount)
            {
                renderedFrameCount = Time.renderedFrameCount;

                var result = SteamVR.HmdTrackingResult.TrackingResult_Uninitialized;
                if (hmd.GetTrackerFromHeadPose(0.0f, ref pose, ref result))
                {
                    head = new SteamVR_Utils.RigidTransform(pose);
                }

                var calibrating =
                    result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_InProgress ||
                    result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_OutOfRange;
                if (calibrating != SteamVR_Camera.calibrating)
                {
                    SteamVR_Utils.Event.Send("calibrating", calibrating);
                }

                var trackingOutOfRange =
                    result == SteamVR.HmdTrackingResult.TrackingResult_Running_OutOfRange ||
                    result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_OutOfRange;
                if (trackingOutOfRange != SteamVR_Camera.trackingOutOfRange)
                {
                    SteamVR_Utils.Event.Send("absolute_tracking", !trackingOutOfRange);
                }
            }
            else
            {
                if (hmd.GetLastTrackerFromHeadPose(ref pose))
                {
                    head = new SteamVR_Utils.RigidTransform(pose);
                }
            }
        }

        offset.localPosition = head.pos;
        offset.localRotation = head.rot;

        // Update shared optional overlay shader variables
        if (overlaySettings.texture != null && applyDistortion)
        {
            distortMaterial.SetFloat("alpha", Mathf.Clamp01(overlaySettings.alpha));
            distortMaterial.SetVector("uvOffset", overlaySettings.uvOffset);

            var rot = Matrix4x4.identity;
            rot.SetColumn(0, head.rot * Vector3.right);
            rot.SetColumn(1, head.rot * Vector3.up);
            rot.SetColumn(2, head.rot * Vector3.forward);
            distortMaterial.SetMatrix("rot", rot);

            float aspect = (float)overlaySettings.texture.width / overlaySettings.texture.height;
            if (overlaySettings.curved)
            {
                var range = new Vector2(0.1f, 1.0f);                 // probably should make this tweakable
                var theta = Mathf.Lerp(60.0f, 5.0f, Mathf.SmoothStep(range.x, range.y, -offset.localPosition.z));
                var coef  = new Vector4(2.0f * theta * Mathf.Deg2Rad, aspect / overlaySettings.scale, aspect, 2.0f * overlaySettings.distance);
                distortMaterial.SetVector("coef", coef);
                overlaySettings.radius = overlaySettings.scale / coef.x;
            }
            else
            {
                var coef = new Vector4(1.0f / overlaySettings.scale, aspect / overlaySettings.scale, 0, 0);
                distortMaterial.SetVector("coef", coef);
                overlaySettings.radius = 0.0f;
            }
        }
    }
Ejemplo n.º 4
0
	public void UpdateTracking()
	{
		var head = SteamVR_Utils.RigidTransform.identity;
		if (!disableTracking)
		{
			var hmd = SteamVR.IHmd.instance;
			var pose = new SteamVR.HmdMatrix34_t();
			if (Time.renderedFrameCount != renderedFrameCount)
			{
				renderedFrameCount = Time.renderedFrameCount;

				var result = SteamVR.HmdTrackingResult.TrackingResult_Uninitialized;
				if (hmd.GetTrackerFromHeadPose(0.0f, ref pose, ref result))
					head = new SteamVR_Utils.RigidTransform(pose);

				var calibrating =
					result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_InProgress ||
					result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_OutOfRange;
				if (calibrating != SteamVR_Camera.calibrating)
				{
					SteamVR_Utils.Event.Send("calibrating", calibrating);
				}

				var trackingOutOfRange =
					result == SteamVR.HmdTrackingResult.TrackingResult_Running_OutOfRange ||
					result == SteamVR.HmdTrackingResult.TrackingResult_Calibrating_OutOfRange;
				if (trackingOutOfRange != SteamVR_Camera.trackingOutOfRange)
				{
					SteamVR_Utils.Event.Send("absolute_tracking", !trackingOutOfRange);
				}
			}
			else
			{
				if (hmd.GetLastTrackerFromHeadPose(ref pose))
					head = new SteamVR_Utils.RigidTransform(pose);
			}
		}

		offset.localPosition = head.pos;
		offset.localRotation = head.rot;

		// Update shared optional overlay shader variables
		if (overlaySettings.texture != null && applyDistortion)
		{
			distortMaterial.SetFloat("alpha", Mathf.Clamp01(overlaySettings.alpha));
			distortMaterial.SetVector("uvOffset", overlaySettings.uvOffset);

			var rot = Matrix4x4.identity;
			rot.SetColumn(0, head.rot * Vector3.right);
			rot.SetColumn(1, head.rot * Vector3.up);
			rot.SetColumn(2, head.rot * Vector3.forward);
			distortMaterial.SetMatrix("rot", rot);

			float aspect = (float)overlaySettings.texture.width / overlaySettings.texture.height;
			if (overlaySettings.curved)
			{
				var range = new Vector2(0.1f, 1.0f); // probably should make this tweakable
				var theta = Mathf.Lerp(60.0f, 5.0f, Mathf.SmoothStep(range.x, range.y, -offset.localPosition.z));
				var coef = new Vector4(2.0f * theta * Mathf.Deg2Rad, aspect / overlaySettings.scale, aspect, 2.0f * overlaySettings.distance);
				distortMaterial.SetVector("coef", coef);
				overlaySettings.radius = overlaySettings.scale / coef.x;
			}
			else
			{
				var coef = new Vector4(1.0f / overlaySettings.scale, aspect / overlaySettings.scale, 0, 0);
				distortMaterial.SetVector("coef", coef);
				overlaySettings.radius = 0.0f;
			}
		}
	}
Ejemplo n.º 5
0
    void Start()
    {
        Debug.Log("Testing SteamVR...");

        var hmd = SteamVR.IHmd.instance;
        if (hmd == null)
            return;

        int x = 0, y = 0;
        uint w = 0, h = 0;

        hmd.GetWindowBounds(ref x, ref y, ref w, ref h);
        Debug.Log(string.Format("GetWindowBounds: {0} {1} {2} {3}", x, y, w, h));

        hmd.GetRecommendedRenderTargetSize(ref w, ref h);
        Debug.Log(string.Format("GetRecommendedRenderTargetSize: {0} {1}", w, h));

        uint X = 0, Y = 0;
        hmd.GetEyeOutputViewport(SteamVR.Hmd_Eye.Eye_Left, ref X, ref Y, ref w, ref h);
        Debug.Log(string.Format("GetEyeOutputViewport:L {0} {1} {2} {3}", X, Y, w, h));

        hmd.GetEyeOutputViewport(SteamVR.Hmd_Eye.Eye_Right, ref X, ref Y, ref w, ref h);
        Debug.Log(string.Format("GetEyeOutputViewport:R {0} {1} {2} {3}", X, Y, w, h));

        var m = hmd.GetProjectionMatrix(SteamVR.Hmd_Eye.Eye_Left, 1.0f, 1000.0f, SteamVR.GraphicsAPIConvention.API_DirectX);
        Debug.Log(string.Format("GetProjectionMatrix: {0}", m));

        float left = 0.0f, right = 0.0f, top = 0.0f, bottom = 0.0f;
        hmd.GetProjectionRaw(SteamVR.Hmd_Eye.Eye_Left, ref left, ref right, ref top, ref bottom);
        Debug.Log(string.Format("GetProjectionRaw: {0} {1} {2} {3}", left, right, top, bottom));

        var coords = hmd.ComputeDistortion(SteamVR.Hmd_Eye.Eye_Left, 0.5f, 0.5f);
        Debug.Log(string.Format("ComputeDistortion: {0}", coords));

        var eye = hmd.GetHeadFromEyePose(SteamVR.Hmd_Eye.Eye_Left);
        Debug.Log(string.Format("GetHeadFromEyePose: {0}", eye));

        var result = SteamVR.HmdTrackingResult.TrackingResult_Uninitialized;
        SteamVR.HmdMatrix44_t mL = new SteamVR.HmdMatrix44_t(), mR = new SteamVR.HmdMatrix44_t();
        if (hmd.GetViewMatrix(0.0f, ref mL, ref mR, ref result))
            Debug.Log(string.Format("GetViewMatrix: {0} {1}", mL, mR));
        else
            Debug.Log(string.Format("GetViewMatrix: {0}", result));

        var adapter = hmd.GetD3D9AdapterIndex();
        Debug.Log("GetD3D9AdapterIndex: " + adapter);

        var pose = new SteamVR.HmdMatrix34_t();
        if (hmd.GetTrackerFromHeadPose(0.0f, ref pose, ref result))
            Debug.Log("GetTrackerFromHeadPose: " + pose);
        else
            Debug.Log("GetTrackerFromHeadPose: " + result);

        if (hmd.WillDriftInYaw())
            Debug.Log("WillDriftInYaw:yes");
        else
            Debug.Log("WillDriftInYaw:no");

        hmd.ZeroTracker();

        var zero = hmd.GetTrackerZeroPose();
        Debug.Log("GetTrackerZeroPose: " + zero);

        var driverId = hmd.GetDriverId();
        Debug.Log("DriverId: " + driverId);

        var displayId = hmd.GetDisplayId();
        Debug.Log("DisplayId: " + displayId);

        var version = SteamVR.IHmd_Version();
        Debug.Log("IHmd_Version: " + version);
    }