/// <summary> /// Initializes the billboard /// </summary> private void InitializeBillboard() { fBillboard = new DynamicBillboard(GraphicsDevice); fBillboard.Mode = BillboardMode.Quad; fBillboard.UseVertexBuffer = true; const float DISTANCE = 1000f; for (int x = -4; x <= 4; x++) { for (int y = -4; y <= 4; y++) { for (int z = -4; z <= 4; z++) { fBillboard.AddObject( new Vector3(DISTANCE * x, DISTANCE * y, DISTANCE * z), Color.White, 400f); } } } }
/// <summary> /// Draw particles /// </summary> private void RenderParticles() { Dictionary <Texture2D, DynamicBillboard> billboards = new Dictionary <Texture2D, DynamicBillboard>(); foreach (Particle particle in fParticles) { Texture2D texture = particle.Texture; if (texture == null) { SetParticleTexture(particle); texture = particle.Texture; } if (!billboards.ContainsKey(texture)) { billboards.Add(texture, new DynamicBillboard(GraphicsDevice)); } DynamicBillboard billboard = billboards[texture]; billboard.AddObject(particle.Position, Color.White, particle.Size); } //-------------------- GraphicsDevice.BlendState = fBlendState; GraphicsDevice.DepthStencilState = DepthStencilState.None; Matrix vp = fCamera.Camera.ViewMatrix * fCamera.Camera.ProjectionMatrix; fShader.Parameters["world"].SetValue(fCamera.Camera.WorldMatrix); fShader.Parameters["vp"].SetValue(vp); int i = 0; foreach (KeyValuePair <Texture2D, DynamicBillboard> kvp in billboards) { fShader.Parameters["particleTexture"].SetValue(kvp.Key); for (int ps = 0; ps < fShader.CurrentTechnique.Passes.Count; ps++) { fShader.CurrentTechnique.Passes[ps].Apply(); kvp.Value.Render(); } i++; } //-------------------- }
private void InitBillboard() { fBillboardChanged = false; if (fBillboard == null) { fBillboard = new DynamicBillboard(GraphicsDevice); } else { fBillboard.Clear(); } foreach (MyPoint point in fPoints) { Color color = Color.White; Vector3 direction = point.Direction; int r = (byte)(128 + 127 * direction.X); int g = (byte)(128 + 127 * direction.Y); int b = (byte)(128 + 127 * direction.Z); color = new Color(r, g, b, 255); fBillboard.AddObject(point.Position, color, point.Size); } }