コード例 #1
0
        public void DrawLightning(Camera camera)
        {
            if (!m_lightningStrikePosition.HasValue)
            {
                return;
            }
            FlatBatch3D flatBatch3D = m_primitivesRenderer3d.FlatBatch(0, DepthStencilState.DepthRead, null, BlendState.Additive);
            Vector3     value       = m_lightningStrikePosition.Value;
            Vector3     unitY       = Vector3.UnitY;
            Vector3     v           = Vector3.Normalize(Vector3.Cross(camera.ViewDirection, unitY));
            Viewport    viewport    = Display.Viewport;
            float       num         = Vector4.Transform(new Vector4(value, 1f), camera.ViewProjectionMatrix).W * 2f / ((float)viewport.Width * camera.ProjectionMatrix.M11);

            for (int i = 0; i < (int)(m_lightningStrikeBrightness * 30f); i++)
            {
                float   s    = m_random.NormalFloat(0f, 1f * num);
                float   s2   = m_random.NormalFloat(0f, 1f * num);
                Vector3 v2   = s * v + s2 * unitY;
                float   num2 = 260f;
                while (num2 > value.Y)
                {
                    uint    num3    = MathUtils.Hash((uint)(m_lightningStrikePosition.Value.X + 100f * m_lightningStrikePosition.Value.Z + 200f * num2));
                    float   num4    = MathUtils.Lerp(4f, 10f, (float)(double)(num3 & 0xFF) / 255f);
                    float   s3      = ((num3 & 1) == 0) ? 1 : (-1);
                    float   s4      = MathUtils.Lerp(0.05f, 0.2f, (float)(double)((num3 >> 8) & 0xFF) / 255f);
                    float   num5    = num2;
                    float   num6    = num5 - num4 * MathUtils.Lerp(0.45f, 0.55f, (float)(double)((num3 >> 16) & 0xFF) / 255f);
                    float   num7    = num5 - num4 * MathUtils.Lerp(0.45f, 0.55f, (float)(double)((num3 >> 24) & 0xFF) / 255f);
                    float   num8    = num5 - num4;
                    Vector3 p       = new Vector3(value.X, num5, value.Z) + v2;
                    Vector3 vector  = new Vector3(value.X, num6, value.Z) + v2 - num4 * v * s3 * s4;
                    Vector3 vector2 = new Vector3(value.X, num7, value.Z) + v2 + num4 * v * s3 * s4;
                    Vector3 p2      = new Vector3(value.X, num8, value.Z) + v2;
                    Color   color   = Color.White * 0.2f * MathUtils.Saturate((260f - num5) * 0.2f);
                    Color   color2  = Color.White * 0.2f * MathUtils.Saturate((260f - num6) * 0.2f);
                    Color   color3  = Color.White * 0.2f * MathUtils.Saturate((260f - num7) * 0.2f);
                    Color   color4  = Color.White * 0.2f * MathUtils.Saturate((260f - num8) * 0.2f);
                    flatBatch3D.QueueLine(p, vector, color, color2);
                    flatBatch3D.QueueLine(vector, vector2, color2, color3);
                    flatBatch3D.QueueLine(vector2, p2, color3, color4);
                    num2 -= num4;
                }
            }
            float num9 = MathUtils.Lerp(0.3f, 0.75f, 0.5f * (float)MathUtils.Sin(MathUtils.Remainder(1.0 * m_subsystemTime.GameTime, 6.2831854820251465)) + 0.5f);

            m_lightningStrikeBrightness -= m_subsystemTime.GameTimeDelta / num9;
            if (m_lightningStrikeBrightness <= 0f)
            {
                m_lightningStrikePosition   = null;
                m_lightningStrikeBrightness = 0f;
            }
        }
コード例 #2
0
        public void FillStarsBuffers()
        {
            Random random = new Random(7);

            StarVertex[] array = new StarVertex[600];
            for (int i = 0; i < 150; i++)
            {
                Vector3 v;
                do
                {
                    v = new Vector3(random.Float(-1f, 1f), random.Float(-1f, 1f), random.Float(-1f, 1f));
                }while (v.LengthSquared() > 1f);
                v = Vector3.Normalize(v);
                float      s          = 9f * random.NormalFloat(1f, 0.1f);
                float      w          = MathUtils.Saturate(random.NormalFloat(0.6f, 0.4f));
                Color      color      = new Color(new Vector4(random.Float(0.6f, 1f), 0.7f, random.Float(0.8f, 1f), w));
                Vector3    v2         = 900f * v;
                Vector3    vector     = Vector3.Normalize(Vector3.Cross((v.X > v.Y) ? Vector3.UnitY : Vector3.UnitX, v));
                Vector3    v3         = Vector3.Normalize(Vector3.Cross(vector, v));
                Vector3    position   = v2 + s * (-vector - v3);
                Vector3    position2  = v2 + s * (vector - v3);
                Vector3    position3  = v2 + s * (vector + v3);
                Vector3    position4  = v2 + s * (-vector + v3);
                StarVertex starVertex = array[i * 4] = new StarVertex
                {
                    Position          = position,
                    TextureCoordinate = new Vector2(0f, 0f),
                    Color             = color
                };
                starVertex = (array[i * 4 + 1] = new StarVertex
                {
                    Position = position2,
                    TextureCoordinate = new Vector2(1f, 0f),
                    Color = color
                });
                starVertex = (array[i * 4 + 2] = new StarVertex
                {
                    Position = position3,
                    TextureCoordinate = new Vector2(1f, 1f),
                    Color = color
                });
                starVertex = (array[i * 4 + 3] = new StarVertex
                {
                    Position = position4,
                    TextureCoordinate = new Vector2(0f, 1f),
                    Color = color
                });
            }
            m_starsVertexBuffer.SetData(array, 0, array.Length);
            ushort[] array2 = new ushort[900];
            for (int j = 0; j < 150; j++)
            {
                array2[j * 6]     = (ushort)(j * 4);
                array2[j * 6 + 1] = (ushort)(j * 4 + 1);
                array2[j * 6 + 2] = (ushort)(j * 4 + 2);
                array2[j * 6 + 3] = (ushort)(j * 4 + 2);
                array2[j * 6 + 4] = (ushort)(j * 4 + 3);
                array2[j * 6 + 5] = (ushort)(j * 4);
            }
            m_starsIndexBuffer.SetData(array2, 0, array2.Length);
        }