Exemplo n.º 1
0
        /// <summary>
        /// Aktualizace herního světa a všech aktivních objektů před vykreslením.
        /// </summary>
        /// <param name="gameTime">Herní čas.</param>
        protected override void Update(GameTime gameTime)
        {
            //Aktuální stav vstupních zařízení
            _currentKeyboardState = Keyboard.GetState();

            _currentGamePadState = GamePad.GetState(PlayerIndex.One);
            _currentMouseState   = Mouse.GetState();

            if (PressedOnce(Keys.Escape, Buttons.Back))
            {
                Exit();
            }

            #region Přepínání ukázkových scén

            if (PressedOnce(Keys.Left, Buttons.DPadLeft))
            {
                DestructCurrentScene();
                _currentDemo++;
                _currentDemo = _currentDemo % DemoScenes.Count;
                DemoScenes[_currentDemo].Construct();
            }

            if (PressedOnce(Keys.Right, Buttons.DPadRight))
            {
                DestructCurrentScene();
                _currentDemo += DemoScenes.Count - 1;
                _currentDemo  = _currentDemo % DemoScenes.Count;
                DemoScenes[_currentDemo].Construct();
            }

            #endregion Přepínání ukázkových scén

            //Aktualizace pohybu kamerou
            CameraMovement(gameTime);

            //Aktualizace herního světa (a tím probíhající fyzikální simulace)
            World3D.Update(gameTime);

            //Možnost uchopení tělesa myší
            GrabWorldObject();
            DemoScenes[_currentDemo].Update(
                _currentKeyboardState,
                _previousKeyboardState,
                _currentGamePadState,
                _previousGamePadState);

            //Skrytí nebo zobrazení překryvného informačního textu
            if (PressedOnce(Keys.F12, Buttons.Start))
            {
                Info.Visible = !Info.Visible;
            }

            //Předchozí stav vstupních zařízení (pro další aktualizaci)
            _previousKeyboardState = _currentKeyboardState;
            _previousGamePadState  = _currentGamePadState;
            _previousMouseState    = _currentMouseState;

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        protected Scene3D(MasterRenderer3D renderer, Canvas canvas, World3D world, Space3D space) :
            base(canvas, world, space)
        {
            Debug.Assert(renderer != null, "3D scenes must be created with a non-null renderer.");

            Renderer = renderer;
        }
Exemplo n.º 3
0
        protected void LogErrorEvent(String message, int level)
        {
            Vixen.ErrorEvent err = new Vixen.ErrorEvent(World3D.Get());

            err.ErrString = message;
            err.ErrLevel  = level;
            err.ErrCode   = 0;
            err.Log();
        }
Exemplo n.º 4
0
 private void GrabWorldObject()
 {
     if (_currentMouseState.LeftButton == ButtonState.Pressed)
     {
         World3D.GrabBody(_currentMouseState.Position, force: 50f, viewport: _graphics.GraphicsDevice.Viewport);
     }
     if (_currentMouseState.LeftButton == ButtonState.Released)
     {
         World3D.ReleaseGrabbedBody();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Vykreslí aktuální scénu a nebe na pozadí.
        /// </summary>
        /// <param name="gameTime">Herní čas.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Bisque);
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            DrawSky();

            World3D.Draw();
            DemoScenes[_currentDemo].Draw();

            base.Draw(gameTime);
        }
Exemplo n.º 6
0
        protected override void Initialize()
        {
            Vector3 cameraPosition = new Vector3(0f, 5f, 6f);

            camera3D        = new BasicCamera3D(cameraPosition, GraphicsDevice.Viewport.AspectRatio);
            camera3D.Target = Vector3.Zero;

            Vector2 gravity = new Vector2(0f, -9.80665f);

            world3D = new World3D(gravity, camera3D);

            base.Initialize();
        }
Exemplo n.º 7
0
        private void DestructCurrentScene()
        {
            for (int i = Components.Count - 1; i >= 0; i--)
            {
                IGameComponent component = Components[i];
                if (component is Info)
                {
                    continue;
                }
                Components.RemoveAt(i);
            }

            World3D.Clear();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Výchozí inicializace všech objektů nutných pro vykreslování scén.
        /// </summary>
        protected override void Initialize()
        {
            SetGraphics(_windowed);

            Camera3D = new BasicCamera3D(
                DemoHelper.Positions.DefaultCameraPosition,
                _graphics.GraphicsDevice.Viewport.AspectRatio);

            World3D = new World3D(DemoHelper.Gravity.Earth, Camera3D);

            Info = new Info(this)
            {
                DrawOrder = int.MaxValue
            };
            Components.Add(Info);

            CreateScenesInstances();

            base.Initialize();
        }
Exemplo n.º 9
0
        public override object SolveOne()
        {
            var world = new World3D();

            for (int x = 0; x < Rows.Count; x++)
            {
                for (int y = 0; y < Rows[x].Length; y++)
                {
                    if (Rows[x][y] == '#')
                    {
                        world.SetValue(x, y, 0, true);
                    }
                }
            }

            for (int i = 0; i < 6; i++)
            {
                world = world.Run();
            }

            return(world.Sum(x => x.Value.Sum(y => y.Value.Count(z => z.Value))));
        }
Exemplo n.º 10
0
            public World3D Run()
            {
                int loX    = Keys.Min();
                int hiX    = Keys.Max();
                int loY    = Values.Min(x => x.Keys.Min());
                int hiY    = Values.Max(x => x.Keys.Max());
                int loZ    = Values.Min(x => x.Values.Min(y => y.Keys.Min()));
                int hiZ    = Values.Max(x => x.Values.Max(y => y.Keys.Max()));
                var output = new World3D();

                for (int x = loX - 1; x <= hiX + 1; x++)
                {
                    for (int y = loY - 1; y <= hiY + 1; y++)
                    {
                        for (int z = loZ - 1; z <= hiZ + 1; z++)
                        {
                            int nCount = CountNeighbors(x, y, z);
                            output.SetValue(x, y, z, nCount == 3 || (GetValue(x, y, z) && nCount == 2));
                        }
                    }
                }
                return(output);
            }
Exemplo n.º 11
0
        private void LoadWorld()
        {
            world3D = new World3D();
            world3D.LoadContent();

            camera1 = new Camera();
            camera1.LoadContent();
            camera1.position = new Vector3(0, 27, -22);
            camera1.Face(new Vector3(0, 26, -21));

            camera2 = new Camera();
            camera2.LoadContent();
            camera2.position = new Vector3(10, 10, -10);
            camera2.Face(new Vector3(0, 0, 0));
            camera2.minDepth = 1f;
            camera2.maxDepth = 50f;

            dirLight1 = new LightDirectional();
            dirLight1.LoadContent();

            zombie = new GenericModelObject();
            zombie.LoadContent();
            zombie.model     = Global.zombieSceneModel;
            zombie.ColorMap  = Global.zombieDiffuse;
            zombie.NormalMap = Global.zombieNormal;
            zombie.position  = new Vector3(0, 0.5f, -20);
            zombie.angle.Y   = MathHelper.ToRadians(-90);

            map = new Map();
            map.LoadContent();
            map.length = 10;
            map.width  = 10;

            Cwing1 = new GenericModelObject();
            Cwing1.LoadContent();
            Cwing1.model       = Global.ship1Model;
            Cwing1.ColorMap    = Global.ship1Diffuse;
            Cwing1.NormalMap   = Global.ship1Normal;
            Cwing1.SpecularMap = Global.ship1Specular;
            Cwing1.position    = new Vector3(-52, 5f, 60);

            Acolyte1 = new GenericModelObject();
            Acolyte1.LoadContent();
            Acolyte1.model       = Global.ship2Model;
            Acolyte1.ColorMap    = Global.ship2Diffuse;
            Acolyte1.NormalMap   = Global.ship2Normal;
            Acolyte1.SpecularMap = Global.ship2Specular;
            Acolyte1.position    = new Vector3(-32, 5f, 60);

            Orbiter = new Orbiter();
            Orbiter.LoadContent();
            Orbiter.size = Vector3.One * 0.4f;

            Orbiter2 = new Orbiter();
            Orbiter2.LoadContent();
            Orbiter2.size = Vector3.One * 0.4f;

            Orbiter3 = new Orbiter();
            Orbiter3.LoadContent();
            Orbiter3.size = Vector3.One * 0.4f;

            pointLight1 = new PointLight();
            pointLight1.LoadContent();
            pointLight1.intensity = 1.5f;
            pointLight1.position  = new Vector3(40, 5, 45);
            pointLight1.color     = Color.Red;

            spotLight1 = new SpotLight();
            spotLight1.LoadContent();
            spotLight1.intensity = 2f;
            spotLight1.color     = Color.White;
            spotLight1.intensity = 1.5f;
            spotLight1.position  = new Vector3(10, 40, 30);
            spotLight1.Face(new Vector3(0f, -1, -0.7f));

            spotLight2 = new SpotLight();
            spotLight2.LoadContent();
            spotLight2.intensity = 2f;
            spotLight2.color     = Color.Red;
            spotLight2.intensity = 1.5f;
            spotLight2.position  = new Vector3(-60f, 35f, 75f);
            spotLight2.Face(new Vector3(-40f, 0f, 55f));

            spotLight3 = new SpotLight();
            spotLight3.LoadContent();
            spotLight3.intensity = 2f;
            spotLight3.color     = Color.Blue;
            spotLight3.intensity = 1.5f;
            spotLight3.position  = new Vector3(-20f, 35f, 75f);
            spotLight3.Face(new Vector3(-40f, 0f, 55f));

            spotLight4 = new SpotLight();
            spotLight4.LoadContent();
            spotLight4.intensity = 2f;
            spotLight4.color     = Color.Green;
            spotLight4.intensity = 1.5f;
            spotLight4.position  = new Vector3(-40f, 35f, 75f);
            spotLight4.Face(new Vector3(-40f, 0f, 45f));

            blueBall = new Ball();
            blueBall.LoadContent();
            blueBall.position = new Vector3(10, 15, 5);
            blueBall.friction = 1f;
            blueBall.Material.diffuseColor = Color.Blue.ToVector4();
            blueBall.Material.matteColor   = Color.AliceBlue.ToVector4();
            blueBall.Material.shininess    = 1f;
            blueBall.Material.ambient      = 0.4f;

            ball2 = new Ball();
            ball2.LoadContent();
            ball2.position = new Vector3(0f, 1f, 0f);
            ball2.Material.diffuseColor = Color.DarkMagenta.ToVector4();
            ball2.Material.matteColor   = Color.Magenta.ToVector4();
            ball2.Material.shininess    = 1f;
            ball2.Material.ambient      = 0.2f;

            ball4 = new Ball();
            ball4.LoadContent();
            ball4.position = new Vector3(0f, 3f, 0f);
            ball4.Material.diffuseColor = Color.Green.ToVector4();
            ball4.Material.matteColor   = Color.GreenYellow.ToVector4();
            ball4.Material.shininess    = 1f;
            ball4.Material.ambient      = 0.2f;

            goldBall = new Ball();
            goldBall.LoadContent();
            goldBall.position = new Vector3(50f, 10f, 50f);
            goldBall.Material.diffuseColor = Color.Goldenrod.ToVector4();
            goldBall.Material.matteColor   = Color.Gold.ToVector4();
            goldBall.Material.shininess    = 2f;
            goldBall.size = Vector3.One * 10;

            orientAid = new Orientaid();
            orientAid.LoadContent();
            orientAid2 = new Orientaid();
            orientAid2.LoadContent();
            orientAid3 = new Orientaid();
            orientAid3.LoadContent();
            orientAid4 = new Orientaid();
            orientAid4.LoadContent();

            a1 = new Arrow();
            a1.LoadContent();
            a2 = new Arrow();
            a2.LoadContent();
            a3 = new Arrow();
            a3.LoadContent();
            a4 = new Arrow();
            a4.LoadContent();
            a5 = new Arrow();
            a5.LoadContent();
            a6 = new Arrow();
            a6.LoadContent();
            a7 = new Arrow();
            a7.LoadContent();
            a8 = new Arrow();
            a8.LoadContent();
            a9 = new Arrow();
            a9.LoadContent();
            a10 = new Arrow();
            a10.LoadContent();
        }
Exemplo n.º 12
0
        protected override void Initialize()
        {
            Vector3 cameraPosition = new Vector3(0f, 4f, 15f);

            camera3D        = new BasicCamera3D(cameraPosition, GraphicsDevice.Viewport.AspectRatio);
            camera3D.Target = new Vector3(0f, 0f, 3f);

            Vector2 gravity = new Vector2(0f, -9.80665f);

            world3D = new World3D(gravity, camera3D);

            #region BasicEffectParams

            Vector3 ambientColor  = Color.Blue.ToVector3();
            Vector3 specularColor = Color.Red.ToVector3();
            float   specularPower = 1f;
            Vector3 emmisiveColor = Color.Black.ToVector3();

            Vector3 directionalLight0Direction     = new Vector3(-1.5f, -1.5f, 1f);
            Vector3 directionalLight0DiffuseColor  = Color.Green.ToVector3();
            Vector3 directionalLight0SpecularColor = Color.Magenta.ToVector3();

            Vector3 directionalLight1Direction     = new Vector3(-1.5f, 1.5f, 0f);
            Vector3 directionalLight1DiffuseColor  = Color.Cyan.ToVector3();
            Vector3 directionalLight1SpecularColor = Color.Yellow.ToVector3();

            Vector3 directionalLight2Direction     = new Vector3(0, 1.5f, 1.5f);
            Vector3 directionalLight2DiffuseColor  = Color.Violet.ToVector3();
            Vector3 directionalLight2SpecularColor = Color.White.ToVector3();

            DirectionalLightParams directionalLight1 =
                new DirectionalLightParams(
                    directionalLight0Direction,
                    directionalLight0DiffuseColor,
                    directionalLight0SpecularColor);

            DirectionalLightParams directionalLight2 =
                new DirectionalLightParams(
                    directionalLight1Direction,
                    directionalLight1DiffuseColor,
                    directionalLight1SpecularColor);

            DirectionalLightParams directionalLight3 =
                new DirectionalLightParams(
                    directionalLight2Direction,
                    directionalLight2DiffuseColor,
                    directionalLight2SpecularColor);;

            FogParams fogParams = new FogParams(Color.CornflowerBlue.ToVector3(), 10f, 25f);

            effectParams =
                new BasicEffectParams(
                    ambientColor,
                    specularColor,
                    specularPower,
                    emmisiveColor,
                    directionalLight1,
                    directionalLight2,
                    directionalLight3,
                    fogParams);

            #endregion BasicEffectParams

            base.Initialize();
        }