private void Load() { linevx1 = new VertexPositionTexture[width * height]; linevx2 = new VertexPositionTexture[width * height]; float fwidth = width; float fheight = height; int j = 0; for (int y = 0; y > -height; y -= 1) { for (int x = 0; x < width; x += 1) { float fx = x / fwidth; float fy = -y / fheight; //float index = (float)(x + -y * width); Vector2 indexv = new Vector2(fx, fy); float v = pack(indexv); if (j < width*height) { linevx1[j] = new VertexPositionTexture(new Vector3((x + 0.01f) / fwidth, y / fheight, v), indexv); j++; linevx1[j] = new VertexPositionTexture(new Vector3((x - 0.01f) / fwidth, y / fheight, v), indexv); j++; } else { linevx2[j - width * height] = new VertexPositionTexture(new Vector3((x + 0.01f) / fwidth, y / fheight, v), indexv); j++; linevx2[j - width * height] = new VertexPositionTexture(new Vector3((x - 0.01f) / fwidth, y / fheight, v), indexv); j++; } } } vertexBuffer1 = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, linevx1.Length, BufferUsage.WriteOnly); vertexBuffer1.SetData(linevx1); vertexBuffer2 = new VertexBuffer(device, VertexPositionTexture.VertexDeclaration, linevx2.Length, BufferUsage.WriteOnly); vertexBuffer2.SetData(linevx2); Camera camera = new Camera(device.Viewport, 1, 1); camera.Position = new Vector3((float)0.5, -(float)0.5, 1); camera.LookAt = new Vector3((float)0.5, -(float)0.5, 0); camera.Update(); effect = content.Load<Effect>(@"effects\delete_indexes"); effect.Parameters["world"].SetValue(Matrix.Identity); effect.Parameters["view"].SetValue(camera.ViewMatrix); effect.Parameters["projection"].SetValue(camera.ProjectionMatrix); effect.CurrentTechnique = effect.Techniques["Delete"]; effect2 = content.Load<Effect>(@"effects\adjust_from_index"); effect2.Parameters["world"].SetValue(Matrix.Identity); effect2.Parameters["view"].SetValue(camera.ViewMatrix); effect2.Parameters["projection"].SetValue(camera.ProjectionMatrix); effect2.CurrentTechnique = effect2.Techniques["Offset"]; }
private void loadContent() { sprite = new SpriteBatch(Device); camera = new Camera(Device.Viewport, 1, 1); camera.Position = new Vector3((float)0.5, -(float)0.5, 1); camera.LookAt = new Vector3((float)0.5, -(float)0.5, 0); camera.Update(); renderTarget = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Vector4, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); renderTarget2 = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Vector4, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents); effect.Parameters["world"].SetValue(Matrix.Identity); effect.Parameters["view"].SetValue(camera.ViewMatrix); effect.Parameters["projection"].SetValue(camera.ProjectionMatrix); }
protected override void LoadContent() { int bodyTextureWidth = 16; int bodyTextureHeight = 16; int particleTextureWidth = 512; int particleTextureHeight = 512; //int particleTextureWidth = 512; int particleTextureHeight = 512; //int spatialHashWidth = 128; int spatialHashHeight = 128; //int spatialHashWidth = 256; int spatialHashHeight = 256; int spatialHashWidth = 512; int spatialHashHeight = 512; int bucketWidth = 12; int bucketHeight = 12; //Vector2 worldSize = new Vector2(12, 12); //Vector2 worldPosition = new Vector2(-6, -6); //Vector2 worldSize = new Vector2(60, 40); //Vector2 worldPosition = new Vector2(-30, -20); Vector2 worldSize = new Vector2(66, 40); Vector2 worldPosition = new Vector2(-33, -20); Vector3 globalWorldSize, globalWorldPosition; stopwatch = new Stopwatch(); globalWorldPosition = new Vector3(worldPosition.X, worldPosition.Y, 0); globalWorldSize = new Vector3(worldSize.X, worldSize.Y, 1); bucketWidth = (int)(worldSize.X / particleStep); bucketHeight = (int)(worldSize.Y / particleStep); Console.WriteLine(bucketWidth + "," + bucketHeight); device = GraphicsDevice; spriteBatch = new SpriteBatch(GraphicsDevice); //if (first) printData(); camera = new Camera(device.Viewport, 1, 1); camera.Position = new Vector3(0.5f, -0.5f, 1); camera.LookAt = new Vector3(0.5f, -0.5f, 0); camera.Update(); camera2 = new Camera(device.Viewport, worldSize.X / 2, worldSize.Y / 2); camera2.LookAt = new Vector3(0, 0, 0); camera2.Position = new Vector3(0, 0, 1); camera2.Update(); font1 = Content.Load<SpriteFont>(@"fonts\MyFont"); stopwatch.Start(); gpucd = new GPUCollisionDetection(device, Content, particleDiameter, new TextureDimension2D(bodyTextureWidth, bodyTextureHeight), new TextureDimension2D(particleTextureWidth, particleTextureHeight), new TextureDimension2D(spatialHashWidth, spatialHashHeight), globalWorldSize, globalWorldPosition, new TextureDimension3D(bucketWidth, bucketHeight, 1)); interestingWorldGPUcd(); //interestingWorldGPUcd2(); //interestingWorldGPUcd3(); //fluids(); //fluidBoxes(0.25f); //fluidBoxes(0.375f); gpucd.setBuffers(); //gpucd.spatialHash.setBuffersComplete(); gpucd.deleteObject(0); //gpucd.deleteObject(1); rt = new RenderTarget2D(device, gpucd.bodyLinearMomentum.Width, gpucd.bodyLinearMomentum.Height, false, SurfaceFormat.Vector4, DepthFormat.None); sw2 = new Stopwatch(); sw.Start(); sw2.Start(); cycles2 = 0; }
private void loadContent() { sprite = new SpriteBatch(Device); camera = new Camera(Device.Viewport, 1, 1); camera.Position = new Vector3((float)0.5, -(float)0.5, 1); camera.LookAt = new Vector3((float)0.5, -(float)0.5, 0); camera.Update(); vertexBuffer = new VertexBuffer(Device, VertexPositionTexture.VertexDeclaration, linevtc1.Length, BufferUsage.WriteOnly); vertexBuffer.SetData(linevtc1); vertexBuffer2 = new VertexBuffer(Device, VertexPositionTexture.VertexDeclaration, linevtc2.Length, BufferUsage.WriteOnly); vertexBuffer2.SetData(linevtc2); renderTarget = new RenderTarget2D(Device, width, height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8); effect.Parameters["world"].SetValue(Matrix.Identity); effect.Parameters["view"].SetValue(camera.ViewMatrix); effect.Parameters["projection"].SetValue(camera.ProjectionMatrix); }