/// <summary> /// Load the graphics content. /// </summary> protected override void LoadContent() { //Set up the reference grid and sample camera grid = new SampleGrid(); grid.GridColor = Color.LimeGreen; grid.GridScale = 1.0f; grid.GridSize = 32; grid.LoadGraphicsContent(graphics.GraphicsDevice); camera = new SampleArcBallCamera( SampleArcBallCameraMode.RollConstrained); camera.Distance = 3; //orbit the camera so we're looking down the z=-1 axis //the acr-ball camera is traditionally oriented to look //at the "front" of an object camera.OrbitRight(MathHelper.Pi); //orbit up a bit for perspective camera.OrbitUp(.2f); sampleMeshes = new Model[5]; //load meshes sampleMeshes[0] = Content.Load <Model>("Cube"); sampleMeshes[1] = Content.Load <Model>("SphereHighPoly"); sampleMeshes[2] = Content.Load <Model>("SphereLowPoly"); sampleMeshes[3] = Content.Load <Model>("Cylinder"); sampleMeshes[4] = Content.Load <Model>("Cone"); //Example 1.2 //create the effect objects that correspond to the effect files //that have been imported via the Content Pipeline noLightingEffect = Content.Load <Effect>("FlatShaded"); vertexLightingEffect = Content.Load <Effect>("VertexLighting"); GetEffectParameters(); //Calculate the projection properties first on any //load callback. That way if the window gets resized, //the perspective matrix is updated accordingly float aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; float fov = MathHelper.PiOver4 * aspectRatio * 3 / 4; projection = Matrix.CreatePerspectiveFieldOfView(fov, aspectRatio, .1f, 1000f); //create a default world matrix world = Matrix.Identity; //grid requires a projection matrix to draw correctly grid.ProjectionMatrix = projection; //Set the grid to draw on the x/z plane around the origin grid.WorldMatrix = Matrix.Identity; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up the reference grid and sample camera grid = new SampleGrid { GridColor = Color.LimeGreen, GridScale = 10.0f, GridSize = 100 }; grid.LoadGraphicsContent(graphics.GraphicsDevice); // Create a new SpriteBatch, which can be used to draw textures. basicEffect = new BasicEffect(GraphicsDevice); metaballs = new Metaball[2]; metaballs[0] = new Metaball { CenterX = 60, CenterY = 60, CenterZ = 50, Radius = 40 }; metaballs[1] = new Metaball { CenterX = 130, CenterY = 60, CenterZ = 70, Radius = 40 }; // metaballs[2] = new Metaball { CenterX = 150, CenterY = 75, CenterZ = 100, Radius = 20 }; marchingCubeAlgorithm = new MarchingCubeAlgorithm(); vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), 3, BufferUsage.WriteOnly); //vertexBuffer.SetData<VertexPositionColor>(vertices); //grid requires a projection matrix to draw correctly grid.ProjectionMatrix = projection; //Set the grid to draw on the x/z plane around the origin grid.WorldMatrix = Matrix.Identity; RasterizerState rasterizerState = new RasterizerState(); rasterizerState.CullMode = CullMode.None; GraphicsDevice.RasterizerState = rasterizerState; basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.VertexColorEnabled = false; basicEffect.LightingEnabled = true; basicEffect.EnableDefaultLighting(); basicEffect.PreferPerPixelLighting = true; basicEffect.AmbientLightColor = new Vector3(0.2f, 0.1f, 0.7f); for (int z = 0; z < 50; z++) { for (int y = 0; y < 50; y++) { for (int x = 0; x < 50; x++) { var index = z * 50 * 50 + y * 50 + x; // Grid edge length var g = 5; gridCells[index] = new GridCell(); gridCells[index].point[0] = new Vector3(x * g, y * g, z * g); gridCells[index].point[1] = new Vector3(x * g + g, y * g, z * g); gridCells[index].point[2] = new Vector3(x * g + g, y * g, z * g + g); gridCells[index].point[3] = new Vector3(x * g, y * g, z * g + g); gridCells[index].point[4] = new Vector3(x * g, y * g + g, z * g); gridCells[index].point[5] = new Vector3(x * g + g, y * g + g, z * g); gridCells[index].point[6] = new Vector3(x * g + g, y * g + g, z * g + g); gridCells[index].point[7] = new Vector3(x * g, y * g + g, z * g + g); } } } }