public Ray3?CalculateVrHandRay()
 {
     if (VrManager.IsControllerPresent(VrController.Right))
     {
         Camera activeCamera = m_componentPlayer.GameWidget.ActiveCamera;
         Matrix m            = VrManager.HmdMatrixInverted * Matrix.CreateWorld(activeCamera.ViewPosition, activeCamera.ViewDirection, activeCamera.ViewUp);
         Matrix matrix       = VrManager.GetControllerMatrix(VrController.Right) * m;
         return(new Ray3(matrix.Translation + matrix.Forward * (5f / 64f), matrix.Forward));
     }
     return(null);
 }
 public void UpdateInputFromVrControllers(WidgetInput input)
 {
     if (!IsControlledByVr)
     {
         return;
     }
     IsControlledByTouch = false;
     if (m_componentGui.ModalPanelWidget != null || DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
     {
         if (!input.IsVrCursorVisible)
         {
             input.IsVrCursorVisible = true;
         }
     }
     else
     {
         input.IsVrCursorVisible = false;
         float   num              = MathUtils.Pow(1.25f, 10f * (SettingsManager.MoveSensitivity - 0.5f));
         float   num2             = MathUtils.Pow(1.25f, 10f * (SettingsManager.LookSensitivity - 0.5f));
         float   num3             = MathUtils.Clamp(m_subsystemTime.GameTimeDelta, 0f, 0.1f);
         Vector2 v                = Vector2.Normalize(m_componentPlayer.ComponentBody.Matrix.Right.XZ);
         Vector2 v2               = Vector2.Normalize(m_componentPlayer.ComponentBody.Matrix.Forward.XZ);
         Vector2 vrStickPosition  = input.GetVrStickPosition(VrController.Left, 0.2f);
         Vector2 vrStickPosition2 = input.GetVrStickPosition(VrController.Right, 0.2f);
         Matrix  m                = VrManager.HmdMatrixInverted.OrientationMatrix * m_componentPlayer.ComponentCreatureModel.EyeRotation.ToMatrix();
         Vector2 xZ               = Vector3.TransformNormal(new Vector3(VrManager.WalkingVelocity.X, 0f, VrManager.WalkingVelocity.Y), m).XZ;
         Vector3 value            = Vector3.TransformNormal(new Vector3(VrManager.HeadMove.X, 0f, VrManager.HeadMove.Y), m);
         Vector3 zero             = Vector3.Zero;
         zero += 0.5f * new Vector3(Vector2.Dot(xZ, v), 0f, Vector2.Dot(xZ, v2));
         zero += new Vector3(2f * vrStickPosition.X, 2f * vrStickPosition2.Y, 2f * vrStickPosition.Y);
         m_playerInput.Move      += zero;
         m_playerInput.SneakMove += zero;
         m_playerInput.VrMove     = value;
         TouchInput?touchInput = VrManager.GetTouchInput(VrController.Left);
         if (touchInput.HasValue && num3 > 0f)
         {
             if (touchInput.Value.InputType == TouchInputType.Move)
             {
                 Vector2 move   = touchInput.Value.Move;
                 Vector2 vector = 10f * num / num3 * new Vector2(0.5f) * move * MathUtils.Pow(move.LengthSquared(), 0.175f);
                 m_playerInput.SneakMove.X += vector.X;
                 m_playerInput.SneakMove.Z += vector.Y;
                 m_playerInput.Move.X      += ProcessInputValue(touchInput.Value.TotalMoveLimited.X, 0.1f, 1f);
                 m_playerInput.Move.Z      += ProcessInputValue(touchInput.Value.TotalMoveLimited.Y, 0.1f, 1f);
             }
             else if (touchInput.Value.InputType == TouchInputType.Tap)
             {
                 m_playerInput.Jump = true;
             }
         }
         m_playerInput.Look += 0.5f * vrStickPosition2 * MathUtils.Pow(vrStickPosition2.LengthSquared(), 0.25f);
         Vector3 hmdMatrixYpr     = VrManager.HmdMatrixYpr;
         Vector3 hmdLastMatrixYpr = VrManager.HmdLastMatrixYpr;
         Vector3 vector2          = hmdMatrixYpr - hmdLastMatrixYpr;
         m_playerInput.VrLook = new Vector2(vector2.X, hmdMatrixYpr.Y);
         TouchInput?touchInput2 = VrManager.GetTouchInput(VrController.Right);
         Vector2    zero2       = Vector2.Zero;
         if (touchInput2.HasValue)
         {
             if (touchInput2.Value.InputType == TouchInputType.Move)
             {
                 zero2.X = touchInput2.Value.Move.X;
                 m_playerInput.Move.Y += ProcessInputValue(touchInput2.Value.TotalMoveLimited.Y, 0.1f, 1f);
             }
             else if (touchInput2.Value.InputType == TouchInputType.Tap)
             {
                 m_playerInput.Jump = true;
             }
         }
         if (num3 > 0f)
         {
             m_vrSmoothLook      = Vector2.Lerp(m_vrSmoothLook, zero2, 14f * num3);
             m_playerInput.Look += num2 / num3 * new Vector2(0.25f) * m_vrSmoothLook * MathUtils.Pow(m_vrSmoothLook.LengthSquared(), 0.3f);
         }
         if (VrManager.IsControllerPresent(VrController.Right))
         {
             m_playerInput.Dig      = (VrManager.IsButtonDown(VrController.Right, VrControllerButton.Trigger) ? CalculateVrHandRay() : m_playerInput.Dig);
             m_playerInput.Hit      = (VrManager.IsButtonDownOnce(VrController.Right, VrControllerButton.Trigger) ? CalculateVrHandRay() : m_playerInput.Hit);
             m_playerInput.Aim      = (VrManager.IsButtonDown(VrController.Left, VrControllerButton.Trigger) ? CalculateVrHandRay() : m_playerInput.Aim);
             m_playerInput.Interact = (VrManager.IsButtonDownOnce(VrController.Left, VrControllerButton.Trigger) ? CalculateVrHandRay() : m_playerInput.Interact);
         }
         m_playerInput.ToggleMount       |= input.IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadUp);
         m_playerInput.ToggleSneak       |= input.IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadDown);
         m_playerInput.EditItem          |= input.IsVrButtonDownOnce(VrController.Left, VrControllerButton.Grip);
         m_playerInput.ToggleCreativeFly |= input.IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadUp);
         if (input.IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadLeft))
         {
             m_playerInput.ScrollInventory--;
         }
         if (input.IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadRight))
         {
             m_playerInput.ScrollInventory++;
         }
         m_playerInput.Drop |= input.IsVrButtonDownOnce(VrController.Right, VrControllerButton.Grip);
     }
     if (!DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
     {
         m_playerInput.ToggleInventory |= input.IsVrButtonDownOnce(VrController.Right, VrControllerButton.Menu);
     }
 }
        public void Draw(Camera camera, int drawOrder)
        {
            if (!(m_componentPlayer.ComponentHealth.Health > 0f) || !camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) || !m_componentPlayer.ComponentInput.IsControlledByVr)
            {
                return;
            }
            Vector3 eyePosition      = m_componentPlayer.ComponentCreatureModel.EyePosition;
            int     x                = Terrain.ToCell(eyePosition.X);
            int     num              = Terrain.ToCell(eyePosition.Y);
            int     z                = Terrain.ToCell(eyePosition.Z);
            int     activeBlockValue = m_componentMiner.ActiveBlockValue;

            if (Time.FrameStartTime >= m_nextHandLightTime)
            {
                float?num2 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                if (num2.HasValue)
                {
                    m_nextHandLightTime = Time.FrameStartTime + 0.1;
                    m_handLight         = num2.Value;
                }
            }
            Matrix identity = Matrix.Identity;

            if (m_pokeAnimationTime > 0f)
            {
                float num3 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                if (activeBlockValue != 0)
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num3);
                }
                else
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num3);
                }
            }
            if (!VrManager.IsControllerPresent(VrController.Right))
            {
                return;
            }
            Matrix m = VrManager.HmdMatrixInverted * Matrix.CreateWorld(camera.ViewPosition, camera.ViewDirection, camera.ViewUp) * camera.ViewMatrix;
            Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right);

            if (activeBlockValue == 0)
            {
                Display.DepthStencilState      = DepthStencilState.Default;
                Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                m_shader.SamplerState          = SamplerState.PointClamp;
                m_shader.MaterialColor         = Vector4.One;
                m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                m_shader.LightDirection1       = -Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                m_shader.LightDirection2       = -Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                m_shader.Transforms.View       = Matrix.Identity;
                m_shader.Transforms.Projection = camera.ProjectionMatrix;
                m_shader.Transforms.World[0]   = Matrix.CreateScale(0.01f) * identity * controllerMatrix * m;
                foreach (ModelMesh mesh in m_vrHandModel.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                    }
                }
            }
            else
            {
                if (num >= 0 && num <= 255)
                {
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                    if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                    {
                        m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num, z);
                    }
                }
                int     num4   = Terrain.ExtractContents(activeBlockValue);
                Block   block  = BlocksManager.Blocks[num4];
                Vector3 vector = block.InHandRotation * ((float)Math.PI / 180f) + m_itemRotation;
                Matrix  matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * Matrix.CreateTranslation(block.InHandOffset) * identity * Matrix.CreateTranslation(m_itemOffset) * controllerMatrix * m;
                m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                m_drawBlockEnvironmentData.Light            = m_itemLight;
                m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetHumidity(x, z);
                m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num);
                block.DrawBlock(m_primitivesRenderer, activeBlockValue, Color.White, block.InHandScale, ref matrix, m_drawBlockEnvironmentData);
            }
            m_primitivesRenderer.Flush(camera.ProjectionMatrix);
        }