Пример #1
0
        public override void Initialize()
        {
            base.Initialize();

            // Camera
            var camera = new CameraPrefab("camera");

            camera.AddComponent <OrbitController>();
            camera.AddComponent <DemoBehaviour>();
            Add(camera);

            // Light
            var lightPrefab = new LightPrefab("lightPrefab", LightType.Directional);

            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            Add(lightPrefab);

            var sceneObject = new SceneObject("HexaGrid");

            sceneObject.AddComponent <HexaGridBuilder>();
            Add(sceneObject);

            // Skybox
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.StarsSkybox);

            Screen.ShowCursor = true;
        }
Пример #2
0
        public override void Initialize()
        {
            base.Initialize();

            // Skybox
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.BlueSkybox);

            // Camera
            var camera = new CameraPrefab("camera");

            camera.AddComponent <ControllerSwitcher>();
            camera.AddComponent <DemoBehaviour>();
            Add(camera);

            // Light
            var lightPrefab = new LightPrefab("light", LightType.Directional);

            lightPrefab.Transform.Translate(0, 10, 0);
            lightPrefab.Light.Range        = 25;
            lightPrefab.Light.Intensity    = 1.0f;
            lightPrefab.Light.FallOf       = 5f;
            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            lightPrefab.Light.Angle        = MathHelper.PiOver4;
            lightPrefab.Light.ShadowGenerator.ShadowStrength = 0.6f;
            lightPrefab.Light.ShadowGenerator.SetShadowMapSize(Application.GraphicsDevice, 1024);
            lightPrefab.EnableShadows = true;
            Add(lightPrefab);

            // Finally a terrain
            var terrainMat = new TerrainMaterial(scene);

            var terrain = new TerrainPrefab("terrain");

            terrain.Randomize(4, 12);
            terrain.Renderer.Material = terrainMat;
            terrain.Transform.Translate(-terrain.Width >> 1, 0, -terrain.Depth / 2);
            Add(terrain);

            terrain.SetWeightData(0.5f, 4, 15, 30);

            terrainMat.Texture       = Application.Content.Load <Texture2D>("Textures/Terrain/Grass");
            terrainMat.SandTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Sand");
            terrainMat.SnowTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Snow");
            terrainMat.RockTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Rock");
            terrainMat.WeightTexture = terrain.GenerateWeightMap();
            terrainMat.Tiling        = new Vector2(4);

            // Water !
            var water = new WaterPrefab("water");

            Add(water);
            water.Generate("Textures/water", "Textures/wavesbump", new Vector3(terrain.Width * 0.5f));

            var waterMat = water.Renderer.Material as WaterMaterial;

            waterMat.ReflectiveMap     = scene.RenderSettings.Skybox.Texture;
            waterMat.WaterTransparency = 0.6f;
        }
Пример #3
0
        public override void Initialize()
        {
            base.Initialize();

            // Add a camera with a FPS controller
            var camera = new CameraPrefab("camera");

            camera.Setup(new Vector3(0, 2, -10), new Vector3(0, 0, 0), Vector3.Up);
            camera.AddComponent <ControllerSwitcher>();
            Add(camera);

            // And a light
            var lightPrefab = new LightPrefab("light", LightType.Directional);

            Add(lightPrefab);
            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            lightPrefab.Light.Color        = Color.LightSkyBlue;
            lightPrefab.Light.Intensity    = 1.0f;
            lightPrefab.AddComponent <DemoBehaviour>();
            lightPrefab.EnableShadows = true;

            // Finally a terrain
            var terrainMat = new TerrainMaterial(scene);

            var terrain = new TerrainPrefab("terrain");

            scene.Add(terrain);
            terrain.LoadHeightmap("Textures/heightmap");
            terrain.Renderer.Material = terrainMat;
            terrain.Transform.Translate(-terrain.Width >> 1, -10, -terrain.Depth >> 1);
            terrain.AddComponent <WeightMapViewer>();
            var map = terrain.GenerateWeightMap();

            terrainMat.Texture       = Application.Content.Load <Texture2D>("Textures/Terrain/Grass");
            terrainMat.SandTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Sand");
            terrainMat.SnowTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Snow");
            terrainMat.RockTexture   = Application.Content.Load <Texture2D>("Textures/Terrain/Rock");
            terrainMat.WeightTexture = map;
            terrainMat.Tiling        = new Vector2(4);

            // With water !
            var water = new WaterPrefab("water");

            scene.Add(water);
            water.Generate("Textures/water", "Textures/wavesbump", new Vector3(terrain.Width * 0.5f));

            Screen.ShowCursor = true;

            // Don't miss the Skybox ;)
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.BlueSkybox);

            // And fog
            RenderSettings.FogDensity = 0.0085f;
            RenderSettings.FogMode    = FogMode.Exp2;
        }
Пример #4
0
        public override void Initialize()
        {
            base.Initialize();

            // First we add a Skybox
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.StarsSkybox);

            // And a camera with some components
            var camera = new CameraPrefab("camera");

            camera.AddComponent <ControllerSwitcher>();
            camera.AddComponent <DemoBehaviour>();
            Add(camera);

            // A light is required to illuminate objects.
            var lightPrefab = new LightPrefab("light", LightType.Directional);

            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            lightPrefab.Light.ShadowGenerator.SetShadowMapSize(Application.GraphicsDevice, 1024);
            lightPrefab.EnableShadows = true;
            Add(lightPrefab);

            // A terrain with its material.
            var terrainMaterial = new StandardMaterial(scene);

            terrainMaterial.Texture   = Application.Content.Load <Texture2D>("Textures/Terrain/Rock");
            terrainMaterial.Shininess = 150;
            terrainMaterial.Tiling    = new Vector2(8);

            var terrain = new TerrainPrefab("terrain");

            terrain.Renderer.Geometry.Size = new Vector3(2);
            terrain.Renderer.ReceiveShadow = true;
            terrain.Randomize(4, 12);
            terrain.Renderer.Material = terrainMaterial;
            terrain.Transform.Translate(-terrain.Width >> 1, 0, -terrain.Depth / 2);
            Add(terrain);

            // Lava !
            var lavaMaterial = new LavaMaterial(this);

            lavaMaterial.Texture   = Application.Content.Load <Texture2D>("Textures/lava_texture");
            lavaMaterial.NormalMap = Application.Content.Load <Texture2D>("Textures/lava_bump");

            var lava = new WaterPrefab("water");

            lava.Renderer.Material      = lavaMaterial;
            lava.Renderer.ReceiveShadow = true;
            lava.Renderer.Geometry.Size = new Vector3(terrain.Width * 0.5f);
            lava.Renderer.Geometry.Build();
            Add(lava);
        }
Пример #5
0
        public override void Initialize()
        {
            base.Initialize();

            // Camera
            var camera = new CameraPrefab("camera");

            camera.AddComponent <OrbitController>();
            camera.AddComponent <RayPickingTester>();
            Add(camera);

            // Light
            var lightPrefab = new LightPrefab("lightPrefab", LightType.Point);

            Add(lightPrefab);
            lightPrefab.Transform.Position = new Vector3(0, 15, 15);
            lightPrefab.Light.Range        = 105;
            lightPrefab.Light.Intensity    = 2.0f;
            lightPrefab.Light.FallOf       = 5f;
            lightPrefab.Light.Color        = Color.Violet;
            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            lightPrefab.Light.Angle        = 0.1f;
            lightPrefab.Light.ShadowGenerator.ShadowStrength = 0.6f; // FIXME need to be inverted
            lightPrefab.Light.ShadowGenerator.SetShadowMapSize(Application.GraphicsDevice, 1024);
            lightPrefab.EnableShadows = true;
            lightPrefab.AddComponent <LightSwitcher>();
            lightPrefab.AddComponent <LightMover>();
            lightPrefab.AddComponent <DemoBehaviour>();

            var lightPrefabSphere = lightPrefab.AddComponent <MeshRenderer>();

            lightPrefabSphere.Geometry = new SphereGeometry(2f, 4);
            lightPrefabSphere.Geometry.Build();
            lightPrefabSphere.CastShadow       = false;
            lightPrefabSphere.ReceiveShadow    = false;
            lightPrefabSphere.Material         = new SimpleMaterial(scene);
            lightPrefabSphere.Material.Texture = GraphicsHelper.CreateTexture(Color.Yellow, 1, 1);

            // Terrain
            var terrainMaterial = new StandardMaterial(scene);

            terrainMaterial.Texture   = GraphicsHelper.CreateBorderTexture(Color.LightGreen, Color.LightSeaGreen, 128, 128, 4);
            terrainMaterial.Shininess = 10;
            terrainMaterial.Tiling    = new Vector2(16);

            var terrain = new TerrainPrefab("terrain");

            terrain.Renderer.Geometry.Size = new Vector3(4);
            terrain.Renderer.Geometry.Build();
            terrain.Flatten();
            terrain.Renderer.Material = terrainMaterial;
            terrain.Transform.Translate(-terrain.Width >> 1, 0, -terrain.Depth / 2);
            Add(terrain);

            // Cube
            var cubeSuperMaterial = new StandardMaterial(scene);

            cubeSuperMaterial.Texture       = GraphicsHelper.CreateCheckboardTexture(Color.FloralWhite, Color.DodgerBlue);
            cubeSuperMaterial.DiffuseColor  = Color.WhiteSmoke;
            cubeSuperMaterial.SpecularColor = new Color(0.8f, 0.8f, 0.8f, 1.0f);
            cubeSuperMaterial.Shininess     = 10;
            cubeSuperMaterial.EmissiveColor = new Color(0f, 0.0f, 0.2f, 1.0f);

            var cubeScene = new SceneObject();

            cubeScene.Transform.Translate(0, 6f, 0);
            cubeScene.Transform.LocalScale = new Vector3(4.0f);
            cubeScene.Transform.Rotate((float)Math.PI / 4, 0, (float)Math.PI / 4);
            var autoRot = cubeScene.AddComponent <AutoRotation>();

            autoRot.Rotation = new Vector3(0, 0.01f, 0);
            Add(cubeScene);

            var cube = cubeScene.AddComponent <MeshRenderer>();

            cube.ReceiveShadow = false;
            cube.Geometry      = new CubeGeometry();
            cube.Geometry.Build();
            cube.Material = cubeSuperMaterial;

            cubeScene.AddComponent <BoxCollider>();

            // Skybox
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.StarsSkybox, 500);

            Screen.ShowCursor = true;
        }
Пример #6
0
        public override void Initialize()
        {
            base.Initialize();

            // Skybox
            RenderSettings.Skybox.Generate(Application.GraphicsDevice, Application.Content, DemoGame.StarsSkybox);

            // Camera
            var camera = new CameraPrefab("camera");

            camera.Transform.Translate(0, 25, 0);
            camera.AddComponent <DemoBehaviour>();
            camera.AddComponent <PostProcessSwitcher>();
            Add(camera);

            var orbitController = camera.AddComponent <OrbitController>();

            // Light
            var lightPrefab = new LightPrefab("light", LightType.Directional);

            lightPrefab.Transform.Rotation = new Vector3(-1, 1, 0);
            lightPrefab.Light.ShadowGenerator.SetShadowMapSize(Application.GraphicsDevice, 1024);
            lightPrefab.EnableShadows   = true;
            lightPrefab.Light.Intensity = 0.5f;
            lightPrefab.Light.FallOf    = 5.0f;
            Add(lightPrefab);

            // Terrain
            var terrainMaterial = new StandardMaterial(scene);

            terrainMaterial.Texture   = Application.Content.Load <Texture2D>("Textures/Terrain/Rock");
            terrainMaterial.Shininess = 50;
            terrainMaterial.Tiling    = new Vector2(8);

            var terrain = new TerrainPrefab("terrain");

            terrain.Renderer.Geometry.Size = new Vector3(2);
            terrain.Renderer.ReceiveShadow = true;
            terrain.Randomize(4, 15, 0.086, 0.25, true);
            terrain.Renderer.Material = terrainMaterial;
            terrain.Transform.Translate(-terrain.Width >> 1, 0, -terrain.Depth / 2);
            Add(terrain);

            // Lava
            var lava = new LavaPrefab("water");

            Add(lava);

            lava.Generate("Textures/lava_texture", "Textures/lava_bump", new Vector3(terrain.Width * 0.5f));

            var jack = new ModelPrefab("Jack");

            jack.Transform.Rotate(-MathHelper.PiOver2, MathHelper.Pi, 0);
            jack.Transform.Translate(0, 35, 0);
            jack.Transform.LocalScale = new Vector3(4);
            jack.LoadModel("Models/Jack/JackOLantern");
            var jackMaterial = new StandardMaterial(this);

            jackMaterial.EmissiveColor = new Color(0.2f, 0.005f, 0);
            jackMaterial.Texture       = Application.Content.Load <Texture2D>("Models/Jack/PumpkinColor");
            jack.Renderer.Material     = jackMaterial;
            Add(jack);

            orbitController.LookAt(jack.Transform);
            orbitController.Distance = 150.0f;
        }