public Particle(ParticleID pid, Real3 coordinate, float radius, string species) { this.pid = pid; this.coordinate = coordinate; this.radius = radius; this.species = species; }
private List <Particle> ReadCSV(string filepath) { FileInfo fi = new FileInfo(filepath); List <Particle> snapshot = new List <Particle>(); using (StreamReader sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)) { sr.ReadLine(); // Skip The Header Line while (!sr.EndOfStream) { var line = sr.ReadLine(); var values = line.Split(','); ParticleID pid = new ParticleID( System.Convert.ToInt32(values[5]), System.Convert.ToInt32(values[6])); Real3 coordinate = new Real3( System.Convert.ToSingle(values[0]), System.Convert.ToSingle(values[1]), System.Convert.ToSingle(values[2])); snapshot.Add(new Particle( pid, coordinate, /* radius = */ System.Convert.ToSingle(values[3]), /* species = */ values[4])); } } return(snapshot); }
public static void Spawn( ParticleID ID, //type of particle to spawn float X, float Y, //spawn x, y position float accX, float accY //initial x, y acceleration ) { Particle P = new Particle(); //setup P based on parameters P.X = X; P.preX = X; P.Y = Y; P.preY = Y; P.accX = accX; P.accY = accY; P.color = Color.White; P.color.A = 255; //pass ID P.Id = ID; //setup particle based on ID if (P.Id == ParticleID.Fire) { //fire starts red P.color = Color.White; } //save P to heap via marker data[lastActive] = P; lastActive++; //bound dead index to array size if (lastActive >= size) { lastActive = size - 1; } }
public void GenerateParticle(ParticleID iD, Vector3 worldPos, Quaternion rotation, float duration = -1.0f) { RaycastHit hit; int mask = 1 << inst_minimap.layerMask; if (Physics.Raycast(worldPos, Vector3.down, out hit, float.MaxValue, mask)) { Vector3 pos = hit.point; pos.y += 0.1f; //z-fighting GameObject generate = Instantiate(Particles[(int)iD], pos, rotation); if (duration > 0) { StartCoroutine("KillParticle", new object[2] { duration, generate }); } } }
public static void Spawn( ParticleID ID, //type of particle to spawn float X, float Y, //spawn x, y position float accX, float accY //initial x, y acceleration ) { //create a stack instance to work on Particle P = new Particle(); //setup P based on parameters P.physics.X = X; P.physics.preX = X; P.physics.Y = Y; P.physics.preY = Y; P.physics.accX = accX; P.physics.accY = accY; //set defaults for particle P.alpha = 1.0f; P.age = 0; P.color = Color.White; //pass the ID P.Id = ID; //setup particle based on ID if (P.Id == ParticleID.Fire) { //fire is red, for instance P.color = Color.Red; } else if (P.Id == ParticleID.Rain) { //rain is blue, this could be an animated sprite tho P.color = Color.Blue; } //find an inactive particle to copy data to int s = size; for (int i = 0; i < s; i++) { //read each struct once if (data[i].Id == ParticleID.Inactive) { //write local to heap once data[i] = P; active++; return; } //if all are active, } //fail silently/ignore }
public static void Spawn( ParticleID ID, //type of particle to spawn float X, float Y, //spawn x, y position float accX, float accY //initial x, y acceleration ) { Particle P = new Particle(); P.X = X; P.preX = X; P.Y = Y; P.preY = Y; P.accX = accX; P.accY = accY; P.color = Color.Black; //change color based on spawn pos //if (X < 1280 / 3) { P.color.R = 255; } //else if (X < (1280 / 3) * 2) { P.color.G = 255; } //else { P.color.B = 255; } //P.color.R = (byte)(X * 3); //P.color.G = (byte)(255 - Y); //P.color.B = (byte)(255 - X); //P.color.B = (byte)((X * 255) / 255); //add some randomness to blue channel P.color.B += (byte)Rand.Next(0, 100); P.color.R += (byte)Rand.Next(0, 100); P.color.G += (byte)Rand.Next(150, 255); P.Id = ID; //save P to heap data[lastActive] = P; lastActive++; //bound dead index to array size if (lastActive >= size) { lastActive = size - 1; } }
public static void Spawn( ParticleID ID, //type of particle to spawn float X, float Y, //spawn x, y position float accX, float accY //initial x, y acceleration ) { //create a stack instance to work on Particle P = new Particle(); //setup P based on parameters P.physics.X = X; P.physics.preX = X; P.physics.Y = Y; P.physics.preY = Y; P.physics.accX = accX; P.physics.accY = accY; //set defaults for particle P.alpha = 1.0f; P.age = 0; P.color = Color.White; //pass the ID P.Id = ID; //setup particle based on ID if (P.Id == ParticleID.Fire) { //fire is red, for instance P.color = Color.Red; } else if (P.Id == ParticleID.Rain) { //rain is blue, this could be an animated sprite tho P.color = Color.Blue; } //save P to heap via marker data[deadIndex] = P; deadIndex++; //bound dead index to array size if (deadIndex >= size) { deadIndex = size - 1; } }