-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystem.cs
More file actions
55 lines (49 loc) · 1.84 KB
/
ParticleSystem.cs
File metadata and controls
55 lines (49 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using OpenTK;
using OpenTK.Graphics.OpenGL;
using System;
using System.Collections.Generic;
namespace SuperJet
{
public class ParticleSystem
{
private List<Particle> particles;
private Random random;
public ParticleSystem()
{
particles = new List<Particle>();
random = new Random();
}
public void Emit(int count)
{
for(int i = 0; i < count; i++)
{
var position = new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), 0);
var velocity = new Vector3((float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), 0);
var color = new Vector3(1.0f, (float)random.NextDouble(), (float)random.NextDouble());
var life = 1.0f;
particles.Add(new Particle(position, velocity, color, life));
}
}
public void Update(float deltaTime)
{
particles.RemoveAll(p => p.Life <= 0);
foreach(var particle in particles)
{
particle.Update(deltaTime);
}
}
public void Render()
{
foreach(var particle in particles)
{
GL.Color3(particle.Color.X, particle.Color.Y, particle.Color.Z);
GL.Begin(PrimitiveType.Quads);
GL.Vertex3(particle.Position.X - 0.01f, particle.Position.Y - 0.01f, 0);
GL.Vertex3(particle.Position.X + 0.01f, particle.Position.Y - 0.01f, 0);
GL.Vertex3(particle.Position.X + 0.01f, particle.Position.Y + 0.01f, 0);
GL.Vertex3(particle.Position.X - 0.01f, particle.Position.Y + 0.01f, 0);
GL.End();
}
}
}
}