Beispiel #1
0
        /// <summary>
        /// Invoked after either control has created its graphics device.
        /// </summary>
        private void OnGraphicsControlLoadContent(object sender, GraphicsDeviceEventArgs e)
        {
	        _basicEffect = new BasicEffect(e.GraphicsDevice)
	        {
		        View = Matrix.LookAtRH(new Vector3(0, 0, 3), new Vector3(0, 0, 0), Vector3.UnitY),
		        World = Matrix.Identity,
		        PreferPerPixelLighting = true
	        };
	        _basicEffect.EnableDefaultLighting();

            _geometricPrimitives = new[]
            {
                GeometricPrimitive.Cube.New(e.GraphicsDevice),
                GeometricPrimitive.Cylinder.New(e.GraphicsDevice),
                GeometricPrimitive.GeoSphere.New(e.GraphicsDevice),
                GeometricPrimitive.Teapot.New(e.GraphicsDevice),
                GeometricPrimitive.Torus.New(e.GraphicsDevice)
            };
            _primitiveIndex = 0;

	        _texture = Texture2D.Load(e.GraphicsDevice, "Modules/SceneViewer/Resources/tile_aqua.png");
	        _basicEffect.Texture = _texture;
	        _basicEffect.TextureEnabled = true;

            _yaw = 0.5f;
            _pitch = 0.3f;
        }
Beispiel #2
0
 public BasicEffect GetParamsFromModel()
 {
     if (myModel.modelType == ModelType.Colored)
     {
         basicEffect = new BasicEffect(game.GraphicsDevice)
         {
             View = game.camera.View,
             Projection = game.camera.Projection,
             World = Matrix.Identity,
             VertexColorEnabled = true
         };
     }
     else if (myModel.modelType == ModelType.Textured)
     {
         basicEffect = new BasicEffect(game.GraphicsDevice)
         {
             View = game.camera.View,
             Projection = game.camera.Projection,
             World = Matrix.Identity,
             Texture = myModel.Texture,
             TextureEnabled = true,
             VertexColorEnabled = false
         };
     }
     return basicEffect;
 }
        public Enemy(LabGame game, Vector3 pos)
        {
            this.game = game;
            type = GameObjectType.Enemy;

            model = game.assets.GetModel("ship", CreateEnemyModel);
            collisionRadius = size/2;

            BoundingSphere modelBounds = model.CalculateBounds();
            scaling = size / modelBounds.Radius;
            originalWorld = Matrix.Translation(-modelBounds.Center.X, -modelBounds.Center.Y, -modelBounds.Center.Z) * Matrix.Scaling(scaling);

            this.pos = pos;
            //setFireTimer();
            //GetParamsFromModel();

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                //World = Matrix.Identity
                World = originalWorld

            };
        }
Beispiel #4
0
        private VertexPositionNormalColor[] terrain; //Terrain vertices

        #endregion Fields

        #region Constructors

        public Landscape(Project1Game game, int degree)
        {
            this.degree = degree;
            this.size = (int)Math.Pow(2,this.degree)+1;
            this.maxheight = this.size/2;
            this.polycount = (int)Math.Pow(this.size - 1, 2) * 2;
            this.rngesus = new Random();
            this.coords = new float[size, size];

            //Generate the heightmap using DiamondSquare
            Generate(0,this.size,0,size,maxheight,size/2);
            //Generate the terrain model
            this.terrain = TerrainModel(this.coords);
            //Place terrain model into vertex buffer
            vertices = Buffer.Vertex.New(game.GraphicsDevice, TerrainModel(this.coords));

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                LightingEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f),
                World = Matrix.Identity
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.gameaccess = game;
            this.game = game;
        }
Beispiel #5
0
        public Water(Project1Game game)
        {
            int max = (int)Math.Pow(2,game.scale)+1;

            Vector3 surfacenormal = new Vector3(0, 1, 0);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
                {
                    new VertexPositionNormalColor(new Vector3(0f, 0f, 0f), surfacenormal, Color.Blue), // Front FBLN
                    new VertexPositionNormalColor(new Vector3(0f, 0f, max), surfacenormal, Color.Blue), //FTLN
                    new VertexPositionNormalColor(new Vector3(max, 0f, max), surfacenormal, Color.Blue), //FTRN
                    new VertexPositionNormalColor(new Vector3(max, 0f, max), surfacenormal, Color.Blue), //FBLN
                    new VertexPositionNormalColor(new Vector3(max, 0f, 0f), surfacenormal, Color.Blue), //FTRN
                    new VertexPositionNormalColor(new Vector3(0f, 0f, 0f), surfacenormal, Color.Blue), //FBRN)
                });

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                LightingEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f),
                World = Matrix.Identity
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.gameaccess = game;
            this.game = game;
        }
Beispiel #6
0
		public void Draw(BasicEffect effect)
		{
			if (!_initialized)
				throw new InvalidOperationException("Initialize must be called before Draw");

			_device.SetVertexBuffer(_vertexBuffer);
			_device.SetIndexBuffer(_indexBuffer, false);

			effect.World = ConversionUtility.ToSharpDXMatrix(_sourceMesh.Transform.Value);
			effect.DiffuseColor = ConversionUtility.ToSharpDXVector3(_sourceMesh.Material.DiffuseColor);
			effect.SpecularColor = ConversionUtility.ToSharpDXVector3(_sourceMesh.Material.SpecularColor);
			effect.SpecularPower = _sourceMesh.Material.Shininess;

			if (!string.IsNullOrEmpty(_sourceMesh.Material.DiffuseTextureName))
			{
				effect.TextureEnabled = true;
				effect.Texture = _texture;
			}
			else
			{
				effect.TextureEnabled = false;
				effect.Texture = null;
			}

			effect.Alpha = _sourceMesh.Material.Transparency;

			foreach (var pass in effect.CurrentTechnique.Passes)
			{
				pass.Apply();
				_device.DrawIndexed(PrimitiveType.TriangleList, _sourceMesh.Indices.Count);
			}

			_device.SetIndexBuffer(null, false);
			_device.SetVertexBuffer((Buffer<VertexPositionNormalTexture>) null);
		}
        public Sphere(Model sphere,LabGame game)
        {
            this.game = game;
            model = sphere;
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Identity,
                //Texture = myModel.Texture,
                TextureEnabled = true,
                VertexColorEnabled = false
            };
            BasicEffect.EnableDefaultLighting(model,true);
            const float MaxModelSize = 10.0f;
            //var scaling = MaxModelSize / modelBounds.Radius;
            //var scaling = MaxModelSize / model.Meshes[0].BoundingSphere.Radius;
            modelBounds = model.CalculateBounds();
            view = Matrix.LookAtRH(new Vector3(0, 0, MaxModelSize * 2.5f), new Vector3(0, 0, 0), Vector3.UnitY);
            projection = Matrix.PerspectiveFovRH(0.9f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, MaxModelSize * 10.0f);
            world = Matrix.Translation(-modelBounds.Center.X, -modelBounds.Center.Y, -modelBounds.Center.Z)*Matrix.Scaling(1);
            basicEffect.View = game.camera.View;
            basicEffect.Projection = game.camera.Projection;
            //modelBounds = model.CalculateBounds();
            //pos = model.BoundingSphere.Center;
              //  pos = new Vector3(-model.BoundingSphere.Center.X,-model.BoundingSphere.Center.Y,-model.BoundingSphere.Center.Z);
            pos = new Vector3(0, 0, 0);
            //basicEffect.World = Matrix.Translation(pos);// * Matrix.Scaling(1f);
            //effect = game.Content.Load<Effect>("Phong");

            radius = model.Meshes[0].BoundingSphere.Radius;
            frictionConstant = 0.4f;
        }
        protected override void LoadContent()
        {
            // Instantiate a SpriteBatch
            spriteBatch = ToDisposeContent(new SpriteBatch(GraphicsDevice));

            // Loads a sprite font
            // The [Arial16.xml] file is defined with the build action [ToolkitFont] in the project
            arial16Font = Content.Load<SpriteFont>("Arial16");

            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice));
            basicEffect.DiffuseColor = Color.OrangeRed.ToVector4();
            basicEffect.PreferPerPixelLighting = true;
            basicEffect.EnableDefaultLighting();

            // Creates torus primitive
            sphere = ToDisposeContent(GeometricPrimitive.Sphere.New(GraphicsDevice, 1.75f));

            pixelTexture = Texture2D.New(GraphicsDevice, 1, 1, GraphicsDevice.BackBuffer.Format);
            pixelTexture.SetData<Color>(new Color[] { Color.Green });

            occlusionQuery = new OcclusionQuery(GraphicsDevice);

            offscreenBuffer = RenderTarget2D.New(GraphicsDevice, 128, 128, GraphicsDevice.BackBuffer.Format);

            base.LoadContent();
        }
        //builds the vertex list, assigns values for lighting and light rotation
        public Landscape(Game game, float rotationSpeed, int worldSize)
        {
            this.worldSize = worldSize;
            DiamondSquareGenerator();
            BuildVertexNormals();
            VertexPositionNormalColor[] vertexList = BuildVertexArray();
            vertices = Buffer.Vertex.New(game.GraphicsDevice, vertexList);
            this.rotationSpeed = rotationSpeed;

            zAngle = 0f;
            yAngle = (float)Math.PI;
            lightDirection = new Vector3(0f, (float)Math.Sin(yAngle), (float)Math.Cos(zAngle));
            specularColor = new Vector3(0.5f, 0.5f, 0.5f);
            diffuseColor = new Vector3(0.5f, 0.5f, 0.5f);
            ambientColor = new Vector3(0.1f, 0.1f, 0.1f);

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                LightingEnabled = true,
                PreferPerPixelLighting = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f,
                    (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World = Matrix.Identity
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Beispiel #10
0
        protected override void LoadContent()
        {
            // Creates a basic effect
            basicEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)
                {
                    VertexColorEnabled = true,
                    View = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY),
                    Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                    World = Matrix.Identity
                });

            // Creates vertices for the cube
            vertices = ToDisposeContent(Buffer.Vertex.New(
                GraphicsDevice,
                new[]
                    {
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.Orange), // Front
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.Orange), // BACK
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.OrangeRed), // Top
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.OrangeRed), // Bottom
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.DarkOrange), // Left
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.DarkOrange), // Right
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    }));
            ToDisposeContent(vertices);

            // Create an input layout from the vertices
            inputLayout = VertexInputLayout.FromBuffer(0, vertices);

            base.LoadContent();
        }
Beispiel #11
0
        void LoadContent()
        {
            m_basicEffect = ToDispose(new BasicEffect(this.GraphicsDevice));

            m_basicEffect.EnableDefaultLighting(); // enable default lightning, useful for quick prototyping
            m_basicEffect.TextureEnabled = true;   // enable texture drawing

            LoadCube();
        }
Beispiel #12
0
 public SkyBox(Project1Game game, Vector3 pos)
 {
     this.game = game;
     myModel = game.assets.GetModel("ship", CreateEnemyModel);
     //==================
     //type = GameObjectType.Enemy;
     this.pos = pos;
     basicEffect = GetParamsFromModel();
 }
Beispiel #13
0
        public Cube(Lab4Game game)
        {
            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
                    {
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.Orange), // Front
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.Orange), // BACK
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.Orange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.OrangeRed), // Top
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.OrangeRed), // Bottom
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.OrangeRed),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.DarkOrange), // Left
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.DarkOrange), // Right
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, 1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, -1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), Color.DarkOrange),
                        new VertexPositionColor(new Vector3(1.0f, 1.0f, 1.0f), Color.DarkOrange),
                    });

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, -10), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World = Matrix.Identity
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Beispiel #14
0
 protected override void LoadContent()
 {
     _mainPrimitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
     _mainBasicEffect = new BasicEffect(GraphicsDevice)
     {
         VertexColorEnabled = true,
         TextureEnabled = false,
         LightingEnabled = false
     };
     base.LoadContent();
 }
Beispiel #15
0
 public Cursor(ProjectGame game)
 {
     this.game = game;
     model = game.Content.Load<Model>("Cursor");
     basicEffect = new BasicEffect(game.GraphicsDevice)
     {
         World = Matrix.Identity,
         View = game.camera.View,
         Projection = game.camera.Projection
     };
     BasicEffect.EnableDefaultLighting(model, true);
 }
 public override void Initialize()
 {
     base.Initialize();
     this.Visible = true;
     basicEffect = new BasicEffect(game.GraphicsDevice)
     {
         VertexColorEnabled = true,
         View = game.camera.view,
         Projection = game.camera.projection,
         World = Matrix.Identity
     };
     basicEffect.VertexColorEnabled = true;
 }
Beispiel #17
0
        public override void LoadContent()
        {
            base.LoadContent();

            Model = Main.GameContent.Load<Model>(string.Format("Models/{0}", karts[rand.Next(0, 4)]));

            Effect = new BasicEffect(Main.Graphics.GraphicsDevice);
            Effect.LightingEnabled = true;
            Effect.DirectionalLight0.DiffuseColor = new Color(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255)).ToVector3();
            Effect.DirectionalLight0.Direction = new Vector3(1, 0, -1);
            Effect.DirectionalLight0.SpecularColor = new Vector3(1, 0, 0);

            completeCircuits = 0;
        }
        void LoadContent()
        {
            var device = this.GraphicsDevice;

            m_basicEffect = ToDispose(new BasicEffect(GraphicsDevice));

            m_basicEffect.TextureEnabled = true;
            m_basicEffect.Sampler = device.SamplerStates.PointClamp;

            LoadCube();

            var rdesc = device.RasterizerStates.Default.Description;
            rdesc.DepthBias = -10;
            m_rasterizerState = RasterizerState.New(device, rdesc);
        }
Beispiel #19
0
        // Constructor.
        public Explosion(Project1Game game)
        {
            this.game = game;
            this.SetBuffer();
            vertices = Buffer.Vertex.New(game.GraphicsDevice, colorBuffer);

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Identity,
                VertexColorEnabled = true
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
        }
Beispiel #20
0
        public CannonModel(Project1Game game)
        {
            model = game.Content.Load<Model>("Cannon");
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Scaling(0.0003f) * Matrix.Translation(game.x0, game.y0 + 0.05f,game.z0),
                VertexColorEnabled = true
            };

            BasicEffect.EnableDefaultLighting(model,true);
            inputLayout = VertexInputLayout.FromBuffer(0, vertices);

            this.game = game;
            pos = new SharpDX.Vector3(-0.8f, 0f, 0.8f);
        }
Beispiel #21
0
        public Landscape(Project1Game game, int level)
        {
            this.level = level;
            this.SetBuffer();
            vertices = Buffer.Vertex.New(game.GraphicsDevice, colorBuffer);
            setBoxBoundary();
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Identity,
                VertexColorEnabled = true
            };

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }
Beispiel #22
0
        public Tree(Project1Game game)
        {
            model = game.Content.Load<Model>("tree1a_lod0");
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,
                Projection = game.camera.Projection,
                World = Matrix.Scaling(0.003f),
                VertexColorEnabled = true
            };

            BasicEffect.EnableDefaultLighting(model,true);
            inputLayout = VertexInputLayout.FromBuffer(0, vertices);

            this.game = game;
            pos = new SharpDX.Vector3(0, 0, 0);
        }
Beispiel #23
0
        protected override void Initialize()
        {
            base.Initialize();

            IsMouseVisible = true;
            Window.Title = "Worms";
            Window.AllowUserResizing = true;

            // nastavení pohledu a projekce
            view = Matrix.LookAtLH(new Vector3(0, 0, 1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            projection = Matrix.OrthoLH(Width, Height, 1, 0);

            // vytvoření a nastavení effektu (aplikování pohledu a projekce)
            effect = new BasicEffect(GraphicsDevice);
            effect.World = Matrix.Identity;
            effect.View = view;
            effect.Projection = projection;
        }
Beispiel #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MiniTriRenderer" /> class.
        /// </summary>
        protected override void LoadContent()
        {
            // Creates a basic effect
            Utilities.Dispose(ref basicEffect);
            basicEffect = new BasicEffect(GraphicsDevice)
                              {
                                  VertexColorEnabled = true,
                                  View = Matrix.Identity,
                                  Projection = Matrix.Identity,
                                  World = Matrix.Identity
                              };

            // Creates primitive bag
            Utilities.Dispose(ref primitiveBatch);
            primitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);

            Window.AllowUserResizing = true;
        }
		public WarpSceneRenderer(Scene scene, int width, int height)
		{
			_scene = scene;
			_width = width;
			_height = height;
			_aspectRatio = width / (float)height;

			_device = GraphicsDevice.New(DriverType.Warp, DeviceCreationFlags.None, FeatureLevel.Level_10_1);

			var serviceProvider = new ServiceProvider();
			serviceProvider.AddService<IGraphicsDeviceService>(new GraphicsDeviceService(_device));

			_contentManager = new ContentManager(serviceProvider);
			_contentManager.Resolvers.Add(new ContentResolver());

			var viewport = new Viewport(0, 0, _width, _height);
			_device.SetViewports(viewport);

			const MSAALevel msaaLevel = MSAALevel.None;
			_depthStencilTexture = DepthStencilBuffer.New(_device, _width, _height, msaaLevel, DepthFormat.Depth24Stencil8);
			_renderTexture = RenderTarget2D.New(_device, _width, _height, msaaLevel, PixelFormat.R8G8B8A8.UNorm);

			Options = new RenderOptions();

			_effect = new BasicEffect(_device);
			_effect.EnableDefaultLighting();

			_inputLayout = VertexInputLayout.New(0, typeof(VertexPositionNormalTexture));
			_device.SetVertexInputLayout(_inputLayout);

			_meshes = new List<WarpMesh>();
			foreach (Mesh mesh in _scene.Meshes)
			{
				if (!mesh.Positions.Any())
					continue;

				var warpMesh = new WarpMesh(_device, mesh);
				_meshes.Add(warpMesh);

				warpMesh.Initialize(_contentManager);
			}
		}
Beispiel #26
0
        public Sphere(Model sphere,LabGame game)
        {
            this.game = game;
            model = sphere;
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.camera.View,

                //View = Matrix.LookAtRH(game.camera.pos, game.camera.pos+game.camera.pos_relative_to_player, Vector3.UnitY),
                Projection = game.camera.Projection,
                //Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.01f, 15000.0f),
                World = Matrix.Identity,
                //Texture = myModel.Texture,
                TextureEnabled = true,
                VertexColorEnabled = false
            };
            BasicEffect.EnableDefaultLighting(model,true);
            //const float MaxModelSize = 10.0f;
            //var scaling = MaxModelSize / modelBounds.Radius;
            //var scaling = MaxModelSize / model.Meshes[0].BoundingSphere.Radius;
            //modelBounds = model.CalculateBounds();
            //view = Matrix.LookAtRH(new Vector3(0, 0, MaxModelSize * 2.5f), new Vector3(0, 0, 0), Vector3.UnitY);
            //projection = Matrix.PerspectiveFovRH(0.9f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, MaxModelSize * 10.0f);
            //world = Matrix.Translation(-modelBounds.Center.X, -modelBounds.Center.Y, -modelBounds.Center.Z) * Matrix.Scaling(0.5f);
            //basicEffect.View = game.camera.View;
            //basicEffect.Projection = game.camera.Projection;
            //modelBounds = model.CalculateBounds();
            //pos = model.BoundingSphere.Center;
              //  pos = new Vector3(-model.BoundingSphere.Center.X,-model.BoundingSphere.Center.Y,-model.BoundingSphere.Center.Z);
            //pos = new Vector3(game.mazeLandscape.maze.startPoint.x, 3, game.mazeLandscape.maze.startPoint.y);
            pos = new Vector3(game.mazeLandscape.entranceX, 0, game.mazeLandscape.entranceZ);
            radius = model.CalculateBounds().Radius * scallingFactor + 0.6f;
            basicEffect.World = Matrix.Translation(new Vector3(model.CalculateBounds().Center.X,
                model.CalculateBounds().Center.Y, model.CalculateBounds().Center.Z)) * Matrix.Translation(pos);// * Matrix.Scaling(1f);
            effect = game.Content.Load<Effect>("modelShader");
            texture = game.Content.Load<Texture2D>("wood");

            //radius = model.Meshes[0].BoundingSphere.Radius * scallingFactor;

            frictionConstant = 0.03f;
        }
Beispiel #27
0
 public Canvas(int width, int height) {
    Width = width;
    Height = height;
    RenderTarget = RenderTarget2D.New(
       GraphicsDevice,
       width,
       height,
       Format.B8G8R8A8_UNorm);
    rasterizerState = RasterizerState.New(GraphicsDevice, new RasterizerStateDescription {
       CullMode = CullMode.None,
       FillMode = FillMode.Solid,
       IsAntialiasedLineEnabled = true,
       IsMultisampleEnabled = true
    });
    effect = new BasicEffect(GraphicsDevice) {
       World = Matrix.Identity,
       View = Matrix.Identity,
       Projection = Matrix.OrthoOffCenterLH(0, Width, 0, Height, 1.0f, 1000.0f),
       VertexColorEnabled = true
    };
 }
Beispiel #28
0
        // Constructor for the player as the shooter
        public Projectile(ProjectGame game, string model_name, Vector3 pos, float velocity, Enemy target, GameObjectType targetType)
        {
            this.game = game;
            this.pos = pos;
            this.velocity = velocity;
            this.target = target;
            this.targetType = targetType;
            hitRadius = 5;
            squareHitRadius = hitRadius * hitRadius;
            collisionRadius = squareHitRadius;
            scaling = 1.5f;

            model = game.Content.Load<Model>(model_name);
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                World = Matrix.Identity,
                View = game.camera.View,
                Projection = game.camera.Projection
            };
            BasicEffect.EnableDefaultLighting(model, true);
        }
Beispiel #29
0
 public Sun(Game game, float x, float yAngle, float zAngle, float sideLength, float rotationSpeed, float diameter)
 {
     this.rotationSpeed = rotationSpeed;
     this.x = x;
     this.yAngle = yAngle;
     this.zAngle = zAngle;
     this.sideLength = sideLength;
     this.diameter = diameter;
     this.projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f,
             (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f);
     basicEffect = new BasicEffect(game.GraphicsDevice)
     {
         VertexColorEnabled = true,
         LightingEnabled = false,
         PreferPerPixelLighting = true,
         View = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY),
         Projection = projection
     };
     this.game = game;
     BuildVertices();
 }
Beispiel #30
0
        public Ghost(GameController game)
        {
            this.game = game;
            color = new Color(new Vector3(124, 0, 0), 0.05f);
            size = 2;
            height = 0.5f;
            seek = 0;
            delay = 240;
            Spawn();
            speed = .05f;
            direction = new Vector3(game.player.pos.X - pos.X, 0, game.player.pos.Z - pos.Z);
            UpdateVertices();

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View = game.player.View,
                Projection = game.player.Projection,
                World = game.player.World,
                VertexColorEnabled = true
            };
        }