Exemplo n.º 1
0
        public override void Initialize()
        {
            base.Initialize();

            // Add a camera with a FPS controller
            var cameraGo = AddGameObject("Camera"); GameObjectFactory.CreateCamera(new Vector3(0, 2, -10), new Vector3(0, 0, 0), Vector3.Up);

            var camera = cameraGo.GetComponent <Camera>();

            camera.Setup(new Vector3(0, 2, 5), Vector3.Forward, Vector3.Up);
            camera.Far = 10000;
            camera.AddComponent <EditorController>();

            // And a light
            var lightGo = AddGameObject("Directional");

            lightGo.Transform.LocalPosition = new Vector3(500, 500, 0);
            lightGo.Transform.LocalRotation = new Vector3(MathHelper.PiOver2, -MathHelper.PiOver4, 0);
            var directionalLight = lightGo.GetComponent <Light>();

            // Sun Flares
            var content       = Application.Content;
            var glowTexture   = content.Load <Texture2D>("Textures/Flares/SunGlow");
            var flareTextures = new Texture2D[]
            {
                content.Load <Texture2D>("Textures/Flares/circle"),
                content.Load <Texture2D>("Textures/Flares/circle_sharp_1"),
                content.Load <Texture2D>("Textures/Flares/circle_soft_1")
            };

            var direction = directionalLight.Direction;
            var sunflares = directionalLight.AddComponent <LensFlare>();

            sunflares.Setup(glowTexture, flareTextures);

            // Skybox
            var blueSkybox = new string[6]
            {
                "Textures/Skybox/bluesky/px",
                "Textures/Skybox/bluesky/nx",
                "Textures/Skybox/bluesky/py",
                "Textures/Skybox/bluesky/ny",
                "Textures/Skybox/bluesky/pz",
                "Textures/Skybox/bluesky/nz"
            };

            RenderSettings.Skybox.Generate(Application.GraphicsDevice, blueSkybox);

            // Grid
            var grid = new GameObject("Grid");

            grid.Tag = EditorGame.EditorTag;
            grid.AddComponent <Grid>();

            _defaultMaterial             = new StandardMaterial();
            _defaultMaterial.MainTexture = TextureFactory.CreateColor(Color.WhiteSmoke, 1, 1);

            SceneInitialized?.Invoke(new[] { cameraGo, lightGo });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize is called once when the control is created.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            Content = new ContentManager(Services, _contentDir);

            // hook events now (graphics, etc. is now loaded)
            // any components added prior we insert manually
            foreach (var c in Components)
            {
                ComponentAdded(this, new GameComponentCollectionEventArgs(c));
            }
            Components.ComponentAdded   += ComponentAdded;
            Components.ComponentRemoved += ComponentRemoved;

            LoadContent();
            SceneInitialized?.Invoke(this);
        }
Exemplo n.º 3
0
        private void glControl1_Load(object sender, EventArgs e)
        {
            //  create a new dynamic scene and pass this control as the scene owner to hook control
            //  then load the selected map into the scene
            Scene = new DynamicScene(_glControl1);

            //  application idle will handle the render and update loop
            Application.Idle   += HandleApplicationIdle;
            Scene.OnFrameReady += Scene_OnFrameReady;
            _glControl1.Resize += glControl1_Resize;

            //  firing this method is meant to load the view-projection matrix values into
            //  the shader uniforms, and initalizes the camera before the first draw can be called
            glControl1_Resize(this, new EventArgs( ));
            SceneInitialized?.Invoke(this, null);

            OpenGL.EnableDebugging();
        }
 private void Start()
 {
     SceneInitialized?.Invoke();
 }