private Metaball CreateMetaball() { Metaball m = new Metaball { Position = new Vector2(rand.Next(GraphicsDevice.Viewport.Width), rand.Next(GraphicsDevice.Viewport.Height)), Texture = metaballTexture }; m.Initialize(rand.Next()); return(m); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); this.texture = new Texture2D(graphics.GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, false, SurfaceFormat.Color); this.data = new uint[graphics.PreferredBackBufferWidth * graphics.PreferredBackBufferHeight]; metaballs = new Metaball[3]; metaballs[0] = new Metaball { CenterX = 400, CenterY = 240, Radius = 40 }; metaballs[1] = new Metaball { CenterX = 300, CenterY = 150, Radius = 30 }; metaballs[2] = new Metaball { CenterX = 350, CenterY = 375, Radius = 20 }; }
/// <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); } } } }