Esempio n. 1
0
        public Planet(string name, Vector3d position, IModule module, Effect testEffect, float radius, Color sea, Color land, Color mountains)
        {
            nodesBeingBuilt  = new Dictionary <Vector3, PatchMinMax>();
            neighbourTracker = new NeighbourTracker();
            this.Name        = name;
            planetId         = ++planetIdList;
            this.module      = module;
            this.testEffect  = testEffect;
            this.radius      = radius;

            Position = new HighPrecisionPosition();
            AddComponent(Position);

            Transform.SetHighPrecisionPosition(position);

            splitDistance = radius * 4;

            customProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                   SystemCore.GraphicsDevice.Viewport.AspectRatio, 1f, this.radius * 10);

            SeaColor      = sea;
            LandColor     = land;
            MountainColor = mountains;


            Initialise();
        }
Esempio n. 2
0
        protected override void LoadContent()
        {
            base.LoadContent();

            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI * 0.25f,
                (float)TargetSize.Width / TargetSize.Height,
                0.05f,
                1000f);

            var camera = new Camera(_projectionMatrix)
            {
                ViewPosition = new Vector3(-.0f, .0f, 1.2f)
            };
            var device = Graphics.GraphicsDevice;

            _sun = new Sun(StarType);
            _sun.Create(Graphics, Content, camera);

            _usePostProcessor = device.GraphicsDeviceCapabilities.DeviceType == DeviceType.Hardware &&
                                device.GraphicsDeviceCapabilities.MaxPixelShaderProfile >= ShaderProfile.PS_3_0;

            if (_usePostProcessor)
            {
                _postProcessor = new PostProcessor(device, Content);
            }
        }
Esempio n. 3
0
        private void InitializeXNA()
        {
            _device = SharedGraphicsDeviceManager.Current.GraphicsDevice;

            // Set the sharing mode of the graphics device to turn on XNA rendering
            _device.SetSharingMode(true);

            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(_device);

            BackgroundRenderer = new UIElementRenderer(this, _device.Viewport.Width, _device.Viewport.Height);
            // Create a timer for this page
            _gameTimer = new GameTimer();
            _gameTimer.UpdateInterval = TimeSpan.FromTicks(333333);
            _gameTimer.Update        += new EventHandler <GameTimerEventArgs>(_gameTimer_Update);
            _gameTimer.Draw          += new EventHandler <GameTimerEventArgs>(_gameTimer_Draw);

            _cameraMatrix     = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, (float)(this.LayoutRoot.ActualWidth / this.LayoutRoot.ActualHeight), 0.01f, 10000.0f);

            foreach (LocationsVM.Location l in myVM.SelectedNearbyLocations)
            {
                l.Object3dEffect                = new BasicEffect(_device);
                l.Object3dEffect.World          = l.WorldMatrix;
                l.Object3dEffect.View           = _cameraMatrix;
                l.Object3dEffect.Projection     = _projectionMatrix;
                l.Object3dEffect.TextureEnabled = true;
            }

            _gameTimer.Start();
        }
Esempio n. 4
0
 public Camera(Game g, Vector3 position, Vector3 target, Vector3 up)
     : base(g)
 {
     view       = Matrix.CreateLookAt(position, target, up);
     projection = Matrix.CreatePerspectiveFieldOfView(
         MathHelper.PiOver4,
         (float)g.Window.ClientBounds.Width / g.Window.ClientBounds.Height,
         1, 100);
 }
        public void InitializeViewport()
        {
            // Initialize the viewport and matrixes for 3d projection.
            viewport = new Viewport(0, 0, (int)this.ActualWidth, (int)this.ActualHeight);
            float aspect = viewport.AspectRatio;

            projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 12);
            view       = Matrix.CreateLookAt(new Vector3(0, 0, 1), Vector3.Zero, Vector3.Up);
        }
Esempio n. 6
0
        private void GenerateCustomProjectionMatrix(float far)
        {
            if (far <= 0)
            {
                far = 2;
            }

            customProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                   SystemCore.GraphicsDevice.Viewport.AspectRatio, 1f, far);
        }
Esempio n. 7
0
        private void InitializeXna()
        {
            CreateDevice();

            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI * 0.25f,
                (float)_targetSize.Width / _targetSize.Height,
                0.05f,
                1000f);

            _copySurfaceMethod = typeof(GraphicsDevice).GetMethod("CopySurface", BindingFlags.Instance | BindingFlags.NonPublic);

            CreateBuffers();
            CreateContentManager();
            LoadSun();
        }
Esempio n. 8
0
        private void OnLoadedContent(object sender, EventArgs e)
        {
            var eye = new Vector3(0.0f, 0.0f, -35.0f);
            var at  = new Vector3(0.0f, 0.0f, 0.0f);
            var up  = new Vector3(0, 1.0f, 0.0f);

            _worldMatrix      = Matrix.Identity;
            _viewMatrix       = Matrix.CreateLookAt(eye, at, up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI * 0.25f,
                (float)Component.TargetSize.Width / Component.TargetSize.Height,
                1f,
                1000f);

            LoadModel();
        }
Esempio n. 9
0
        void UpdateCameraThirdPerson()
        {
            // Create a vector pointing the direction the camera is facing.
            //var transformedReference = Vector3.Transform(, Matrix.CreateRotationY(avatarYaw));
            //transformedReference = Vector3.Transform(transformedReference, Matrix.CreateRotationX(avatarPitch));

            // Calculate the position the camera is looking from
            var target = avatarPosition + Vector3.Transform(Vector3.UnitZ, Matrix.CreateFromYawPitchRoll(avatarYaw, avatarPitch, 0));

            // Set up the view matrix and projection matrix
            _view = Matrix.CreateLookAt(avatarPosition, target, new Vector3(0.0f, 1.0f, 0.0f));

            var viewport    = _graphics.GraphicsDevice.Viewport;
            var aspectRatio = viewport.Width / (float)viewport.Height;

            _proj = Matrix.CreatePerspectiveFieldOfView(ViewAngle, aspectRatio, NearClip, FarClip);
        }
Esempio n. 10
0
        public void Draw()
        {
            GraphicsDevice device = SharedGraphicsDeviceManager.Current.GraphicsDevice;

            device.BlendState        = BlendState.Opaque;
            device.RasterizerState   = RasterizerState.CullCounterClockwise;
            device.DepthStencilState = DepthStencilState.Default;

            // Store the old viewport and set the desired viewport
            Viewport oldViewport = device.Viewport;

            device.Viewport = new Viewport(state.ViewportRect);

            // Calculate the world-view-projection matrices for the tank and camera
            Matrix world      = Matrix.CreateScale(.002f) * Matrix.CreateRotationY(MathHelper.ToRadians((float)state.TankRotationY));
            Matrix view       = Matrix.CreateLookAt(state.CameraPosition, state.CameraTarget, Vector3.Up);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, device.Viewport.AspectRatio, .01f, 100f);

            // Draw the sky
            sky.Draw(view, projection);

            // Draw the ground
            groundEffect.World      = Matrix.Identity;
            groundEffect.View       = view;
            groundEffect.Projection = projection;
            device.SetVertexBuffer(groundVertices);
            foreach (var pass in groundEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }

            // Draw the tank
            tank.Draw(world, view, projection, state);

            // Reset the viewport
            device.Viewport = oldViewport;
        }
Esempio n. 11
0
        private void InitializeXna()
        {
            CreateDevice();

            var eye = new Vector3(0.0f, 0.0f, -35.0f);
            var at  = new Vector3(0.0f, 0.0f, 0.0f);
            var up  = new Vector3(0, 1.0f, 0.0f);

            _worldMatrix      = Matrix.Identity;
            _viewMatrix       = Matrix.CreateLookAt(eye, at, up);
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                (float)Math.PI * 0.25f,
                (float)_targetSize.Width / _targetSize.Height,
                1f,
                1000f);

            CreateBuffers();

            _copySurfaceMethod = typeof(GraphicsDevice).GetMethod("CopySurface", BindingFlags.Instance | BindingFlags.NonPublic);

            this.CreateContentManager();
            this.LoadModel();
        }
Esempio n. 12
0
        protected override void Present(XnaTime time)
        {
            var device = Graphics.GraphicsDevice;

            Clear();

            // Compute camera matrices.
            var aspectRatio = (float)device.Viewport.Width / device.Viewport.Height;

            var view = Matrix.CreateLookAt(
                new Vector3(0, 0, -200),
                new Vector3(0, 0, 0),
                Vector3.Up);

            var projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4,
                aspectRatio,
                1,
                10000);

            // Pass camera matrices through to the particle system components.
            _explosionParticles.SetCamera(view, projection);
            _explosionParticles.Draw(time);
        }
Esempio n. 13
0
        public virtual void Initialize()
        {
            float tilt = MathHelper.ToRadians(0);  // 0 degree angle

            // Use the world matrix to tilt the cube along x and y axes.
            _worldMatrix = Matrix.CreateRotationX(tilt) * Matrix.CreateRotationY(tilt);
            _viewMatrix  = Matrix.CreateLookAt(new Vector3(5, 5, 5), Vector3.Zero, Vector3.Up);

            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45),  // 45 degree angle
                (float)GraphicsDevice.Viewport.Width /
                (float)GraphicsDevice.Viewport.Height,
                1.0f, 100.0f);

            _basicEffect = new BasicEffect(GraphicsDevice);

            _basicEffect.World      = _worldMatrix;
            _basicEffect.View       = _viewMatrix;
            _basicEffect.Projection = _projectionMatrix;

            // primitive color
            _basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);
            _basicEffect.DiffuseColor      = new Vector3(1.0f, 1.0f, 1.0f);
            _basicEffect.SpecularColor     = new Vector3(0.25f, 0.25f, 0.25f);
            _basicEffect.SpecularPower     = 5.0f;
            _basicEffect.Alpha             = 1.0f;

            _basicEffect.LightingEnabled = true;
            if (_basicEffect.LightingEnabled)
            {
                _basicEffect.DirectionalLight0.Enabled = true; // enable each light individually
                if (_basicEffect.DirectionalLight0.Enabled)
                {
                    // x direction
                    _basicEffect.DirectionalLight0.DiffuseColor = new Vector3(1, 0, 0); // range is 0 to 1
                    _basicEffect.DirectionalLight0.Direction    = Vector3.Normalize(new Vector3(-1, 0, 0));
                    // points from the light to the origin of the scene
                    _basicEffect.DirectionalLight0.SpecularColor = Vector3.One;
                }

                _basicEffect.DirectionalLight1.Enabled = true;
                if (_basicEffect.DirectionalLight1.Enabled)
                {
                    // y direction
                    _basicEffect.DirectionalLight1.DiffuseColor  = new Vector3(0, 0.75f, 0);
                    _basicEffect.DirectionalLight1.Direction     = Vector3.Normalize(new Vector3(0, -1, 0));
                    _basicEffect.DirectionalLight1.SpecularColor = Vector3.One;
                }

                _basicEffect.DirectionalLight2.Enabled = true;
                if (_basicEffect.DirectionalLight2.Enabled)
                {
                    // z direction
                    _basicEffect.DirectionalLight2.DiffuseColor  = new Vector3(0, 0, 0.5f);
                    _basicEffect.DirectionalLight2.Direction     = Vector3.Normalize(new Vector3(0, 0, -1));
                    _basicEffect.DirectionalLight2.SpecularColor = Vector3.One;
                }
            }

            vertexDeclaration = new VertexDeclaration(new[]
            {
                new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
            });

            Vector3 topLeftFront     = new Vector3(-1.0f, 1.0f, 1.0f);
            Vector3 bottomLeftFront  = new Vector3(-1.0f, -1.0f, 1.0f);
            Vector3 topRightFront    = new Vector3(1.0f, 1.0f, 1.0f);
            Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f);
            Vector3 topLeftBack      = new Vector3(-1.0f, 1.0f, -1.0f);
            Vector3 topRightBack     = new Vector3(1.0f, 1.0f, -1.0f);
            Vector3 bottomLeftBack   = new Vector3(-1.0f, -1.0f, -1.0f);
            Vector3 bottomRightBack  = new Vector3(1.0f, -1.0f, -1.0f);

            Vector2 textureTopLeft     = new Vector2(0.0f, 0.0f);
            Vector2 textureTopRight    = new Vector2(1.0f, 0.0f);
            Vector2 textureBottomLeft  = new Vector2(0.0f, 1.0f);
            Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);

            Vector3 frontNormal  = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 backNormal   = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 topNormal    = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal   = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal  = new Vector3(1.0f, 0.0f, 0.0f);

            var cubeVertices = new VertexPositionNormalTexture[36];

            // Front face.
            cubeVertices[0] = new VertexPositionNormalTexture(topLeftFront, frontNormal, textureTopLeft);
            cubeVertices[1] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[2] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);
            cubeVertices[3] = new VertexPositionNormalTexture(bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[4] = new VertexPositionNormalTexture(bottomRightFront, frontNormal, textureBottomRight);
            cubeVertices[5] = new VertexPositionNormalTexture(topRightFront, frontNormal, textureTopRight);

            // Back face.
            cubeVertices[6]  = new VertexPositionNormalTexture(topLeftBack, backNormal, textureTopRight);
            cubeVertices[7]  = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[8]  = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[9]  = new VertexPositionNormalTexture(bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[10] = new VertexPositionNormalTexture(topRightBack, backNormal, textureTopLeft);
            cubeVertices[11] = new VertexPositionNormalTexture(bottomRightBack, backNormal, textureBottomLeft);

            // Top face.
            cubeVertices[12] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[13] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);
            cubeVertices[14] = new VertexPositionNormalTexture(topLeftBack, topNormal, textureTopLeft);
            cubeVertices[15] = new VertexPositionNormalTexture(topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[16] = new VertexPositionNormalTexture(topRightFront, topNormal, textureBottomRight);
            cubeVertices[17] = new VertexPositionNormalTexture(topRightBack, topNormal, textureTopRight);

            // Bottom face.
            cubeVertices[18] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[19] = new VertexPositionNormalTexture(bottomLeftBack, bottomNormal, textureBottomLeft);
            cubeVertices[20] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[21] = new VertexPositionNormalTexture(bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[22] = new VertexPositionNormalTexture(bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[23] = new VertexPositionNormalTexture(bottomRightFront, bottomNormal, textureTopRight);

            // Left face.
            cubeVertices[24] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);
            cubeVertices[25] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[26] = new VertexPositionNormalTexture(bottomLeftFront, leftNormal, textureBottomRight);
            cubeVertices[27] = new VertexPositionNormalTexture(topLeftBack, leftNormal, textureTopLeft);
            cubeVertices[28] = new VertexPositionNormalTexture(bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[29] = new VertexPositionNormalTexture(topLeftFront, leftNormal, textureTopRight);

            // Right face.
            cubeVertices[30] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[31] = new VertexPositionNormalTexture(bottomRightFront, rightNormal, textureBottomLeft);
            cubeVertices[32] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);
            cubeVertices[33] = new VertexPositionNormalTexture(topRightBack, rightNormal, textureTopRight);
            cubeVertices[34] = new VertexPositionNormalTexture(topRightFront, rightNormal, textureTopLeft);
            cubeVertices[35] = new VertexPositionNormalTexture(bottomRightBack, rightNormal, textureBottomRight);

            _vertexBuffer = new VertexBuffer(GraphicsDevice, vertexDeclaration, cubeVertices.Length, BufferUsage.None);
            _vertexBuffer.SetData(cubeVertices);
        }
        MathboxRenderer(Machine machine, ScreenManager screenManager)
        {
            Machine       = machine;
            Memory        = Machine.Mathbox.Memory16;
            ScreenManager = screenManager;

            if (!(screenManager.Game is I_Robot.Game game))
            {
                throw new Exception("VideoInterpreter can only be used with I_Robot.Game");
            }
            Game = game;

            DisplayListManager = new DisplayList.Manager(this);
            Object             = new ObjectRenderer(this);
            Terrain            = new TerrainRenderer(this);

            // create our scene buffer
            // this buffer has a z-buffer
            SceneBuffer = new RenderTarget2D(
                Game.GraphicsDevice,
                Game.GraphicsDevice.Viewport.Width,
                Game.GraphicsDevice.Viewport.Height,
                false,
                Game.GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.None,
                8,
                RenderTargetUsage.DiscardContents);

            // create our two screen buffers
            // these buffers do not require depth sorting, they are simply raw bitmaps
            // however the contents need to be preserved when rendering context is reset
            for (int n = 0; n < ScreenBuffers.Length; n++)
            {
                ScreenBuffers[n] = new RenderTarget2D(
                    Game.GraphicsDevice,
                    Game.GraphicsDevice.Viewport.Width,
                    Game.GraphicsDevice.Viewport.Height,
                    false,
                    Game.GraphicsDevice.PresentationParameters.BackBufferFormat,
                    DepthFormat.None,
                    0,
                    RenderTargetUsage.PreserveContents);
            }

            camTarget   = new Vector3(0f, 0f, 0f);
            camPosition = new Vector3(0f, 0f, -1f);

            double scaleToMonitor = Emulation.Machine.MonitorAspectRatio / Emulation.Machine.NativeAspectRatio;

            projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45f),
                (float)(Game.GraphicsDevice.Viewport.AspectRatio / scaleToMonitor),
                0.1f,
                65536f);

            // it's important to move the projection matrix down a bit, this matches what I, Robot seems to do
            projectionMatrix = projectionMatrix * Matrix.CreateTranslation(new Vector3(0, -0.1f, 0));
            viewMatrix       = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
            worldMatrix      = Matrix.CreateWorld(Vector3.Zero, Vector3.Forward, Vector3.Down);

            basicEffect       = new BasicEffect(Game.GraphicsDevice);
            basicEffect.Alpha = 1f;
            basicEffect.VertexColorEnabled = true; // Want to see the colors of the vertices, this needs to be on
            // Lighting requires normal information which VertexPositionColor does not have
            // If you want to use lighting and VPC you need to create a custom def
            basicEffect.LightingEnabled = false;
        }