Exemplo n.º 1
0
    public static Quaternion Slerp(Quaternion A, Quaternion B, float t)
    {
        float num = Mathf.Clamp(A.x * B.x + A.y * B.y + A.z * B.z + A.w * B.w, -1f, 1f);

        if (num < 0f)
        {
            B   = new Quaternion(-B.x, -B.y, -B.z, -B.w);
            num = -num;
        }
        float num4;
        float num5;

        if (1f - num > 0.0001f)
        {
            float num2 = Mathf.Acos(num);
            float num3 = Mathf.Sin(num2);
            num4 = Mathf.Sin((1f - t) * num2) / num3;
            num5 = Mathf.Sin(t * num2) / num3;
        }
        else
        {
            num4 = 1f - t;
            num5 = t;
        }
        return(new Quaternion(num4 * A.x + num5 * B.x, num4 * A.y + num5 * B.y, num4 * A.z + num5 * B.z, num4 * A.w + num5 * B.w));
    }
Exemplo n.º 2
0
    public static Vector3 GetScale(this Matrix4x4 m)
    {
        float x = Mathf.Sqrt(m.m00 * m.m00 + m.m01 * m.m01 + m.m02 * m.m02);
        float y = Mathf.Sqrt(m.m10 * m.m10 + m.m11 * m.m11 + m.m12 * m.m12);
        float z = Mathf.Sqrt(m.m20 * m.m20 + m.m21 * m.m21 + m.m22 * m.m22);

        return(new Vector3(x, y, z));
    }
Exemplo n.º 3
0
 private static float _copysign(float sizeval, float signval)
 {
     if (Mathf.Sign(signval) != 1f)
     {
         return(-Mathf.Abs(sizeval));
     }
     return(Mathf.Abs(sizeval));
 }
Exemplo n.º 4
0
    public static Quaternion GetRotation(this Matrix4x4 matrix)
    {
        Quaternion quaternion = default(Quaternion);

        quaternion.w = Mathf.Sqrt(Mathf.Max(0f, 1f + matrix.m00 + matrix.m11 + matrix.m22)) / 2f;
        quaternion.x = Mathf.Sqrt(Mathf.Max(0f, 1f + matrix.m00 - matrix.m11 - matrix.m22)) / 2f;
        quaternion.y = Mathf.Sqrt(Mathf.Max(0f, 1f - matrix.m00 + matrix.m11 - matrix.m22)) / 2f;
        quaternion.z = Mathf.Sqrt(Mathf.Max(0f, 1f - matrix.m00 - matrix.m11 + matrix.m22)) / 2f;
        quaternion.x = SteamVR_Utils._copysign(quaternion.x, matrix.m21 - matrix.m12);
        quaternion.y = SteamVR_Utils._copysign(quaternion.y, matrix.m02 - matrix.m20);
        quaternion.z = SteamVR_Utils._copysign(quaternion.z, matrix.m10 - matrix.m01);
        return(quaternion);
    }
Exemplo n.º 5
0
        private void UpdateBulletDisplayAmount(InventorySlotAmmo item, int clipLeft)
        {
            if (ItemEquippableEvents.IsCurrentItemShootableWeapon() &&
                ItemEquippableEvents.currentItem.ItemDataBlock.inventorySlot.Equals(item.Slot))
            {
                m_numberBulletsInMagDisplay.text = clipLeft + "\n----\n" + ((int)(item.BulletsMaxCap * item.RelInPack)).ToString();
                m_numberBulletsInMagDisplay.ForceMeshUpdate(false);

                m_bulletsInMagDisplay.MaxValue = Mathf.Max(item.BulletClipSize, 1);
                m_bulletsInMagDisplay.UpdateCurrentAmmo(clipLeft);
                m_bulletsInMagDisplay.UpdateAmmoGridDivisions();
            }
        }
Exemplo n.º 6
0
    public static void TakeStereoScreenshot(uint screenshotHandle, GameObject target, int cellSize, float ipd, ref string previewFilename, ref string VRFilename)
    {
        Texture2D texture2D = new Texture2D(4096, 4096, TextureFormat.ARGB32, false);
        Stopwatch stopwatch = new Stopwatch();
        Camera    camera    = null;

        stopwatch.Start();
        Camera camera2 = target.GetComponent <Camera>();

        if (camera2 == null)
        {
            if (camera == null)
            {
                camera = new GameObject().AddComponent <Camera>();
            }
            camera2 = camera;
        }
        Texture2D           texture2D2      = new Texture2D(2048, 2048, TextureFormat.ARGB32, false);
        RenderTexture       renderTexture   = new RenderTexture(2048, 2048, 24);
        RenderTexture       targetTexture   = camera2.targetTexture;
        bool                orthographic    = camera2.orthographic;
        float               fieldOfView     = camera2.fieldOfView;
        float               aspect          = camera2.aspect;
        StereoTargetEyeMask stereoTargetEye = camera2.stereoTargetEye;

        camera2.stereoTargetEye = StereoTargetEyeMask.None;
        camera2.fieldOfView     = 60f;
        camera2.orthographic    = false;
        camera2.targetTexture   = renderTexture;
        camera2.aspect          = 1f;
        camera2.Render();
        RenderTexture.active = renderTexture;
        texture2D2.ReadPixels(new Rect(0f, 0f, (float)renderTexture.width, (float)renderTexture.height), 0, 0);
        RenderTexture.active  = null;
        camera2.targetTexture = null;
        UnityEngine.Object.DestroyImmediate(renderTexture);
        SteamVR_SphericalProjection steamVR_SphericalProjection = camera2.gameObject.AddComponent <SteamVR_SphericalProjection>();
        Vector3       localPosition  = target.transform.localPosition;
        Quaternion    localRotation  = target.transform.localRotation;
        Vector3       position       = target.transform.position;
        Quaternion    lhs            = Quaternion.Euler(0f, target.transform.rotation.eulerAngles.y, 0f);
        Transform     transform      = camera2.transform;
        int           num            = 1024 / cellSize;
        float         num2           = 90f / (float)num;
        float         num3           = num2 / 2f;
        RenderTexture renderTexture2 = new RenderTexture(cellSize, cellSize, 24);

        renderTexture2.wrapMode     = TextureWrapMode.Clamp;
        renderTexture2.antiAliasing = 8;
        camera2.fieldOfView         = num2;
        camera2.orthographic        = false;
        camera2.targetTexture       = renderTexture2;
        camera2.aspect          = aspect;
        camera2.stereoTargetEye = StereoTargetEyeMask.None;
        for (int i = 0; i < num; i++)
        {
            float num4 = 90f - (float)i * num2 - num3;
            int   num5 = 4096 / renderTexture2.width;
            float num6 = 360f / (float)num5;
            float num7 = num6 / 2f;
            int   num8 = i * 1024 / num;
            for (int j = 0; j < 2; j++)
            {
                if (j == 1)
                {
                    num4 = -num4;
                    num8 = 2048 - num8 - cellSize;
                }
                for (int k = 0; k < num5; k++)
                {
                    float num9  = -180f + (float)k * num6 + num7;
                    int   destX = k * 4096 / num5;
                    int   num10 = 0;
                    float num11 = -ipd / 2f * Mathf.Cos(num4 * 0.017453292f);
                    for (int l = 0; l < 2; l++)
                    {
                        if (l == 1)
                        {
                            num10 = 2048;
                            num11 = -num11;
                        }
                        Vector3 b = lhs * Quaternion.Euler(0f, num9, 0f) * new Vector3(num11, 0f, 0f);
                        transform.position = position + b;
                        Quaternion quaternion = Quaternion.Euler(num4, num9, 0f);
                        transform.rotation = lhs * quaternion;
                        Vector3 vector     = quaternion * Vector3.forward;
                        float   num12      = num9 - num6 / 2f;
                        float   num13      = num12 + num6;
                        float   num14      = num4 + num2 / 2f;
                        float   num15      = num14 - num2;
                        float   y          = (num12 + num13) / 2f;
                        float   x          = (Mathf.Abs(num14) < Mathf.Abs(num15)) ? num14 : num15;
                        Vector3 vector2    = Quaternion.Euler(x, num12, 0f) * Vector3.forward;
                        Vector3 vector3    = Quaternion.Euler(x, num13, 0f) * Vector3.forward;
                        Vector3 vector4    = Quaternion.Euler(num14, y, 0f) * Vector3.forward;
                        Vector3 vector5    = Quaternion.Euler(num15, y, 0f) * Vector3.forward;
                        Vector3 vector6    = vector2 / Vector3.Dot(vector2, vector);
                        Vector3 a          = vector3 / Vector3.Dot(vector3, vector);
                        Vector3 vector7    = vector4 / Vector3.Dot(vector4, vector);
                        Vector3 a2         = vector5 / Vector3.Dot(vector5, vector);
                        Vector3 a3         = a - vector6;
                        Vector3 a4         = a2 - vector7;
                        float   magnitude  = a3.magnitude;
                        float   magnitude2 = a4.magnitude;
                        float   num16      = 1f / magnitude;
                        float   num17      = 1f / magnitude2;
                        Vector3 uAxis      = a3 * num16;
                        Vector3 vAxis      = a4 * num17;
                        steamVR_SphericalProjection.Set(vector, num12, num13, num14, num15, uAxis, vector6, num16, vAxis, vector7, num17);
                        camera2.aspect = magnitude / magnitude2;
                        camera2.Render();
                        RenderTexture.active = renderTexture2;
                        texture2D.ReadPixels(new Rect(0f, 0f, (float)renderTexture2.width, (float)renderTexture2.height), destX, num8 + num10);
                        RenderTexture.active = null;
                    }
                    float flProgress = ((float)i * ((float)num5 * 2f) + (float)k + (float)(j * num5)) / ((float)num * ((float)num5 * 2f));
                    OpenVR.Screenshots.UpdateScreenshotProgress(screenshotHandle, flProgress);
                }
            }
        }
        OpenVR.Screenshots.UpdateScreenshotProgress(screenshotHandle, 1f);
        previewFilename += ".png";
        VRFilename      += ".png";
        texture2D2.Apply();
        File.WriteAllBytes(previewFilename, ImageConversion.EncodeToPNG(texture2D));
        texture2D.Apply();
        File.WriteAllBytes(VRFilename, ImageConversion.EncodeToPNG(texture2D));
        if (camera2 != camera)
        {
            camera2.targetTexture          = targetTexture;
            camera2.orthographic           = orthographic;
            camera2.fieldOfView            = fieldOfView;
            camera2.aspect                 = aspect;
            camera2.stereoTargetEye        = stereoTargetEye;
            target.transform.localPosition = localPosition;
            target.transform.localRotation = localRotation;
        }
        else
        {
            camera.targetTexture = null;
        }
        UnityEngine.Object.DestroyImmediate(renderTexture2);
        UnityEngine.Object.DestroyImmediate(steamVR_SphericalProjection);
        stopwatch.Stop();
        UnityEngine.Debug.Log(string.Format("Screenshot took {0} seconds.", stopwatch.Elapsed));
        if (camera != null)
        {
            UnityEngine.Object.DestroyImmediate(camera.gameObject);
        }
        UnityEngine.Object.DestroyImmediate(texture2D2);
        UnityEngine.Object.DestroyImmediate(texture2D);
    }
Exemplo n.º 7
0
        private SteamVR()
        {
            BlackMagic.LoadBlackMagic();
            ClassInjector.RegisterTypeInIl2Cpp <MelonCoroutineCallbacks>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_ActivateActionSetOnLoad>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Boolean>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Single>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Skeleton>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Vector2>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Vector3>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Behaviour_Pose>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Camera>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_CameraFlip>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_CameraMask>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Ears>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_ExternalCamera>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Frustum>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Fade>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_GameView>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_IK>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Overlay>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_PlayArea>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_RenderModel>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Render>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Skeleton_Poser>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_SphericalProjection>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_Skybox>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_TrackingReferenceManager>();
            ClassInjector.RegisterTypeInIl2Cpp <SteamVR_TrackedObject>();
            UnityHooks.Init();


            this.hmd = OpenVR.System;
            UnityEngine.Debug.Log("<b>[SteamVR_Standalone]</b> Initialized. Connected to " + this.hmd_TrackingSystemName + ":" + this.hmd_SerialNumber);
            this.compositor = OpenVR.Compositor;
            this.overlay    = OpenVR.Overlay;
            uint num  = 0u;
            uint num2 = 0u;

            this.hmd.GetRecommendedRenderTargetSize(ref num, ref num2);
            this.sceneWidth  = num;
            this.sceneHeight = num2;
            float num3 = 0f;
            float num4 = 0f;
            float num5 = 0f;
            float num6 = 0f;

            this.hmd.GetProjectionRaw(EVREye.Eye_Left, ref num3, ref num4, ref num5, ref num6);
            float num7  = 0f;
            float num8  = 0f;
            float num9  = 0f;
            float num10 = 0f;

            this.hmd.GetProjectionRaw(EVREye.Eye_Right, ref num7, ref num8, ref num9, ref num10);
            this.tanHalfFov = new Vector2(Mathf.Max(new float[]
            {
                -num3,
                num4,
                -num7,
                num8
            }), Mathf.Max(new float[]
            {
                -num5,
                num6,
                -num9,
                num10
            }));
            this.textureBounds         = new VRTextureBounds_t[2];
            this.textureBounds[0].uMin = 0.5f + 0.5f * num3 / this.tanHalfFov.x;
            this.textureBounds[0].uMax = 0.5f + 0.5f * num4 / this.tanHalfFov.x;
            this.textureBounds[0].vMin = 0.5f - 0.5f * num6 / this.tanHalfFov.y;
            this.textureBounds[0].vMax = 0.5f - 0.5f * num5 / this.tanHalfFov.y;
            this.textureBounds[1].uMin = 0.5f + 0.5f * num7 / this.tanHalfFov.x;
            this.textureBounds[1].uMax = 0.5f + 0.5f * num8 / this.tanHalfFov.x;
            this.textureBounds[1].vMin = 0.5f - 0.5f * num10 / this.tanHalfFov.y;
            this.textureBounds[1].vMax = 0.5f - 0.5f * num9 / this.tanHalfFov.y;
            SteamVR.OpenVRMagic.SetSubmitParams(this.textureBounds[0], this.textureBounds[1], EVRSubmitFlags.Submit_Default);
            this.sceneWidth  /= Mathf.Max(this.textureBounds[0].uMax - this.textureBounds[0].uMin, this.textureBounds[1].uMax - this.textureBounds[1].uMin);
            this.sceneHeight /= Mathf.Max(this.textureBounds[0].vMax - this.textureBounds[0].vMin, this.textureBounds[1].vMax - this.textureBounds[1].vMin);
            this.aspect       = this.tanHalfFov.x / this.tanHalfFov.y;
            this.fieldOfView  = 2f * Mathf.Atan(this.tanHalfFov.y) * 57.29578f;
            this.eyes         = new SteamVR_Utils.RigidTransform[]
            {
                new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Left)),
                new SteamVR_Utils.RigidTransform(this.hmd.GetEyeToHeadTransform(EVREye.Eye_Right))
            };
            GraphicsDeviceType graphicsDeviceType = SystemInfo.graphicsDeviceType;

            if (graphicsDeviceType <= GraphicsDeviceType.OpenGLES3)
            {
                if (graphicsDeviceType != GraphicsDeviceType.OpenGLES2 && graphicsDeviceType != GraphicsDeviceType.OpenGLES3)
                {
                    goto IL_3F8;
                }
            }
            else if (graphicsDeviceType != GraphicsDeviceType.OpenGLCore)
            {
                if (graphicsDeviceType == GraphicsDeviceType.Vulkan)
                {
                    this.textureType = ETextureType.Vulkan;
                    goto IL_3FF;
                }
                goto IL_3F8;
            }
            this.textureType = ETextureType.OpenGL;
            goto IL_3FF;
IL_3F8:
            this.textureType = ETextureType.DirectX;
IL_3FF:

            SteamVR_Events.Initializing.Listen((this.OnInitializing));
            SteamVR_Events.Calibrating.Listen((this.OnCalibrating));
            SteamVR_Events.OutOfRange.Listen((this.OnOutOfRange));
            SteamVR_Events.DeviceConnected.Listen((this.OnDeviceConnected));
            SteamVR_Events.NewPoses.Listen((this.OnNewPoses));
        }