Пример #1
0
 public MyModel(Project1Game game, VertexPositionColor[] shapeArray, String textureName)
 {
     this.vertices = Buffer.Vertex.New(game.GraphicsDevice, shapeArray);
     this.inputLayout = VertexInputLayout.New<VertexPositionColor>(0);
     vertexStride = Utilities.SizeOf<VertexPositionColor>();
     modelType = ModelType.Colored;
 }
Пример #2
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;
        }
Пример #3
0
        private Project1Game gameaccess;                //Access to public game functions

        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;
        }
Пример #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;
        }
Пример #5
0
 // Ensures that all objects are being rendered from a consistent viewpoint
 public Camera(Project1Game game)
 {
     position   = new Vector3(0, game.getHeight(0, 0) + 5, -10);
     target     = new Vector3(0, 0, 0);
     up         = Vector3.UnitY;
     View       = Matrix.LookAtLH(position, target, up);
     Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, (float)Math.Pow(2, game.scale) + 1);
     this.game  = game;
 }
Пример #6
0
 public SkyBox(Project1Game game, Vector3 pos)
 {
     this.game = game;
     myModel = game.assets.GetModel("ship", CreateEnemyModel);
     //==================
     //type = GameObjectType.Enemy;
     this.pos = pos;
     basicEffect = GetParamsFromModel();
 }
Пример #7
0
 // Ensures that all objects are being rendered from a consistent viewpoint
 public Camera(Project1Game game)
 {
     position = new Vector3(0, game.getHeight(0,0)+5, -10);
     target = new Vector3(0, 0, 0);
     up = Vector3.UnitY;
     View = Matrix.LookAtLH(position, target, up);
     Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, (float)Math.Pow(2, game.scale) + 1);
     this.game = game;
 }
Пример #8
0
 public MainPage()
 {
     InitializeComponent();
     game = new Project1Game(this);
     game.Run(this);
     txtScore.Visibility = Visibility.Collapsed;
     scoreLabel.Visibility = Visibility.Collapsed;
     hideLaunchControls();
 }
Пример #9
0
        public Camera(Vector3 eye, Vector3 Target, Vector3 Up, Project1Game game)
        {
            this.eye       = eye;
            this.target    = Target;
            this.up        = Up;
            this.reference = new Vector3(0, 0, 1);

            this.pitch = 0;
            this.yaw   = 0;

            this.game = game;
        }
Пример #10
0
 public Camera(Project1Game game)
 {
     currentMouseState = game.mouseState;
     rotateLeftRight   = 0;
     rotateUpDown      = 0;
     viewDir           = ORIGINALDIR;
     pos        = new Vector3(1, Landscape.MAXSEED + 1, 1);
     viewPoint  = pos + viewDir;
     up         = Vector3.UnitY;
     View       = Matrix.LookAtLH(pos, viewPoint, up);
     Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f);
     this.game  = game;
 }
        // Ensures that all objects are being rendered from a consistent viewpoint
        public Camera(Project1Game game)
        {
            // position of the camera
            this.Position = new Vector3(0, 10, -10);
            // where the camera is looking at
            this.LookAt = new Vector3(0, 10, 10);
            // where the upside of the camera is facing
            this.Up =  Vector3.UnitY;

            View = Matrix.LookAtLH(this.Position, this.Position+this.LookAt, this.Up);
            Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f);
            this.game = game;
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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;
        }
Пример #16
0
 static void Main()
 {
     using (var program = new Project1Game())
         program.Run();
 }
Пример #17
0
        public Landscape(Project1Game game)
        {
            this.game = game;
            // Create the height map and vertex norms
            heightMap   = createRandomMap();
            vertexNorms = calcNorms();

            // Set the array to hold all the vertices
            VertexPositionNormalColor[] pointList = new VertexPositionNormalColor[6 * (LENGTH - 1) * (LENGTH - 1) + 6];
            int counter = 0;

            for (int x = 0; x < LENGTH - 1; x++)
            {
                for (int y = 1; y < LENGTH; y++)
                {
                    // Taking a point (x,y) from the height map it draws the square with the corners (x,y) (x+1,y) (x+1,y+1) and (x+1,y)
                    Vector3 pointA = new Vector3(x, heightMap[x, y - 1], y - 1);
                    pointList[counter] = new VertexPositionNormalColor(pointA, vertexNorms[x, y - 1], chooseColor(heightMap[x, y - 1]));
                    counter++;
                    Vector3 pointB = new Vector3(x, heightMap[x, y], y);
                    pointList[counter] = new VertexPositionNormalColor(pointB, vertexNorms[x, y], chooseColor(heightMap[x, y]));
                    counter++;
                    Vector3 pointC = new Vector3(x + 1, heightMap[x + 1, y], y);
                    pointList[counter] = new VertexPositionNormalColor(pointC, vertexNorms[x + 1, y], chooseColor(heightMap[x + 1, y]));
                    counter++;
                    Vector3 pointD = new Vector3(x, heightMap[x, y - 1], y - 1);
                    pointList[counter] = new VertexPositionNormalColor(pointD, vertexNorms[x, y - 1], chooseColor(heightMap[x, y - 1]));
                    counter++;
                    Vector3 pointE = new Vector3(x + 1, heightMap[x + 1, y], y);
                    pointList[counter] = new VertexPositionNormalColor(pointE, vertexNorms[x + 1, y], chooseColor(heightMap[x + 1, y]));
                    counter++;
                    Vector3 pointF = new Vector3(x + 1, heightMap[x + 1, y - 1], y - 1);
                    pointList[counter] = new VertexPositionNormalColor(pointF, vertexNorms[x + 1, y - 1], chooseColor(heightMap[x + 1, y - 1]));
                    counter++;
                }
            }

            // Adds a plane of water which we will make sea level eg. y=0
            Color   water   = new Color(new Vector3(0, 0, 50), TRANSPARENCY);
            Vector3 wpointA = new Vector3(-0.1f, -0.1f, -0.1f);

            pointList[counter] = new VertexPositionNormalColor(wpointA, Vector3.Down, water);
            counter++;
            Vector3 wpointB = new Vector3(-0.1f, -0.1f, LENGTH - 0.9f);

            pointList[counter] = new VertexPositionNormalColor(wpointB, Vector3.Down, water);
            counter++;
            Vector3 wpointC = new Vector3(LENGTH - 0.9f, -0.1f, LENGTH - 0.9f);

            pointList[counter] = new VertexPositionNormalColor(wpointC, Vector3.Down, water);
            counter++;
            Vector3 wpointD = new Vector3(-0.1f, -0.1f, -0.1f);

            pointList[counter] = new VertexPositionNormalColor(wpointD, Vector3.Down, water);
            counter++;
            Vector3 wpointE = new Vector3(LENGTH - 0.9f, -0.1f, LENGTH - 0.9f);

            pointList[counter] = new VertexPositionNormalColor(wpointE, Vector3.Down, water);
            counter++;
            Vector3 wpointF = new Vector3(LENGTH - 0.9f, -0.1f, -0.1f);

            pointList[counter] = new VertexPositionNormalColor(wpointF, Vector3.Down, water);
            counter++;

            // Add the vertices to the landscape
            vertices = Buffer.Vertex.New(game.GraphicsDevice, pointList);

            // Set the lighting of the landscape
            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                View               = game.camera.View,
                Projection         = game.camera.Projection,
                VertexColorEnabled = true,
                World              = Matrix.Identity,
                LightingEnabled    = true,
                AmbientLightColor  = new Vector3(0.1f, 0.1f, 0.1f),
            };
            basicEffect.DirectionalLight0.Enabled       = true;
            basicEffect.DirectionalLight0.Direction     = Vector3.Right;
            basicEffect.DirectionalLight0.DiffuseColor  = new Vector3(0.1f, 0.1f, 0.1f);
            basicEffect.DirectionalLight0.SpecularColor = new Vector3(1.0f, 1.0f, 1.0f);

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
        }
Пример #18
0
 // Constructor.
 public SkyBoxController(Project1Game game)
 {
     this.game = game;
     skybox = new SkyBox(game, new Vector3(0, 0, 0));
     this.game.Add(skybox);
 }
Пример #19
0
        public Sun(Project1Game game)
        {
            worldsize = (int)Math.Pow(2, game.scale) + 1;

            ambientcolour     = new Vector3(0.2f, 0.2f, 0.2f);
            directionalcolour = new Vector3(0, 0, 0);
            specularcolour    = new Vector3(0, 0, 0);
            lightdirection    = new Vector3(0, 0, 0);
            diffusecolour     = new Vector3(0, 0, 0);


            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);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
            {
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow),     // Front
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), backNormal, Color.Yellow),     // BACK
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), backNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), backNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), topNormal, Color.Yellow),     // Top
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), topNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), topNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), bottomNormal, Color.Yellow),     // Bottom
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), bottomNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), bottomNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), leftNormal, Color.Yellow),     // Left
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), leftNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), leftNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), leftNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), leftNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), leftNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), rightNormal, Color.Yellow),     // Right
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), rightNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), rightNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), rightNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), rightNormal, Color.Yellow),
                new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), rightNormal, Color.Yellow),
            });

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                LightingEnabled    = true,
                View       = Matrix.LookAtLH(new Vector3(0, 0, 0), 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.game   = game;
        }
        public Landscape(Project1Game game, float c1, float c2, float c3, float c4, int recDepth)
        {
            // setting up the random number generator
            this.rand = new Random();

            // recDepth of 0 would make a flat plane with only the 4 corner vertices
            // Determine the size of the array depending of the recursion depth
            this.arraySize = this.compArraySize(recDepth);
            this.recDepth  = recDepth;

            // Creating array structure in order to store height values for all vertices
            // format will be heightMap[x][y] = z
            heightMap = new float[arraySize][];

            for (int i = 0; i < arraySize; i++)
            {
                heightMap[i] = new float[arraySize];
            }

            // corner pattern:
            //   C1-----C2
            //   |		|
            //   C3-----C4

            // set the four corner values
            heightMap[0][0]                         = c1;
            heightMap[arraySize - 1][0]             = c2;
            heightMap[0][arraySize - 1]             = c3;
            heightMap[arraySize - 1][arraySize - 1] = c4;

            // Generate the rest of the height values
            diamondsquare();

            // Calculate vertex colour heights
            calcColourZones();



            vertexArray = new VertexPositionNormalColor[(arraySize - 1) * (6 + (arraySize - 2) * 6) + 6];

            vertexCount = 0;
            // Add the vertices to the array to make polygons
            for (int y = 0; y <= arraySize - 2; y++)
            {
                for (int x = 0; x <= arraySize - 1; x++)
                {
                    if (x == 0)
                    {
                        addPolygon(
                            new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                            new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale),
                            new Vector3((x + 1) * positionScale, heightMap[x + 1][y], y * positionScale)
                            );
                    }
                    else if (x == arraySize - 1)
                    {
                        addPolygon(
                            new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                            new Vector3((x - 1) * positionScale, heightMap[x - 1][y + 1], (y + 1) * positionScale),
                            new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale)
                            );
                    }
                    else
                    {
                        addPolygon(
                            new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                            new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale),
                            new Vector3((x + 1) * positionScale, heightMap[x + 1][y], y * positionScale)
                            );


                        addPolygon(
                            new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                            new Vector3((x - 1) * positionScale, heightMap[x - 1][y + 1], (y + 1) * positionScale),
                            new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale)
                            );
                    }
                }
            }

            // these vertices are for the water
            // TODO add water vertices
            Color water = new Color(new Vector4(0, 0, 255, 0.5f));

            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, 0), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, 0), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, 0), Vector3.UnitY, water);

            vertices = Buffer.Vertex.New(

                game.GraphicsDevice,
                vertexArray
                );

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                Projection         = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 10000.0f),
                World           = Matrix.Identity,
                LightingEnabled = true
            };

            basicEffect.DirectionalLight0.Enabled   = true;
            basicEffect.DirectionalLight0.Direction = new Vector3((float)Math.Cos(0),
                                                                  (float)Math.Sin(0),
                                                                  (float)Math.Cos(0));
            basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.3f, 0.3f, 0.3f);
            basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);
            basicEffect.EmissiveColor     = new Vector3(0.5f, 0.5f, 0.5f);

            basicEffect.SpecularColor = new Vector3(0.3f, 0.5f, 0.5f);
            basicEffect.SpecularPower = 1f;


            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game   = game;
        }
Пример #21
0
        public Sun(Project1Game game)
        {
            worldsize = (int)Math.Pow(2, game.scale) + 1;

            ambientcolour = new Vector3(0.2f, 0.2f, 0.2f);
            directionalcolour = new Vector3(0, 0, 0);
            specularcolour = new Vector3(0,0,0);
            lightdirection = new Vector3(0, 0, 0);
            diffusecolour = new Vector3(0, 0, 0);

            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);

            vertices = Buffer.Vertex.New(
                game.GraphicsDevice,
                new[]
                {
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow), // Front
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), frontNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), frontNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), backNormal, Color.Yellow), // BACK
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), backNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), backNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), backNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), topNormal, Color.Yellow), // Top
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), topNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), topNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), topNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), bottomNormal, Color.Yellow), // Bottom
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f),bottomNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), bottomNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), bottomNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), leftNormal, Color.Yellow), // Left
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, 4.0f), leftNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), leftNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, -4.0f, -4.0f), leftNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, 4.0f), leftNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(-4.0f, 4.0f, -4.0f), leftNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), rightNormal, Color.Yellow), // Right
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), rightNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, 4.0f), rightNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, -4.0f, -4.0f), rightNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, -4.0f), rightNormal, Color.Yellow),
                    new VertexPositionNormalColor(new Vector3(4.0f, 4.0f, 4.0f), rightNormal, Color.Yellow),
                });

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                LightingEnabled = true,
                View = Matrix.LookAtLH(new Vector3(0, 0, 0), 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.game = game;
        }
Пример #22
0
 static void Main()
 {
     using (var program = new Project1Game())
         program.Run();
 }
Пример #23
0
 public Assets(Project1Game game)
 {
     this.game = game;
 }
        public Landscape(Project1Game game, float c1, float c2, float c3, float c4, int recDepth)
        {
            // setting up the random number generator
            this.rand = new Random();

            // recDepth of 0 would make a flat plane with only the 4 corner vertices
            // Determine the size of the array depending of the recursion depth
            this.arraySize = this.compArraySize(recDepth);
            this.recDepth = recDepth;

            // Creating array structure in order to store height values for all vertices
            // format will be heightMap[x][y] = z
            heightMap = new float[arraySize][];

            for (int i = 0; i < arraySize; i++){

                heightMap[i] = new float[arraySize];

            }

            // corner pattern:
            //   C1-----C2
            //   |		|
            //   C3-----C4

            // set the four corner values
            heightMap[0][0]                         = c1;
            heightMap[arraySize - 1][0]             = c2;
            heightMap[0][arraySize - 1]             = c3;
            heightMap[arraySize - 1][arraySize - 1] = c4;

            // Generate the rest of the height values
            diamondsquare();

            // Calculate vertex colour heights
            calcColourZones();

            vertexArray = new VertexPositionNormalColor[(arraySize - 1) * (6 + (arraySize - 2) * 6) + 6];

            vertexCount = 0;
            // Add the vertices to the array to make polygons
            for (int y = 0; y <= arraySize - 2; y++)
            {
                for (int x = 0; x <= arraySize - 1; x++)
                {

                    if (x == 0)
                    {

                        addPolygon(
                                   new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                                   new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale),
                                   new Vector3((x + 1) * positionScale, heightMap[x + 1][y], y * positionScale)
                                   );

                    }
                    else if (x == arraySize - 1)
                    {

                        addPolygon(
                                   new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                                   new Vector3((x - 1) * positionScale, heightMap[x - 1][y + 1], (y + 1) * positionScale),
                                   new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale)
                                   );

                    }
                    else
                    {
                        addPolygon(
                                   new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                                   new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale),
                                   new Vector3((x + 1) * positionScale, heightMap[x + 1][y], y * positionScale)
                            );

                        addPolygon(
                                   new Vector3(x * positionScale, heightMap[x][y], y * positionScale),
                                   new Vector3((x - 1) * positionScale, heightMap[x - 1][y + 1], (y + 1) * positionScale),
                                   new Vector3(x * positionScale, heightMap[x][y + 1], (y + 1) * positionScale)
                            );

                    }
                }
            }

            // these vertices are for the water
            // TODO add water vertices
            Color water = new Color(new Vector4(0, 0, 255, 0.5f));
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, 0), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(0, this.water, 0), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, arraySize * positionScale), Vector3.UnitY, water);
            vertexArray[vertexCount++] = new VertexPositionNormalColor(new Vector3(arraySize * positionScale, this.water, 0), Vector3.UnitY, water);

            vertices = Buffer.Vertex.New(

                    game.GraphicsDevice,
                    vertexArray
                    );

            basicEffect = new BasicEffect(game.GraphicsDevice)
            {
                VertexColorEnabled = true,
                Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 10000.0f),
                World = Matrix.Identity,
                LightingEnabled = true

            };

            basicEffect.DirectionalLight0.Enabled = true;
            basicEffect.DirectionalLight0.Direction = new Vector3((float)Math.Cos(0),
                                                                  (float)Math.Sin(0),
                                                                  (float)Math.Cos(0));
            basicEffect.DirectionalLight0.DiffuseColor = new Vector3(0.3f, 0.3f, 0.3f);
            basicEffect.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f);
            basicEffect.EmissiveColor = new Vector3(0.5f, 0.5f, 0.5f);

            basicEffect.SpecularColor = new Vector3(0.3f, 0.5f, 0.5f);
            basicEffect.SpecularPower = 1f;

            inputLayout = VertexInputLayout.FromBuffer(0, vertices);
            this.game = game;
        }