// Use this for initialization void Start() { lineVertices = new Vector3[numParticles]; lineRenderer = GetComponent <UnityEngine.LineRenderer> (); lineRenderer.SetVertexCount(numParticles); lineRenderer.SetWidth(0.1f, 0.1f); var startPos = new Vec3(-3, 15, 0); var dx = new Vec3(-0.25, -0.25, 0); var mass = 1.0; for (int i = 0; i < numParticles; i++) { particles.Add(new Particle(startPos + i * dx, mass)); } particles [numParticles - 1].Mass = massOfLastParticle; List <Constraint> constraints = new List <Constraint> (); constraints.Add(new PositionConstraint(0, startPos, springK)); for (int i = 0; i < numParticles - 1; i++) { constraints.Add(new DistanceConstraint(i, i + 1, dx.Length, springK)); } particles.constraints = constraints; Engine.instance.Rope = particles; }
private void EmitParticles() { var t = Time.fixedTime; var elapsed = t - lastTime; if (elapsed >= 1 / rate) { var particlesToEmit = Mathf.CeilToInt(elapsed / (1 / rate)); float r = particleSize / 2; float mass = density * 4 * Mathf.PI * r * r * r / 3; for (var i = 0; i < particlesToEmit; i++) { // Add a random perturbation to initial position and velocity var initialVelocity = transform.forward + Random.onUnitSphere; var initialPosition = transform.position; var coords = Random.insideUnitCircle * radius; initialPosition += coords.x * transform.right + coords.y * transform.up; ps.Add(new PE.Particle(initialPosition, initialVelocity, mass, particleSize / 2, lifetime)); } lastTime = t; } }
public void Point_AABBTest() { PE.ParticleSystem ps = new PE.ParticleSystem(); ps.Add(new Particle(new PE.Vec3(0, 0.5, 0), new PE.Vec3(0, 0, 0), 0.0, 0, 0)); AABB aabb = new AABB(new Vec3(-1.0, -1.0, -1.0), new Vec3(1.0, 1.0, 1.0)); Assert.IsTrue(Collider.CheckIntersection(ps, aabb).Count != 0); }
public void Point_PlaneTest1() { PE.ParticleSystem ps = new PE.ParticleSystem(); ps.Add(new Particle(new PE.Vec3(1, 0, 2), new PE.Vec3(0, 0, 0), 0.0, 0, 0)); PlaneCollider pl1 = new PlaneCollider(new Entity(), new PE.Vec3(0, 0, 1), 1.0); Assert.IsFalse(Collider.CheckIntersection(ps, pl1).Count != 0); }