Пример #1
0
        public ConvexHull(Renderer renderer, Mesh polygonGeometry)
        {
            if (renderer == null)
                throw new ArgumentNullException("renderer", "Can't create a ConvexHull with a null renderer.");

            if (polygonGeometry == null)
                throw new ArgumentNullException("polygonGeometry", "Can't create a ConvexHull without a valid " +
                    "mesh.");

            this.renderer = renderer;
            this.polygonGeometry = polygonGeometry;

            effect = GlobalResourceCache.CreateEffectFromFile(renderer,
                "Effect Files\\Dynamic2DLightingEffect.fx");
        }
        /// <summary>
        /// Initializes the game. Loads all resources.
        /// </summary>
        protected override void InitializeGame()
        {
            Cursor.Hide();

            mouse = new MouseDevice(this);

            renderer.ProjectionMode = ProjectionMode.Orthogonal;
            renderer.ViewMatrix = Matrix.LookAtLH(new Vector3(0, 0, 5.0f), new Vector3(),
                new Vector3(0, 1, 0));

            effect = GlobalResourceCache.CreateEffectFromFile(renderer,
                "Effect Files\\Dynamic2DLightingEffect.fx");

            rectMesh = Mesh.Rectangle(renderer, Color.White, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height, 1.0f);

            material = GlobalResourceCache.CreateMaterialFromFile(renderer, "Materials\\roughWallMaterial.xml");

            light = new Light(renderer, 350, 1.0f, new Vector2(), Color.Red);

            sceneImage = new Texture(renderer, renderer.FullscreenSize.Width, renderer.FullscreenSize.Height,
                true);

            lightMesh = Mesh.Circle(renderer, Color.Yellow, Color.Yellow, 6, 16);

            bloomPostProcessor = new BloomPostProcessor(renderer);
            bloomPostProcessor.Blur = 3.5f;
            bloomPostProcessor.BloomScale = 1.5f;
            bloomPostProcessor.BrightPassThreshold = 0.4f;

            poly1 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.Blue, Color.Blue, 65, 8));
            poly1.Position = new Vector2(-150.0f, 150.0f);

            poly2 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.Red, Color.Purple, 50, 4));
            poly2.Position = new Vector2(200.0f, 0.0f);

            poly3 = new ConvexHull(renderer, Mesh.Circle(renderer, Color.SaddleBrown, Color.SeaGreen,
                60, 32));
            poly3.Position = new Vector2(-250.0f, -200.0f);

            this.KeyDown += new KeyEventHandler(OnKeyDown);
        }
Пример #3
0
        public ConvexHull(Renderer renderer, Mesh polygonGeometry, Vector2 position,
            float rotation, float size)
        {
            if (renderer == null)
                throw new ArgumentNullException("renderer", "Can't create a ConvexHull with a null renderer.");

            if (polygonGeometry == null)
                throw new ArgumentNullException("polygonGeometry", "Can't create a ConvexHull without a valid " +
                    "mesh.");

            this.renderer = renderer;
            this.polygonGeometry = polygonGeometry;
            this.position = position;
            this.rotation = rotation;
            this.size = size;

            effect = GlobalResourceCache.CreateEffectFromFile(renderer,
                "Effect Files\\Dynamic2DLightingEffect.fx");

            CalculateWorldMatrix();
        }
        /// <summary>
        /// Initializes the BloomPostProcessor.
        /// </summary>
        public BloomPostProcessor(Renderer renderer)
        {
            if (renderer == null)
                throw new ArgumentNullException("renderer", "Can't create the BloomPostProcessor with a "
                    + "null Renderer reference.");

            this.renderer = renderer;

            brightPassTex = new Texture(renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true);
            blurHorizontalTex = new Texture(renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true);
            blurVerticalTex = new Texture(renderer, renderer.FullscreenSize.Width / 2,
                renderer.FullscreenSize.Height / 2, true);
            finalBloomImage = new Texture(renderer, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height, true);

            fullscreenQuad = Mesh.Rectangle(renderer, Color.Black, renderer.FullscreenSize.Width,
                renderer.FullscreenSize.Height);

            bloomEffect = GlobalResourceCache.CreateEffectFromFile(renderer,
                "Effect Files\\Bloom.fx");
        }
Пример #5
0
        /// <summary>
        /// Builds a rectangular mesh, centered around the origin.
        /// </summary>
        public static Mesh Rectangle(Renderer renderer, Color color, float width, float height,
            float textureMapTiling)
        {
            Mesh rectMesh = new Mesh(renderer, 4, 2);

            rectMesh.AddVertex(0, new Vector3(-width / 2, height / 2, 1.0f), color,
                new Vector2(0.0f, 0.0f));
            rectMesh.AddVertex(1, new Vector3(width / 2, height / 2, 1.0f), color,
                new Vector2(textureMapTiling, 0.0f));
            rectMesh.AddVertex(2, new Vector3(width / 2, -height / 2, 1.0f), color,
                new Vector2(textureMapTiling, textureMapTiling));
            rectMesh.AddVertex(3, new Vector3(-width / 2, -height / 2, 1.0f), color,
                new Vector2(0.0f, textureMapTiling));

            rectMesh.AddTriangle(0, 0, 1, 2);
            rectMesh.AddTriangle(1, 0, 2, 3);

            return rectMesh;
        }
Пример #6
0
        /// <summary>
        /// Builds a circular mesh centered around the origin.
        /// </summary>
        public static Mesh Circle(Renderer renderer, Color centerColor, Color rimColor, float radius,
            int numSubdivisions)
        {
            Mesh circleMesh = new Mesh(renderer, numSubdivisions, numSubdivisions - 2);

            float angleStep = (2 * (float)Math.PI) / numSubdivisions;
            for (int i = 0; i < numSubdivisions; ++i)
            {
                circleMesh.AddVertex(i, new Vector3(radius * (float)Math.Cos(angleStep * i),
                    radius * (float)Math.Sin(angleStep * i), 1.0f), rimColor, new Vector2());
            }

            for (int i = 2, count = 0; i < numSubdivisions - 1; ++i, ++count)
            {
                circleMesh.AddTriangle(count, 0, i, i - 1);
            }

            circleMesh.AddTriangle(numSubdivisions - 3, 0, numSubdivisions - 2, numSubdivisions - 1);

            return circleMesh;
        }
Пример #7
0
        private void CreateAttenuationCircle()
        {
            if (attenuationCircle != null)
                attenuationCircle.Dispose();

            attenuationCircle = Mesh.Circle(renderer, Color.FromArgb((int)(intensity * 255), 0, 0, 0),
                Color.FromArgb(0, 0, 0, 0), range, 32);
        }