Exemplo n.º 1
0
        public RigidTransform(HmdMatrix44_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[3, 0] = pose.m[3 * 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[3, 1] = pose.m[3 * 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[3, 2] = -pose.m[3 * 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];
            m[3, 3] = pose.m[3 * 4 + 3];

            this.pos = m.GetPosition();
            this.rot = m.GetRotation();
        }
Exemplo n.º 2
0
        public static Matrix ToProjMatrix(this HmdMatrix44_t pose)
        {
            var m = Matrix.Identity;

            m[0, 0] = pose.m0;
            m[0, 1] = pose.m1;
            m[0, 2] = -pose.m2;
            m[0, 3] = pose.m3;

            m[1, 0] = pose.m4;
            m[1, 1] = pose.m5;
            m[1, 2] = -pose.m6;
            m[1, 3] = pose.m7;

            m[2, 0] = pose.m8;
            m[2, 1] = pose.m9;
            m[2, 2] = -pose.m10;
            m[2, 3] = pose.m11;

            m[3, 0] = -pose.m12;
            m[3, 1] = -pose.m13;
            m[3, 2] = -pose.m14;
            m[3, 3] = -pose.m15;

            m.Transpose();

            return(m);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Populates the list of cameras according to the cameras that should be used for
        /// the current game scene.
        /// </summary>
        /// <param name="cameraNames">An array of camera names to use for this VR scene.</param>
        private void PopulateCameraList(string[] cameraNames)
        {
            // search for the cameras to render
            NumVRCameras = cameraNames.Length;
            VRCameras    = new Types.CameraData[NumVRCameras];
            for (int i = 0; i < NumVRCameras; i++)
            {
                Camera foundCamera = Array.Find(Camera.allCameras, cam => cam.name.Equals(cameraNames[i]));
                if (foundCamera == null)
                {
                    Utils.LogError("Could not find camera \"" + cameraNames[i] + "\" in the scene!");
                }
                else
                {
                    // determine clip plane and new projection matrices
                    float         nearClipPlane     = (foundCamera.name.Equals("Camera 01")) ? 0.05f : foundCamera.nearClipPlane;
                    HmdMatrix44_t projectionMatrixL = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Left, nearClipPlane, foundCamera.farClipPlane);
                    HmdMatrix44_t projectionMatrixR = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Right, nearClipPlane, foundCamera.farClipPlane);

                    // store information about the camera
                    VRCameras[i].camera = foundCamera;
                    VRCameras[i].originalProjectionMatrix = foundCamera.projectionMatrix;
                    VRCameras[i].hmdProjectionMatrixL     = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixL);
                    VRCameras[i].hmdProjectionMatrixR     = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixR);

                    // disable the camera so we can call Render directly
                    foundCamera.enabled = false;
                }
            }
        }
Exemplo n.º 4
0
        public HmdMatrix44_t ToHmdMatrix44()
        {
            var m    = Matrix4x4.TRS(pos, rot, Vector3.one);
            var pose = new HmdMatrix44_t();

            pose.m = new float[16];

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

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

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

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

            return(pose);
        }
Exemplo n.º 5
0
        public RigidTransform(HmdMatrix44_t pose)
        {
            var m = Matrix4x4.identity;

            m[0, 0] = pose.m0;
            m[0, 1] = pose.m1;
            m[0, 2] = -pose.m2;
            m[0, 3] = pose.m3;

            m[1, 0] = pose.m4;
            m[1, 1] = pose.m5;
            m[1, 2] = -pose.m6;
            m[1, 3] = pose.m7;

            m[2, 0] = -pose.m8;
            m[2, 1] = -pose.m9;
            m[2, 2] = pose.m10;
            m[2, 3] = -pose.m11;

            m[3, 0] = pose.m12;
            m[3, 1] = pose.m13;
            m[3, 2] = -pose.m14;
            m[3, 3] = pose.m15;

            this.pos = m.GetPosition();
            this.rot = m.GetRotation();
        }
Exemplo n.º 6
0
        public HmdMatrix44_t ToHmdMatrix44()
        {
            var m    = Matrix4x4.TRS(pos, rot, Vector3.one);
            var pose = new HmdMatrix44_t();

            pose.m0 = m[0, 0];
            pose.m1 = m[0, 1];
            pose.m2 = -m[0, 2];
            pose.m3 = m[0, 3];

            pose.m4 = m[1, 0];
            pose.m5 = m[1, 1];
            pose.m6 = -m[1, 2];
            pose.m7 = m[1, 3];

            pose.m8  = -m[2, 0];
            pose.m9  = -m[2, 1];
            pose.m10 = m[2, 2];
            pose.m11 = -m[2, 3];

            pose.m12 = m[3, 0];
            pose.m13 = m[3, 1];
            pose.m14 = -m[3, 2];
            pose.m15 = m[3, 3];

            return(pose);
        }
Exemplo n.º 7
0
        void Awake()
        {
            NodeType = VRNodeType.Head;

            LeftCamera = new GameObject("LeftCamera").AddComponent <Camera>();
            LeftCamera.transform.parent = transform;
            VREye leftEye = LeftCamera.gameObject.AddComponent <VREye>();

            leftEye.EyeType = EVREye.Eye_Left;
            leftEye.Init(this);
            SteamVR_Utils.RigidTransform leftEyeTransform = new SteamVR_Utils.RigidTransform(OpenVR.System.GetEyeToHeadTransform(EVREye.Eye_Left));
            LeftCamera.transform.localPosition = leftEyeTransform.pos;
            LeftCamera.transform.localRotation = leftEyeTransform.rot;
            LeftCamera.targetTexture           = VRManager.Instance.LeftEyeRenderTexture;
            LeftCamera.nearClipPlane           = 0.01f;
            HmdMatrix44_t leftEyeProjectionMatrix = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Left, LeftCamera.nearClipPlane, LeftCamera.farClipPlane);

            LeftCamera.projectionMatrix = Utils.Matrix4x4_OpenVr2UnityFormat(ref leftEyeProjectionMatrix);

            RightCamera = new GameObject("RightCamera").AddComponent <Camera>();
            RightCamera.transform.parent = transform;
            VREye rightEye = RightCamera.gameObject.AddComponent <VREye>();

            rightEye.EyeType = EVREye.Eye_Right;
            rightEye.Init(this);
            SteamVR_Utils.RigidTransform rightEyeTransform = new SteamVR_Utils.RigidTransform(OpenVR.System.GetEyeToHeadTransform(EVREye.Eye_Right));
            RightCamera.transform.localPosition = rightEyeTransform.pos;
            RightCamera.transform.localRotation = rightEyeTransform.rot;
            RightCamera.targetTexture           = VRManager.Instance.RightEyeRenderTexture;
            RightCamera.nearClipPlane           = 0.01f;
            HmdMatrix44_t rightEyeProjectionMatrix = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Right, RightCamera.nearClipPlane, RightCamera.farClipPlane);

            RightCamera.projectionMatrix = Utils.Matrix4x4_OpenVr2UnityFormat(ref rightEyeProjectionMatrix);
        }
Exemplo n.º 8
0
        public static Matrix ToProjectionMatrix(this HmdMatrix44_t m)
        {
            return(new Matrix()
            {
                M11 = m.m0,
                M12 = m.m4,
                M13 = m.m8,
                M14 = m.m12,

                M21 = m.m1,
                M22 = m.m5,
                M23 = m.m9,
                M24 = m.m13,

                M31 = -m.m2,
                M32 = -m.m6,
                M33 = -m.m10,
                M34 = -m.m14,

                M41 = m.m3,
                M42 = m.m7,
                M43 = m.m11,
                M44 = m.m15
            });
        }
Exemplo n.º 9
0
 public static Matrix Convert(this HmdMatrix44_t mat)
 {
     return(new Matrix(
                mat.m0, mat.m4, mat.m8, mat.m12,
                mat.m1, mat.m5, mat.m9, mat.m13,
                mat.m2, mat.m6, mat.m10, mat.m14,
                mat.m3, mat.m7, mat.m11, mat.m15));
 }
Exemplo n.º 10
0
 private static Matrix4x4 ToSysMatrix(HmdMatrix44_t hmdMat)
 {
     return(new Matrix4x4(
                hmdMat.m0, hmdMat.m4, hmdMat.m8, hmdMat.m12,
                hmdMat.m1, hmdMat.m5, hmdMat.m9, hmdMat.m13,
                hmdMat.m2, hmdMat.m6, hmdMat.m10, hmdMat.m14,
                hmdMat.m3, hmdMat.m7, hmdMat.m11, hmdMat.m15));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the projection for an eye view point.
        /// </summary>
        /// <param name="lefteye">Left or right.</param>
        /// <param name="znear">Near plane.</param>
        /// <param name="zfar">Far plane.</param>
        /// <returns>Eye projection.</returns>
        public Matrix4 GetProjection(bool lefteye, float znear, float zfar)
        {
            HmdMatrix44_t temp = VR.GetProjectionMatrix(!lefteye ? EVREye.Eye_Left : EVREye.Eye_Right, znear, zfar, EGraphicsAPIConvention.API_OpenGL);
            Matrix4       proj = new Matrix4(temp.m0, temp.m1, temp.m2, temp.m3, temp.m4, temp.m5, temp.m6, temp.m7, temp.m8, temp.m9, temp.m10, temp.m11, temp.m12, temp.m13, temp.m14, temp.m15);

            proj.Transpose();
            return(proj);
        }
Exemplo n.º 12
0
 public static Matrix4 ToGLMatrix4(this HmdMatrix44_t matPose)
 {
     return(new Matrix4(
                matPose.m0, matPose.m4, matPose.m8, matPose.m12,
                matPose.m1, matPose.m5, matPose.m9, matPose.m13,
                matPose.m2, matPose.m6, matPose.m10, matPose.m14,
                matPose.m3, matPose.m7, matPose.m11, matPose.m15
                ));
 }
Exemplo n.º 13
0
 private static Matrix ToSysMatrix(HmdMatrix44_t hmdMat)
 {
     // DOESN'T include RH to LH conversion (since projection matrices are now built from raw data instead)
     return(new Matrix(
                hmdMat.m0, hmdMat.m4, hmdMat.m8, hmdMat.m12,
                hmdMat.m1, hmdMat.m5, hmdMat.m9, hmdMat.m13,
                hmdMat.m2, hmdMat.m6, hmdMat.m10, hmdMat.m14,
                hmdMat.m3, hmdMat.m7, hmdMat.m11, hmdMat.m15));
 }
Exemplo n.º 14
0
        //private float SecondsUntilPhotons()
        //{
        //    // https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetDeviceToAbsoluteTrackingPose
        //    var secondsSinceLastVsync = 0f;
        //    var pulFrameCounter = 0UL;
        //    _vrSystem.GetTimeSinceLastVsync(ref secondsSinceLastVsync, ref pulFrameCounter);
        //    var predictedSecondsFromNow = _frameDuration - secondsSinceLastVsync + _vsyncToPhotons;
        //    return predictedSecondsFromNow;
        //}

        private Matrix ToMonogameMatrix(HmdMatrix44_t mat)
        {
            var output = new Matrix(
                mat.m0, mat.m1, mat.m2, mat.m3,
                mat.m4, mat.m5, mat.m6, mat.m7,
                mat.m8, mat.m9, mat.m10, mat.m11,
                mat.m12, mat.m13, mat.m14, mat.m15);

            return(output);
        }
Exemplo n.º 15
0
        public static Matrix ToXNA(this HmdMatrix44_t mat)
        {
            var m = new Matrix(
                mat.m0, mat.m4, mat.m8, mat.m12,
                mat.m1, mat.m5, mat.m9, mat.m13,
                mat.m2, mat.m6, mat.m10, mat.m14,
                mat.m3, mat.m7, mat.m11, mat.m15);

            return(m);
        }
Exemplo n.º 16
0
        public static Matrix4 convertToMatrix4(HmdMatrix44_t m)
        {
            Matrix4 mat = new Matrix4(
                m.m0, m.m4, m.m8, m.m12,
                m.m1, m.m5, m.m9, m.m13,
                m.m2, m.m6, m.m10, m.m14,
                m.m3, m.m7, m.m11, m.m15
                );

            return(mat);
        }
Exemplo n.º 17
0
    void Awake()
    {
        newPosesAction = SteamVR_Events.NewPosesAction(OnNewPoses);
        HmdMatrix44_t mat = new HmdMatrix44_t();


        /**************************************/

        /*
         * -0.102501    0.19387   0.975658   0.690977
         * 0.00933648   0.980968  -0.193944   0.545085
         * -0.994689 -0.0107702   -0.10236  -0.111363
         * 0            0			0           1
         */
        /*
         * mat.m0 = -0.102501f;
         * mat.m1 = 0.19387f;
         * mat.m2 = 0.975658f;
         * mat.m3 = 0.690977f;
         * mat.m4 = 0.00933648f;
         * mat.m5 = 0.980968f;
         * mat.m6 = -0.193944f;
         * mat.m7 = 0.545085f;
         * mat.m8 = -0.994689f;
         * mat.m9 = -0.0107702f;
         * mat.m10 = -0.10236f;
         * mat.m11 = -0.111363f;
         * mat.m12 = 0;
         * mat.m13 = 0;
         * mat.m14 = 0;
         * mat.m15 = 1;
         */
        mat.m0  = -0.102501f;
        mat.m4  = 0.19387f;
        mat.m8  = 0.975658f;
        mat.m12 = 0.690977f;
        mat.m1  = 0.00933648f;
        mat.m5  = 0.980968f;
        mat.m9  = -0.193944f;
        mat.m13 = 0.545085f;
        mat.m2  = -0.994689f;
        mat.m6  = -0.0107702f;
        mat.m10 = -0.10236f;
        mat.m14 = -0.111363f;
        mat.m3  = 0;
        mat.m7  = 0;
        mat.m11 = 0;
        mat.m15 = 1;

        /**************************************/

        BMatInv = new SteamVR_Utils.RigidTransform(mat);
        BMatInv.Inverse();
    }
Exemplo n.º 18
0
 public static void ToMatrix4(ref HmdMatrix44_t matrix, out Matrix4 result)
 {
     result = new Matrix4(
         matrix.m0,
         matrix.m4,
         matrix.m8,
         matrix.m12,
         matrix.m1,
         matrix.m5,
         matrix.m9,
         matrix.m13,
         matrix.m2,
         matrix.m6,
         matrix.m10,
         matrix.m14,
         matrix.m3,
         matrix.m7,
         matrix.m11,
         matrix.m15
         );
 }
Exemplo n.º 19
0
        /// <summary>
        /// Converts <see cref="HmdMatrix44_t"/> to <see cref="Matrix"/>
        /// </summary>
        /// <param name="ovrMatrix34f">The input.</param>
        /// <param name="matrix">The output.</param>
        public static void ToMatrix(this HmdMatrix44_t ovrMatrix34f, out Matrix matrix)
        {
            // NOTE: automatic conversion from RH to LH

            matrix.M11 = ovrMatrix34f.m0;
            matrix.M12 = ovrMatrix34f.m4;
            matrix.M13 = -ovrMatrix34f.m8;
            matrix.M14 = ovrMatrix34f.m12;
            matrix.M21 = ovrMatrix34f.m1;
            matrix.M22 = ovrMatrix34f.m5;
            matrix.M23 = -ovrMatrix34f.m9;
            matrix.M24 = ovrMatrix34f.m13;
            matrix.M31 = -ovrMatrix34f.m2;
            matrix.M32 = -ovrMatrix34f.m6;
            matrix.M33 = ovrMatrix34f.m10;
            matrix.M34 = -ovrMatrix34f.m14;
            matrix.M41 = ovrMatrix34f.m3;
            matrix.M42 = ovrMatrix34f.m7;
            matrix.M43 = -ovrMatrix34f.m11;
            matrix.M44 = ovrMatrix34f.m15;
        }
Exemplo n.º 20
0
        /// <summary>
        /// Convert an ovrMatrix44f to a Wave Matrix.
        /// </summary>
        /// <param name="ovrMatrix34f">ovrMatrix44f to convert to a Wave Matrix.</param>
        /// <param name="matrix">Wave Matrix, based on the ovrMatrix4f.</param>
        public static void ToMatrix(this HmdMatrix44_t ovrMatrix34f, out Matrix matrix)
        {
            matrix.M11 = ovrMatrix34f.m0;
            matrix.M12 = ovrMatrix34f.m4;
            matrix.M13 = ovrMatrix34f.m8;
            matrix.M14 = ovrMatrix34f.m12;

            matrix.M21 = ovrMatrix34f.m1;
            matrix.M22 = ovrMatrix34f.m5;
            matrix.M23 = ovrMatrix34f.m9;
            matrix.M24 = ovrMatrix34f.m13;

            matrix.M31 = ovrMatrix34f.m2;
            matrix.M32 = ovrMatrix34f.m6;
            matrix.M33 = ovrMatrix34f.m10;
            matrix.M34 = ovrMatrix34f.m14;

            matrix.M41 = ovrMatrix34f.m3;
            matrix.M42 = ovrMatrix34f.m7;
            matrix.M43 = ovrMatrix34f.m11;
            matrix.M44 = ovrMatrix34f.m15;
        }
Exemplo n.º 21
0
        public static Matrix4x4 Matrix4x4_OpenVr2UnityFormat(ref HmdMatrix44_t mat44_openvr)
        {
            Matrix4x4 mat44_unity = Matrix4x4.identity;

            mat44_unity.m00 = mat44_openvr.m0;
            mat44_unity.m01 = mat44_openvr.m1;
            mat44_unity.m02 = mat44_openvr.m2;
            mat44_unity.m03 = mat44_openvr.m3;
            mat44_unity.m10 = mat44_openvr.m4;
            mat44_unity.m11 = mat44_openvr.m5;
            mat44_unity.m12 = mat44_openvr.m6;
            mat44_unity.m13 = mat44_openvr.m7;
            mat44_unity.m20 = mat44_openvr.m8;
            mat44_unity.m21 = mat44_openvr.m9;
            mat44_unity.m22 = mat44_openvr.m10;
            mat44_unity.m23 = mat44_openvr.m11;
            mat44_unity.m30 = mat44_openvr.m12;
            mat44_unity.m31 = mat44_openvr.m13;
            mat44_unity.m32 = mat44_openvr.m14;
            mat44_unity.m33 = mat44_openvr.m15;
            return(mat44_unity);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Populates the list of cameras according to the cameras that should be used for
        /// the current game scene.
        /// </summary>
        /// <param name="cameraNames">An array of camera names to use for this VR scene.</param>
        private void PopulateCameraList(string[] cameraNames)
        {
            // search for the cameras to render
            NumVRCameras = cameraNames.Length;
            VRCameras    = new Types.CameraData[NumVRCameras];
            for (int i = 0; i < NumVRCameras; i++)
            {
                Camera foundCamera = Array.Find(Camera.allCameras, cam => cam.name.Equals(cameraNames[i]));
                if (foundCamera == null)
                {
                    Utils.LogError("Could not find camera \"" + cameraNames[i] + "\" in the scene!");
                }
                else
                {
                    // determine clip plane and new projection matrices
                    HmdMatrix44_t projectionMatrixL = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Left, foundCamera.nearClipPlane, foundCamera.farClipPlane);
                    HmdMatrix44_t projectionMatrixR = OpenVR.System.GetProjectionMatrix(EVREye.Eye_Right, foundCamera.nearClipPlane, foundCamera.farClipPlane);

                    // store information about the camera
                    VRCameras[i].camera = foundCamera;
                    VRCameras[i].originalProjectionMatrix = foundCamera.projectionMatrix;
                    VRCameras[i].hmdProjectionMatrixL     = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixL);
                    VRCameras[i].hmdProjectionMatrixR     = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projectionMatrixR);

                    // disable the camera so we can call Render directly
                    foundCamera.enabled = false;

                    // cache the galaxy camera object, we'll need to call on it directly during eyeball positioning
                    if (foundCamera.name == "GalaxyCamera")
                    {
                        galaxyCamera = foundCamera.gameObject;
                    }
                    else if (foundCamera.name == "Landscape Camera")
                    {
                        landscapeCamera = foundCamera.gameObject;
                    }
                }
            }
        }
Exemplo n.º 23
0
        private static Matrix Convert(HmdMatrix44_t source)
        {
            var destination = new Matrix();

            destination.M11 = source.m0;
            destination.M21 = source.m1;
            destination.M31 = source.m2;
            destination.M41 = source.m3;
            destination.M12 = source.m4;
            destination.M22 = source.m5;
            destination.M32 = source.m6;
            destination.M42 = source.m7;
            destination.M13 = source.m8;
            destination.M23 = source.m9;
            destination.M33 = source.m10;
            destination.M43 = source.m11;
            destination.M14 = source.m12;
            destination.M24 = source.m13;
            destination.M34 = source.m14;
            destination.M44 = source.m15;

            return(destination);
        }
Exemplo n.º 24
0
        public bool startStream()
        {
            myVideoSignalTime = TimeSource.now();
            OpenVR.TrackedCamera.AcquireVideoStreamingService(OpenVR.k_unTrackedDeviceIndex_Hmd, ref myHandle);
            if (myHandle == 0)
            {
                Warn.print("AcquireVideoStreamingService() failed");
                return(false);
            }

            HmdMatrix44_t         proj  = new HmdMatrix44_t();
            EVRTrackedCameraError error = OpenVR.TrackedCamera.GetCameraProjection(OpenVR.k_unTrackedDeviceIndex_Hmd, myFrameType, 0.01f, 10.0f, ref proj);

            if (error != EVRTrackedCameraError.None)
            {
                Warn.print("Error getting camera projection");
            }
            myProjection = VR.convertToMatrix4(proj);

            Info.print("Started VR Camera stream");
            myIsStreaming = true;
            return(true);
        }
Exemplo n.º 25
0
        // Token: 0x06005FD5 RID: 24533 RVA: 0x0021B600 File Offset: 0x00219A00
        public RigidTransform(HmdMatrix44_t pose)
        {
            Matrix4x4 identity = Matrix4x4.identity;

            identity[0, 0] = pose.m0;
            identity[0, 1] = pose.m1;
            identity[0, 2] = -pose.m2;
            identity[0, 3] = pose.m3;
            identity[1, 0] = pose.m4;
            identity[1, 1] = pose.m5;
            identity[1, 2] = -pose.m6;
            identity[1, 3] = pose.m7;
            identity[2, 0] = -pose.m8;
            identity[2, 1] = -pose.m9;
            identity[2, 2] = pose.m10;
            identity[2, 3] = -pose.m11;
            identity[3, 0] = pose.m12;
            identity[3, 1] = pose.m13;
            identity[3, 2] = -pose.m14;
            identity[3, 3] = pose.m15;
            this.pos       = identity.GetPosition();
            this.rot       = identity.GetRotation();
        }
Exemplo n.º 26
0
        public RigidTransform(HmdMatrix44_t pose)
        {
            Matrix4x4 identity = Matrix4x4.identity;

            identity.m00 = pose.m0;
            identity.m01 = pose.m1;
            identity.m02 = -pose.m2;
            identity.m03 = pose.m3;
            identity.m10 = pose.m4;
            identity.m11 = pose.m5;
            identity.m12 = -pose.m6;
            identity.m13 = pose.m7;
            identity.m20 = -pose.m8;
            identity.m21 = -pose.m9;
            identity.m22 = pose.m10;
            identity.m23 = -pose.m11;
            identity.m30 = pose.m12;
            identity.m31 = pose.m13;
            identity.m32 = -pose.m14;
            identity.m33 = pose.m15;
            this.pos     = identity.GetPosition();
            this.rot     = identity.GetRotation();
        }
Exemplo n.º 27
0
    HmdMatrix44_t mul(HmdMatrix44_t a, HmdMatrix44_t b)
    {
        HmdMatrix44_t ret;

        ret.m0 = a.m0 * b.m0 + a.m1 * b.m4 + a.m2 * b.m8 + a.m3 * b.m12;
        ret.m1 = a.m0 * b.m1 + a.m1 * b.m5 + a.m2 * b.m9 + a.m3 * b.m13;
        ret.m2 = a.m0 * b.m2 + a.m1 * b.m6 + a.m2 * b.m10 + a.m3 * b.m14;
        ret.m3 = a.m0 * b.m3 + a.m1 * b.m7 + a.m2 * b.m11 + a.m3 * b.m15;
        ret.m4 = a.m4 * b.m0 + a.m5 * b.m4 + a.m6 * b.m8 + a.m7 * b.m12;
        ret.m5 = a.m4 * b.m1 + a.m5 * b.m5 + a.m6 * b.m9 + a.m7 * b.m13;
        ret.m6 = a.m4 * b.m2 + a.m5 * b.m6 + a.m6 * b.m10 + a.m7 * b.m14;
        ret.m7 = a.m4 * b.m3 + a.m5 * b.m7 + a.m6 * b.m11 + a.m7 * b.m15;

        ret.m8  = a.m8 * b.m0 + a.m9 * b.m4 + a.m10 * b.m8 + a.m11 * b.m12;
        ret.m9  = a.m8 * b.m1 + a.m9 * b.m5 + a.m10 * b.m9 + a.m11 * b.m13;
        ret.m10 = a.m8 * b.m2 + a.m9 * b.m6 + a.m10 * b.m10 + a.m11 * b.m14;
        ret.m11 = a.m8 * b.m3 + a.m9 * b.m7 + a.m10 * b.m11 + a.m11 * b.m15;
        ret.m12 = a.m12 * b.m0 + a.m13 * b.m4 + a.m14 * b.m8 + a.m15 * b.m12;
        ret.m13 = a.m12 * b.m1 + a.m13 * b.m5 + a.m14 * b.m9 + a.m15 * b.m13;
        ret.m14 = a.m12 * b.m2 + a.m13 * b.m6 + a.m14 * b.m10 + a.m15 * b.m14;
        ret.m15 = a.m12 * b.m3 + a.m13 * b.m7 + a.m14 * b.m11 + a.m15 * b.m15;

        return(ret);
    }
Exemplo n.º 28
0
 public abstract bool GetCameraProjection(uint nDeviceIndex,float flWidthPixels,float flHeightPixels,float flZNear,float flZFar,ref HmdMatrix44_t pProjection);
Exemplo n.º 29
0
 public static extern bool GetViewMatrix(System.IntPtr pHmd, float fSecondsFromNow, ref HmdMatrix44_t pMatLeftView, ref HmdMatrix44_t pMatRightView, ref HmdTrackingResult peResult);
Exemplo n.º 30
0
 /** For use in simple VR apps, this method returns the concatenation of the
  * tracking pose and the eye matrix to get a full view matrix for each eye.
  * This is ( GetHeadFromEyePose() ) * (GetTrackerFromHeadPose() ^ -1 )  */
 public bool GetViewMatrix(float fSecondsFromNow, ref HmdMatrix44_t pMatLeftView, ref HmdMatrix44_t pMatRightView, ref HmdTrackingResult peResult)
 {
     return(SteamVR.GetViewMatrix(m_pNativeObject, fSecondsFromNow, ref pMatLeftView, ref pMatRightView, ref peResult));
 }
Exemplo n.º 31
0
 public static extern bool GetViewMatrix(System.IntPtr pHmd, float fSecondsFromNow, ref HmdMatrix44_t pMatLeftView, ref HmdMatrix44_t pMatRightView, ref HmdTrackingResult peResult);
Exemplo n.º 32
0
        private void setupCameras()
        {
            foreach (string cameraName in cameraNamesToRender)
            {
                foreach (Camera camera in Camera.allCameras)
                {
                    if (cameraName.Equals(camera.name))
                    {
                        switch (camera.name)
                        {
                        case "GalaxyCamera":
                            O_Galaxy = camera;
                            break;

                        case "Camera ScaledSpace":
                            O_SclaledSpace = camera;
                            break;

                        case "Camera 01":
                            O_Far = camera;
                            break;

                        case "Camera 00":
                            O_Near = camera;
                            break;

                        default:
                            break;
                        }


                        camera.gameObject.AddOrGetComponent <posTracker>();

                        log("Camera:");
                        log("  Name:  " + camera.name);
                        log("  mask:  " + Convert.ToString(camera.cullingMask, 2));
                        log("  depth: " + camera.depth);
                        log("");

                        if (cameraName.Equals("InternalCamera"))
                        {
                            O_Interior = camera;
                        }
                        if (cameraName.Equals("GalaxyCamera"))
                        {
                            O_Galaxy = camera;
                        }

                        if (cameraName.Equals("Camera ScaledSpace"))
                        {
                            O_SclaledSpace = camera;
                            log("sky cam rot = " + camera.transform.rotation.eulerAngles.ToString());
                        }
                    }
                }
            }

            //Instantiate Cameras for all Layers
            camRight_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Interior  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            camRight_Near = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Near  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            camRight_Far = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            camLeft_Far  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            leftSky  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            rightSky = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            leftStars  = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);
            rightStars = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation);

            //copy Properties from Original Cameras
            leftSky.CopyFrom(O_SclaledSpace);
            rightSky.CopyFrom(O_SclaledSpace);
            leftStars.CopyFrom(O_Galaxy);
            rightStars.CopyFrom(O_Galaxy);
            camRight_Near.CopyFrom(O_Near);
            camLeft_Near.CopyFrom(O_Near);
            camLeft_Interior.CopyFrom(O_Interior);
            camRight_Interior.CopyFrom(O_Interior);
            camRight_Far.CopyFrom(O_Far);
            camLeft_Far.CopyFrom(O_Far);


            //set RenderTextures for Cameras
            setRenderTexturesTo(hmdLeftEyeRenderTexture, hmdRightEyeRenderTexture);

            //create left slave
            leftSlave      = camLeft_Interior.gameObject.AddOrGetComponent <RenderSlave>();
            leftSlave.left = true;

            //create right slave
            rightSlave      = camRight_Interior.gameObject.AddOrGetComponent <RenderSlave>();
            rightSlave.left = false;



            //Set Projectsions for all Cameras
            HmdMatrix44_t projLeft  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Near.nearClipPlane, camLeft_Near.farClipPlane);
            HmdMatrix44_t projRight = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Near.nearClipPlane, camRight_Near.farClipPlane);

            camLeft_Near.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft);
            camRight_Near.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight);

            HmdMatrix44_t projLeft2  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Interior.nearClipPlane, camLeft_Interior.farClipPlane);
            HmdMatrix44_t projRight2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Interior.nearClipPlane, camRight_Interior.farClipPlane);

            camLeft_Interior.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2);
            camRight_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight2);
            camLeft_Interior.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2));
            camLeft_Interior.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2));

            HmdMatrix44_t projLeft3  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Far.nearClipPlane, camLeft_Far.farClipPlane);
            HmdMatrix44_t projRight3 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Far.nearClipPlane, camRight_Far.farClipPlane);

            camLeft_Far.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft3);
            camRight_Far.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight3);

            HmdMatrix44_t projLeft4  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftSky.nearClipPlane, leftSky.farClipPlane);
            HmdMatrix44_t projRight4 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightSky.nearClipPlane, rightSky.farClipPlane);

            leftSky.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft4);
            rightSky.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight4);

            HmdMatrix44_t projLeft5  = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftStars.nearClipPlane, leftStars.farClipPlane);
            HmdMatrix44_t projRight5 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightStars.nearClipPlane, rightStars.farClipPlane);

            leftStars.projectionMatrix  = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft5);
            rightStars.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight5);


            //disable All Cameras to increase Performance
            O_SclaledSpace.enabled = false;
            O_Galaxy.enabled       = false;
            O_Near.enabled         = false;
            O_Far.enabled          = false;
            O_Interior.enabled     = false;

            camLeft_Near.enabled  = false;
            camRight_Near.enabled = false;

            camLeft_Far.enabled  = false;
            camRight_Far.enabled = false;

            leftSky.enabled  = false;
            rightSky.enabled = false;

            leftStars.enabled  = false;
            rightStars.enabled = false;

            camLeft_Interior.enabled  = false;
            camRight_Interior.enabled = false;



            //activate slaves
            posTracker.HmdOn = true;
            leftSlave.HmdOn  = true;
            rightSlave.HmdOn = true;

            //initialize active kerbal:
            activeKerbal = CameraManager.Instance.IVACameraActiveKerbal;
            lastKerbalID = CameraManager.Instance.IVACameraActiveKerbalIndex;
        }
Exemplo n.º 33
0
 /** For use in simple VR apps, this method returns the concatenation of the
 * tracking pose and the eye matrix to get a full view matrix for each eye.
 * This is ( GetHeadFromEyePose() ) * (GetTrackerFromHeadPose() ^ -1 )  */
 public bool GetViewMatrix(float fSecondsFromNow, ref HmdMatrix44_t pMatLeftView, ref HmdMatrix44_t pMatRightView, ref HmdTrackingResult peResult)
 {
     return SteamVR.GetViewMatrix(m_pNativeObject, fSecondsFromNow, ref pMatLeftView, ref pMatRightView, ref peResult);
 }
Exemplo n.º 34
0
 public override bool GetCameraProjection(uint nDeviceIndex,float flWidthPixels,float flHeightPixels,float flZNear,float flZFar,ref HmdMatrix44_t pProjection)
 {
     CheckIfUsable();
     bool result = VRNativeEntrypoints.VR_IVRTrackedCamera_GetCameraProjection(m_pVRTrackedCamera,nDeviceIndex,flWidthPixels,flHeightPixels,flZNear,flZFar,ref pProjection);
     return result;
 }