예제 #1
0
        public float?CalculateModelLight(ModelData modelData)
        {
            Vector3 p;

            if (modelData.ComponentBody != null)
            {
                p    = modelData.ComponentBody.Position;
                p.Y += 0.95f * (modelData.ComponentBody.BoundingBox.Max.Y - modelData.ComponentBody.BoundingBox.Min.Y);
            }
            else
            {
                Matrix?boneTransform = modelData.ComponentModel.GetBoneTransform(modelData.ComponentModel.Model.RootBone.Index);
                p = ((!boneTransform.HasValue) ? Vector3.Zero : (boneTransform.Value.Translation + new Vector3(0f, 0.9f, 0f)));
            }
            return(LightingManager.CalculateSmoothLight(m_subsystemTerrain, p));
        }
        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);
        }
예제 #3
0
        public void DrawIceOverlay(Camera camera, float factor)
        {
            Vector2 viewportSize = camera.ViewportSize;
            float   s            = camera.Eye.HasValue ? 1.3f : 1f;
            float   num          = camera.Eye.HasValue ? MathUtils.Pow(factor, 0.4f) : factor;
            Vector2 v            = camera.Eye.HasValue ? viewportSize : new Vector2(1f);
            float   num2         = v.Length();
            Point2  point        = new Point2((int)MathUtils.Round(12f * viewportSize.X / viewportSize.Y), (int)MathUtils.Round(12f));

            if (m_iceVertices == null || m_cellsCount != point)
            {
                m_cellsCount = point;
                m_random.Seed(0);
                m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)];
                for (int i = 0; i <= point.X; i++)
                {
                    for (int j = 0; j <= point.Y; j++)
                    {
                        float num3 = i;
                        float num4 = j;
                        if (i != 0 && i != point.X)
                        {
                            num3 += m_random.Float(-0.4f, 0.4f);
                        }
                        if (j != 0 && j != point.Y)
                        {
                            num4 += m_random.Float(-0.4f, 0.4f);
                        }
                        float x = num3 / (float)point.X;
                        float y = num4 / (float)point.Y;
                        m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y);
                    }
                }
            }
            Vector3 vector  = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s;
            Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s;
            Vector3 v2      = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2);

            if (!m_light.HasValue || Time.PeriodicEvent(0.05000000074505806, 0.0))
            {
                m_light = (LightingManager.CalculateSmoothLight(m_subsystemTerrain, camera.ViewPosition) ?? m_light ?? 1f);
            }
            Color color = Color.MultiplyColorOnly(Color.White, m_light.Value);

            m_random.Seed(0);
            Texture2D       texture         = ContentManager.Get <Texture2D>("Textures/IceOverlay");
            TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.PointWrap);
            Vector2         v3      = new Vector2(viewportSize.X / viewportSize.Y, 1f);
            Vector2         vector3 = new Vector2(point.X - 1, point.Y - 1);

            for (int k = 0; k < point.X; k++)
            {
                for (int l = 0; l < point.Y; l++)
                {
                    float num5 = (new Vector2((float)(2 * k) / vector3.X - 1f, (float)(2 * l) / vector3.Y - 1f) * v).Length() / num2;
                    if (1f - num5 + m_random.Float(0f, 0.05f) < num)
                    {
                        Vector2 v4        = m_iceVertices[k + l * (point.X + 1)];
                        Vector2 v5        = m_iceVertices[k + 1 + l * (point.X + 1)];
                        Vector2 v6        = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)];
                        Vector2 v7        = m_iceVertices[k + (l + 1) * (point.X + 1)];
                        Vector3 vector4   = v2 + v4.X * vector + v4.Y * vector2;
                        Vector3 p         = v2 + v5.X * vector + v5.Y * vector2;
                        Vector3 vector5   = v2 + v6.X * vector + v6.Y * vector2;
                        Vector3 p2        = v2 + v7.X * vector + v7.Y * vector2;
                        Vector2 vector6   = v4 * v3;
                        Vector2 texCoord  = v5 * v3;
                        Vector2 vector7   = v6 * v3;
                        Vector2 texCoord2 = v7 * v3;
                        texturedBatch3D.QueueTriangle(vector4, p, vector5, vector6, texCoord, vector7, color);
                        texturedBatch3D.QueueTriangle(vector5, p2, vector4, vector7, texCoord2, vector6, color);
                    }
                }
            }
            texturedBatch3D.Flush(camera.ProjectionMatrix);
        }
예제 #4
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr)
     {
         Viewport viewport  = Display.Viewport;
         Viewport viewport2 = viewport;
         viewport2.MaxDepth *= 0.1f;
         Display.Viewport    = viewport2;
         try
         {
             Matrix identity = Matrix.Identity;
             if (m_swapAnimationTime > 0f)
             {
                 float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f);
                 identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num);
             }
             if (m_pokeAnimationTime > 0f)
             {
                 float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                 if (m_value != 0)
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2);
                 }
                 else
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2);
                 }
             }
             if (m_componentRider.Mount != null)
             {
                 ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>();
                 if (componentCreatureModel != null)
                 {
                     float   num3     = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f;
                     Vector3 position = default(Vector3);
                     position.Y = 0.02f * MathUtils.Sin(num3);
                     position.Z = 0.02f * MathUtils.Sin(num3);
                     identity  *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position);
                 }
             }
             else
             {
                 float   num4      = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f;
                 Vector3 position2 = default(Vector3);
                 position2.X = 0.03f * MathUtils.Sin(num4 * 1f);
                 position2.Y = 0.02f * MathUtils.Sin(num4 * 2f);
                 position2.Z = 0.02f * MathUtils.Sin(num4 * 1f);
                 identity   *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2);
             }
             Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
             int     x           = Terrain.ToCell(eyePosition.X);
             int     num5        = Terrain.ToCell(eyePosition.Y);
             int     z           = Terrain.ToCell(eyePosition.Z);
             Matrix  m           = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
             m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition;
             if (m_value != 0)
             {
                 if (num5 >= 0 && num5 <= 255)
                 {
                     TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                     if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                     {
                         m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z);
                     }
                 }
                 int     num6      = Terrain.ExtractContents(m_value);
                 Block   block     = BlocksManager.Blocks[num6];
                 Vector3 vector    = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation;
                 Vector3 position3 = block.FirstPersonOffset + m_itemOffset;
                 position3 += m_itemOffset;
                 Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m;
                 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                 m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                 m_drawBlockEnvironmentData.Light            = m_itemLight;
                 m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                 m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                 block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData);
                 m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
             }
             else
             {
                 if (Time.FrameStartTime >= m_nextHandLightTime)
                 {
                     float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                     if (num7.HasValue)
                     {
                         m_nextHandLightTime = Time.FrameStartTime + 0.1;
                         m_handLight         = num7.Value;
                     }
                 }
                 Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f);
                 Matrix  matrix2   = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix;
                 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.World[0]   = matrix2;
                 m_shader.Transforms.View       = Matrix.Identity;
                 m_shader.Transforms.Projection = camera.ProjectionMatrix;
                 foreach (ModelMesh mesh in m_handModel.Meshes)
                 {
                     foreach (ModelMeshPart meshPart in mesh.MeshParts)
                     {
                         Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                     }
                 }
             }
         }
         finally
         {
             Display.Viewport = viewport;
         }
     }
 }