public void Render(ParticleCamera camera, SamplerState samplerState) { _emitterSpriteBatchHandler.SetupAndStartSpriteBatch(_spriteBatch, camera, samplerState); foreach (var emitter in _emitters) { emitter.Render(camera, _spriteBatch); } _spriteBatch.End(); }
public InputHandler(EditorUiController uiController, ParticleCamera camera, SettingsCommandHandler commandHandler, AppOperationQueue appOperationQueue, ApplicationState applicationState) { _uiController = uiController; _camera = camera; _commandHandler = commandHandler; _appOperationQueue = appOperationQueue; _applicationState = applicationState; }
public void Render(ParticleCamera camera, SpriteBatch spriteBatch) { var particles = ParticleBuffer.Particles; for (var x = 0; x < particles.Length; x++) { ref var particle = ref particles[x]; if (particle.IsAlive) { var startX = particle.Position.X; var startY = camera.PositiveYAxisPointsUp ? -particle.Position.Y : particle.Position.Y; var destinationRectangle = new Rectangle((int)startX, (int)startY, (int)particle.Size.X, (int)particle.Size.Y); Rectangle sourceRectangle; if (EmitterLogic.TextureSections.Length == 0) { sourceRectangle = new Rectangle(0, 0, _texture.Width, _texture.Height); } else { ref var section = ref EmitterLogic.TextureSections[particle.TextureSectionIndex]; sourceRectangle = new Rectangle(section.LeftX, section.TopY, section.RightX - section.LeftX, section.BottomY - section.TopY); } var colorModifier = new Color((byte)particle.CurrentRed, (byte)particle.CurrentGreen, (byte)particle.CurrentBlue, (byte)particle.CurrentAlpha); spriteBatch.Draw(_texture, destinationRectangle, sourceRectangle, colorModifier, -particle.RotationInRadians, // CCW rotations new Vector2(sourceRectangle.Width / 2f, sourceRectangle.Height / 2f), SpriteEffects.None, 0f); }
public void SetupAndStartSpriteBatch(SpriteBatch spriteBatch, ParticleCamera camera, SamplerState samplerState) { var totalHorizontalZoomFactor = camera.HorizontalZoomFactor; var totalVerticalZoomFactor = camera.VerticalZoomFactor; _basicEffect.TextureEnabled = true; _basicEffect.LightingEnabled = false; _basicEffect.FogEnabled = false; _basicEffect.VertexColorEnabled = true; _basicEffect.World = Matrix.Identity; _basicEffect.Projection = Matrix.CreateOrthographic(camera.PixelWidth, -camera.PixelHeight, -1, 1); _basicEffect.View = Matrix.CreateTranslation( -camera.Origin.X, camera.Origin.Y, 0) * Matrix.CreateScale(totalHorizontalZoomFactor, totalVerticalZoomFactor, 1); spriteBatch.Begin(blendState: BlendState.NonPremultiplied, effect: _basicEffect, samplerState: samplerState); }
public void Render() { if (!isRunning) { return; } Device device = this.Host.Device; if (device == null) { return; } device.InputAssembler.InputLayout = this.ParticleLayout; device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip; ParticlePass.Apply(); device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(this.Particles, 32, 0)); ParticleProjection.Set(new Vector2(Host.Width, Host.Height)); ParticleCamera.Set(new Vector2(0, -PlayerShip.Instance.Position.Y)); device.Draw(ParticleManager.particleList.Count, 0); device.InputAssembler.InputLayout = this.ShapeLayout; device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip; ShapeCamera.Set(new Vector2(0, -PlayerShip.Instance.Position.Y)); ShapeProjection.Set(new Vector2(Host.Width, Host.Height)); foreach (Entity entity in EntityManager.Entities) { device.InputAssembler.SetVertexBuffers(0, entity.Shape.Buffer); ShapeColor.Set(entity.Color); ShapePosition.Set(new Vector3(entity.Position, entity.Orientation)); ShapePass.Apply(); device.Draw(entity.Shape.Vertices.Length * 2 + 2, 0); } if (Math.Abs(Profiles.Current.State.LinesPosition - PlayerShip.Instance.Position.Y) < Height) { device.InputAssembler.InputLayout = this.LineLayout; device.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList; device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(LineBuffer, 8, 0)); LineEffect.GetVariableByName("Step").AsScalar().Set(0.1f); LineEffect.GetVariableByName("Width").AsScalar().Set(2.0f / Width); LineEffect.GetVariableByName("Height").AsScalar().Set(1.0f - Math.Abs(Profiles.Current.State.LinesPosition - PlayerShip.Instance.Position.Y) / Height); LineEffect.GetVariableByName("Color").AsVector().Set(Color.Yellow); Vector4[] disturb = new Vector4[16]; float maxX = 0.05f, maxY = 0.02f; for (int i = 0; i < linesCount; i++) { for (int k = 0; k < 16; k++) { disturb[k] = new Vector4(Rand.NextFloat(-maxX, maxX), Rand.NextFloat(-maxY, maxY), Rand.NextFloat(-maxX, maxX), Rand.NextFloat(-maxY, maxY)); } LineEffect.GetVariableByName("Disturb").AsVector().Set(disturb); LineEffect.GetTechniqueByIndex(0).GetPassByIndex(0).Apply(); device.Draw(1, i); } } }