Esempio n. 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //_level = new Level(GraphicsDevice, Content, 300, 300, 300);
            //_gameWorld = GameWorld.CreateNew(GraphicsDevice, Content, 300, 300, 300);
            _gameWorld = GameWorld.Load("test.level", GraphicsDevice, Content);
            _camera = new FirstPersonCamera(new Vector3(100, 100, 100), Vector3.Zero, Vector3.Up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 2.0f, 4.0f / 3.0f, 1, 1000000);

            _console = new GameConsole(Content);

            _sun = Content.Load<Model>("sun");

            _lightEffect = new BasicEffect(GraphicsDevice);
            _lightEffect.Projection = _projectionMatrix;
            _lightEffect.World = Matrix.Identity;

            _crosshair = Content.Load<Texture2D>("crosshair");

            graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            graphics.ToggleFullScreen();

            _screenCenterX = GraphicsDevice.Viewport.Width / 2;
            _screenCenterY = GraphicsDevice.Viewport.Height / 2;
            _crosshairRectangle = new Rectangle(_screenCenterX - _crosshair.Width / 2, _screenCenterY - _crosshair.Height / 2, _crosshair.Width, _crosshair.Height);

            Mouse.SetPosition(_screenCenterX, _screenCenterY);
            _previousMouseState = Mouse.GetState();
            _previousKeyboardState = Keyboard.GetState();

            //_viewMatrix = Matrix.CreateLookAt(_camera.Position, _camera.FocalPoint, _camera.UpVector);
            _lightEffect.View = _viewMatrix;

            _lightPosition = new Vector3(1, 0, 0) * _lightDistance;
            Matrix verticalRotation = Matrix.CreateRotationZ(_lightVerticalAngle);
            Matrix horizontalRotation = Matrix.CreateRotationY(_lightHorizontalAngle);

            // abuse the fact that I made the sun model and know that +z is the normal
            Vector3 currentNormal = Vector3.UnitZ;
            Vector3 desiredNormal = _camera.Position - _lightPosition;
            desiredNormal.Normalize();
            Vector3 axisOfRotation = Vector3.Cross(currentNormal, desiredNormal);
            float angleToRotate = (float)Math.Acos(Vector3.Dot(currentNormal, desiredNormal));

            _sunWorldMatrix = Matrix.CreateScale(75) * Matrix.CreateFromAxisAngle(axisOfRotation, angleToRotate) * Matrix.CreateTranslation(_lightPosition) * horizontalRotation * verticalRotation;

            _viewMatrix = Matrix.CreateLookAt(_camera.Position, _camera.FocalPoint, _camera.UpVector);

            _gameWorld.SetActiveRenderArea(new Vector3(10, 10, 10), 200);

            _lightWorldPosition = Vector3.Transform(Vector3.Zero, _sunWorldMatrix);

            //ComputeShadowMesh(_lightWorldPosition);

            //_shadowVolumeEffect = Content.Load<Effect>("ShadowVolume");
            //_renderWithShadowsEffect = Content.Load<Effect>("RenderWithShadows");
            //_renderWithShadowsEffect.CurrentTechnique = _renderWithShadowsEffect.Techniques["Technique1"];
        }
Esempio n. 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //_level = new Level(GraphicsDevice, Content, 300, 300, 300);
            //_gameWorld = GameWorld.CreateNew(GraphicsDevice, Content, 300, 300, 300);
            _gameWorld        = GameWorld.Load("test.level", GraphicsDevice, Content);
            _camera           = new FirstPersonCamera(new Vector3(100, 100, 100), Vector3.Zero, Vector3.Up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 2.0f, 4.0f / 3.0f, 1, 1000000);

            _console = new GameConsole(Content);

            _sun = Content.Load <Model>("sun");

            _lightEffect            = new BasicEffect(GraphicsDevice);
            _lightEffect.Projection = _projectionMatrix;
            _lightEffect.World      = Matrix.Identity;

            _crosshair = Content.Load <Texture2D>("crosshair");

            graphics.PreferredBackBufferWidth  = GraphicsDevice.DisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
            graphics.ToggleFullScreen();

            _screenCenterX      = GraphicsDevice.Viewport.Width / 2;
            _screenCenterY      = GraphicsDevice.Viewport.Height / 2;
            _crosshairRectangle = new Rectangle(_screenCenterX - _crosshair.Width / 2, _screenCenterY - _crosshair.Height / 2, _crosshair.Width, _crosshair.Height);

            Mouse.SetPosition(_screenCenterX, _screenCenterY);
            _previousMouseState    = Mouse.GetState();
            _previousKeyboardState = Keyboard.GetState();

            //_viewMatrix = Matrix.CreateLookAt(_camera.Position, _camera.FocalPoint, _camera.UpVector);
            _lightEffect.View = _viewMatrix;

            _lightPosition = new Vector3(1, 0, 0) * _lightDistance;
            Matrix verticalRotation   = Matrix.CreateRotationZ(_lightVerticalAngle);
            Matrix horizontalRotation = Matrix.CreateRotationY(_lightHorizontalAngle);

            // abuse the fact that I made the sun model and know that +z is the normal
            Vector3 currentNormal = Vector3.UnitZ;
            Vector3 desiredNormal = _camera.Position - _lightPosition;

            desiredNormal.Normalize();
            Vector3 axisOfRotation = Vector3.Cross(currentNormal, desiredNormal);
            float   angleToRotate  = (float)Math.Acos(Vector3.Dot(currentNormal, desiredNormal));

            _sunWorldMatrix = Matrix.CreateScale(75) * Matrix.CreateFromAxisAngle(axisOfRotation, angleToRotate) * Matrix.CreateTranslation(_lightPosition) * horizontalRotation * verticalRotation;

            _viewMatrix = Matrix.CreateLookAt(_camera.Position, _camera.FocalPoint, _camera.UpVector);

            _gameWorld.SetActiveRenderArea(new Vector3(10, 10, 10), 200);

            _lightWorldPosition = Vector3.Transform(Vector3.Zero, _sunWorldMatrix);

            //ComputeShadowMesh(_lightWorldPosition);

            //_shadowVolumeEffect = Content.Load<Effect>("ShadowVolume");
            //_renderWithShadowsEffect = Content.Load<Effect>("RenderWithShadows");
            //_renderWithShadowsEffect.CurrentTechnique = _renderWithShadowsEffect.Techniques["Technique1"];
        }