예제 #1
0
        public void InitiateSave(Game1 game, Vector3 playerPosition, float playerSize, VertexMultitextured[] terrain, Vector3[] modelRotation, bool[] modelActivated, string filename)
        {
            this.playerPosition = playerPosition;
            this.playerSize = playerSize;
            this.terrain = terrain;
            this.modelRotation = modelRotation;
            this.modelActivated = modelActivated;

            #if WINDOWS
            FileStream fs = new FileStream("lastsave.txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            sw.WriteLine(filename);
            Console.WriteLine("Last save created with name: " + filename);

            sw.Close();
            fs.Close();
            #endif

            #if XBOX
            Save.GlobalData gd = new Save.GlobalData();
            gd.InitiateSave(game, filename, "global");
            #endif

            this.filename = filename + ".sav";
            try
            {
                device = null;
                StorageDevice.BeginShowSelector(SaveToDevice, null);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        private void CopyToTerrainBuffers(VertexMultitextured[] vertices, int[] indices)
        {
            terrainVertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexMultitextured), vertices.Length, BufferUsage.WriteOnly);
            terrainVertexBuffer.SetData(vertices);

            terrainIndexBuffer = new IndexBuffer(graphicsDevice, typeof(int), indices.Length, BufferUsage.WriteOnly);
            terrainIndexBuffer.SetData(indices);
        }
예제 #3
0
        private VertexMultitextured[] CalculateNormals(VertexMultitextured[] vertices, int[] indices)
        {
            //Set al the vertices on Normal 0 just to clear
            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal = new Vector3(0, 0, 0);

            //calculate the normal of each triangle
            for (int i = 0; i < indices.Length / 3; i++) {
                //The indices for the vertex on this i
                int index1 = indices[i * 3];
                int index2 = indices[i * 3 + 1];
                int index3 = indices[i * 3 + 2];

                //Calculates the sides of this triangle
                Vector3 side1 = vertices[index1].Position - vertices[index3].Position;
                Vector3 side2 = vertices[index1].Position - vertices[index2].Position;
                Vector3 normal = Vector3.Cross(side1, side2);

                vertices[index1].Normal += normal;
                vertices[index2].Normal += normal;
                vertices[index3].Normal += normal;
            }

            //Normalize the normals, so they don't have a huge vector
            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal.Normalize();

            return vertices;
        }