예제 #1
0
        public void Draw(Camera camera, int drawOrder)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;

            m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
            Matrix matrix = Matrix.CreateRotationY((float)MathUtils.Remainder(totalElapsedGameTime, 6.2831854820251465));
            float  num    = MathUtils.Min(m_subsystemSky.VisibilityRange, 30f);

            foreach (Pickable pickable in m_pickables)
            {
                Vector3 position = pickable.Position;
                float   num2     = Vector3.Dot(camera.ViewDirection, position - camera.ViewPosition);
                if (num2 > -0.5f && num2 < num)
                {
                    int   num3  = Terrain.ExtractContents(pickable.Value);
                    Block block = BlocksManager.Blocks[num3];
                    float num4  = (float)(totalElapsedGameTime - pickable.CreationTime);
                    if (!pickable.StuckMatrix.HasValue)
                    {
                        position.Y += 0.25f * MathUtils.Saturate(3f * num4);
                    }
                    int          x           = Terrain.ToCell(position.X);
                    int          num5        = Terrain.ToCell(position.Y);
                    int          z           = Terrain.ToCell(position.Z);
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                    if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1 && num5 >= 0 && num5 < 255)
                    {
                        m_drawBlockEnvironmentData.Humidity    = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                        m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                        float f    = MathUtils.Max(position.Y - (float)num5 - 0.75f, 0f) / 0.25f;
                        int   num6 = pickable.Light = (int)MathUtils.Lerp(m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z), m_subsystemTerrain.Terrain.GetCellLightFast(x, num5 + 1, z), f);
                    }
                    m_drawBlockEnvironmentData.Light = pickable.Light;
                    m_drawBlockEnvironmentData.BillboardDirection        = pickable.Position - camera.ViewPosition;
                    m_drawBlockEnvironmentData.InWorldMatrix.Translation = position;
                    if (pickable.StuckMatrix.HasValue)
                    {
                        Matrix matrix2 = pickable.StuckMatrix.Value;
                        block.DrawBlock(m_primitivesRenderer, pickable.Value, Color.White, 0.3f, ref matrix2, m_drawBlockEnvironmentData);
                    }
                    else
                    {
                        matrix.Translation = position + new Vector3(0f, 0.04f * MathUtils.Sin(3f * num4), 0f);
                        block.DrawBlock(m_primitivesRenderer, pickable.Value, Color.White, 0.3f, ref matrix, m_drawBlockEnvironmentData);
                    }
                }
            }
            m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
        }
        public void Draw(Camera camera, int drawOrder)
        {
            m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
            m_drawBlockEnvironmentData.InWorldMatrix    = Matrix.Identity;
            float num = MathUtils.Sqr(m_subsystemSky.VisibilityRange);

            foreach (Projectile projectile in m_projectiles)
            {
                Vector3 position = projectile.Position;
                if (!projectile.NoChunk && Vector3.DistanceSquared(camera.ViewPosition, position) < num && camera.ViewFrustum.Intersection(position))
                {
                    int          x           = Terrain.ToCell(position.X);
                    int          num2        = Terrain.ToCell(position.Y);
                    int          z           = Terrain.ToCell(position.Z);
                    int          num3        = Terrain.ExtractContents(projectile.Value);
                    Block        block       = BlocksManager.Blocks[num3];
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                    if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1 && num2 >= 0 && num2 < 255)
                    {
                        m_drawBlockEnvironmentData.Humidity    = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                        m_drawBlockEnvironmentData.Temperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num2);
                        projectile.Light = m_subsystemTerrain.Terrain.GetCellLightFast(x, num2, z);
                    }
                    m_drawBlockEnvironmentData.Light = projectile.Light;
                    m_drawBlockEnvironmentData.BillboardDirection        = (block.AlignToVelocity ? null : new Vector3?(camera.ViewDirection));
                    m_drawBlockEnvironmentData.InWorldMatrix.Translation = position;
                    Matrix matrix;
                    if (block.AlignToVelocity)
                    {
                        CalculateVelocityAlignMatrix(block, position, projectile.Velocity, out matrix);
                    }
                    else if (projectile.Rotation != Vector3.Zero)
                    {
                        matrix             = Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length());
                        matrix.Translation = projectile.Position;
                    }
                    else
                    {
                        matrix = Matrix.CreateTranslation(projectile.Position);
                    }
                    block.DrawBlock(m_primitivesRenderer, projectile.Value, Color.White, 0.3f, ref matrix, m_drawBlockEnvironmentData);
                }
            }
            m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
        }
예제 #3
0
 public override void DrawExtras(Camera camera)
 {
     if (m_componentCreature.ComponentHealth.Health > 0f && m_componentMiner != null && m_componentMiner.ActiveBlockValue != 0)
     {
         int    num   = Terrain.ExtractContents(m_componentMiner.ActiveBlockValue);
         Block  block = BlocksManager.Blocks[num];
         Matrix m     = base.AbsoluteBoneTransformsForCamera[m_hand2Bone.Index];
         m        *= camera.InvertedViewMatrix;
         m.Right   = Vector3.Normalize(m.Right);
         m.Up      = Vector3.Normalize(m.Up);
         m.Forward = Vector3.Normalize(m.Forward);
         Matrix matrix = Matrix.CreateRotationY(MathUtils.DegToRad(block.InHandRotation.Y) + m_inHandItemRotation.Y) * Matrix.CreateRotationZ(MathUtils.DegToRad(block.InHandRotation.Z) + m_inHandItemRotation.Z) * Matrix.CreateRotationX(MathUtils.DegToRad(block.InHandRotation.X) + m_inHandItemRotation.X) * Matrix.CreateTranslation(block.InHandOffset + m_inHandItemOffset) * Matrix.CreateTranslation(new Vector3(0.05f, 0.05f, -0.56f) * (m_componentCreature.ComponentBody.BoxSize.Y / 1.77f)) * m;
         int    x      = Terrain.ToCell(matrix.Translation.X);
         int    y      = Terrain.ToCell(matrix.Translation.Y);
         int    z      = Terrain.ToCell(matrix.Translation.Z);
         m_drawBlockEnvironmentData.InWorldMatrix      = matrix;
         m_drawBlockEnvironmentData.Humidity           = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
         m_drawBlockEnvironmentData.Temperature        = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
         m_drawBlockEnvironmentData.Light              = m_subsystemTerrain.Terrain.GetCellLight(x, y, z);
         m_drawBlockEnvironmentData.BillboardDirection = -Vector3.UnitZ;
         m_drawBlockEnvironmentData.SubsystemTerrain   = m_subsystemTerrain;
         Matrix matrix2 = matrix * camera.ViewMatrix;
         block.DrawBlock(m_subsystemModelsRenderer.PrimitivesRenderer, m_componentMiner.ActiveBlockValue, Color.White, block.InHandScale, ref matrix2, m_drawBlockEnvironmentData);
     }
     if (m_componentPlayer != null && camera.GameWidget.PlayerData != m_componentPlayer.PlayerData)
     {
         Vector3 position = Vector3.Transform(m_componentCreature.ComponentBody.Position + 1.02f * Vector3.UnitY * m_componentCreature.ComponentBody.BoxSize.Y, camera.ViewMatrix);
         if (position.Z < 0f)
         {
             Color color = Color.Lerp(Color.White, Color.Transparent, MathUtils.Saturate((position.Length() - 4f) / 3f));
             if (color.A > 8)
             {
                 Vector3    right = Vector3.TransformNormal(0.005f * Vector3.Normalize(Vector3.Cross(camera.ViewDirection, Vector3.UnitY)), camera.ViewMatrix);
                 Vector3    down  = Vector3.TransformNormal(-0.005f * Vector3.UnitY, camera.ViewMatrix);
                 BitmapFont font  = ContentManager.Get <BitmapFont>("Fonts/Pericles");
                 m_subsystemModelsRenderer.PrimitivesRenderer.FontBatch(font, 1, DepthStencilState.DepthRead, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.LinearClamp).QueueText(m_componentPlayer.PlayerData.Name, position, right, down, color, TextAnchor.HorizontalCenter | TextAnchor.Bottom);
             }
         }
     }
     base.DrawExtras(camera);
 }
예제 #4
0
        public override void Draw(DrawContext dc)
        {
            Block obj = BlocksManager.Blocks[Contents];

            if (DrawBlockEnvironmentData.SubsystemTerrain != null)
            {
                _ = DrawBlockEnvironmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture;
            }
            else
            {
                _ = BlocksTexturesManager.DefaultBlocksTexture;
            }
            Viewport viewport = Display.Viewport;
            float    num      = MathUtils.Min(base.ActualSize.X, base.ActualSize.Y) * Scale;
            Matrix   m        = Matrix.CreateOrthographic(3.6f, 3.6f, -10f - 1f * Depth, 10f - 1f * Depth);
            Matrix   m2       = MatrixUtils.CreateScaleTranslation(num, 0f - num, base.ActualSize.X / 2f, base.ActualSize.Y / 2f) * base.GlobalTransform * MatrixUtils.CreateScaleTranslation(2f / (float)viewport.Width, -2f / (float)viewport.Height, -1f, 1f);

            DrawBlockEnvironmentData.ViewProjectionMatrix = (CustomViewMatrix.HasValue ? CustomViewMatrix.Value : m_viewMatrix) * m * m2;
            float  iconViewScale = BlocksManager.Blocks[Contents].GetIconViewScale(Value, DrawBlockEnvironmentData);
            Matrix matrix        = CustomViewMatrix.HasValue ? Matrix.Identity : Matrix.CreateTranslation(BlocksManager.Blocks[Contents].GetIconBlockOffset(Value, DrawBlockEnvironmentData));

            obj.DrawBlock(dc.PrimitivesRenderer3D, Value, base.GlobalColorTransform, iconViewScale, ref matrix, DrawBlockEnvironmentData);
        }
        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);
        }
예제 #6
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;
         }
     }
 }