Пример #1
0
 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);
 }
Пример #2
0
 public void UpdateInputFromVrControllers()
 {
     VrCursorPosition = null;
     if (VrQuadMatrix.HasValue)
     {
         Matrix value            = VrQuadMatrix.Value;
         Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right);
         Plane  plane            = new Plane(value.Translation, value.Translation + value.Right, value.Translation + value.Up);
         Ray3   ray = new Ray3(controllerMatrix.Translation, controllerMatrix.Forward);
         float? num = ray.Intersection(plane);
         if (num.HasValue)
         {
             Vector3 v = ray.Position + num.Value * ray.Direction - value.Translation;
             float   x = Vector3.Dot(v, Vector3.Normalize(value.Right)) / value.Right.Length() * Widget.ActualSize.X;
             float   y = (1f - Vector3.Dot(v, Vector3.Normalize(value.Up)) / value.Up.Length()) * Widget.ActualSize.Y;
             VrCursorPosition = Vector2.Transform(new Vector2(x, y), Widget.GlobalTransform);
         }
     }
     if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadLeft))
     {
         Left = true;
     }
     if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadRight))
     {
         Right = true;
     }
     if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadUp))
     {
         Up = true;
     }
     if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.TouchpadDown))
     {
         Down = true;
     }
     if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadLeft))
     {
         Left = true;
     }
     if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadRight))
     {
         Right = true;
     }
     if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadUp))
     {
         Up = true;
     }
     if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadDown))
     {
         Down = true;
     }
     if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.Grip))
     {
         Back   = true;
         Cancel = true;
     }
     if (IsVrButtonDownOnce(VrController.Left, VrControllerButton.Touchpad) || IsVrButtonDownOnce(VrController.Left, VrControllerButton.Trigger) || IsVrButtonDownOnce(VrController.Right, VrControllerButton.Touchpad) || IsVrButtonDownOnce(VrController.Right, VrControllerButton.Trigger))
     {
         Any = true;
     }
     if (IsVrCursorVisible && VrCursorPosition.HasValue)
     {
         if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadUp))
         {
             Scroll = new Vector3(VrCursorPosition.Value, 1f);
         }
         if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.TouchpadDown))
         {
             Scroll = new Vector3(VrCursorPosition.Value, -1f);
         }
         if (IsVrButtonDown(VrController.Right, VrControllerButton.Trigger))
         {
             Press = VrCursorPosition.Value;
         }
         if (IsVrButtonDownOnce(VrController.Right, VrControllerButton.Trigger))
         {
             Ok            = true;
             Tap           = VrCursorPosition.Value;
             m_vrDownPoint = VrCursorPosition.Value;
             m_vrDragTime  = Time.FrameStartTime;
         }
         if (!IsVrButtonDown(VrController.Right, VrControllerButton.Trigger) && m_vrDownPoint.HasValue)
         {
             if (GetVrTriggerPosition(VrController.Left) > 0.5f)
             {
                 SpecialClick = new Segment2(m_vrDownPoint.Value, VrCursorPosition.Value);
             }
             else
             {
                 Click = new Segment2(m_vrDownPoint.Value, VrCursorPosition.Value);
             }
         }
     }
     if (!IsVrButtonDown(VrController.Right, VrControllerButton.Trigger))
     {
         m_vrDragInProgress = false;
         m_vrDownPoint      = null;
     }
     if (m_vrDragInProgress && VrCursorPosition.HasValue)
     {
         Drag = VrCursorPosition;
     }
     else if (IsVrButtonDown(VrController.Right, VrControllerButton.Trigger) && m_vrDownPoint.HasValue)
     {
         if (Vector2.Distance(m_vrDownPoint.Value, VrCursorPosition.Value) > SettingsManager.MinimumDragDistance * Widget.GlobalScale)
         {
             m_vrDragInProgress = true;
             Drag     = m_vrDownPoint.Value;
             DragMode = DragMode.AllItems;
         }
         else if (Time.FrameStartTime - m_vrDragTime > (double)SettingsManager.MinimumHoldDuration)
         {
             Hold     = m_vrDownPoint.Value;
             HoldTime = (float)(Time.FrameStartTime - m_vrDragTime);
         }
     }
 }
        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);
        }