private void boundary(Particle particle) { Vector positionInBoundary = particle.getPosition().clone(); Vector velocityInBoundary = particle.getVelocity().clone(); /* der lantern renderer verändert die übergebenen winkel, somit muss ich hier schauen, dass auch die auslenkung wieder ausgleiche. */ if (positionInBoundary.x < -(BOUNDARY * 0.5f)) { positionInBoundary.x = -(BOUNDARY * 0.5f); velocityInBoundary.x *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.x > (BOUNDARY * 0.5f)) { positionInBoundary.x = (BOUNDARY * 0.5f); velocityInBoundary.x *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.y < -(BOUNDARY * 0.5f)) { positionInBoundary.y = -(BOUNDARY * 0.5f); velocityInBoundary.y *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.y > (BOUNDARY * 1.8)) { positionInBoundary.y = (BOUNDARY * 1.8f); velocityInBoundary.y *= -BUMP_DECELERATION; // reverse and damp } particle.setPosition(positionInBoundary); particle.setVelocity(velocityInBoundary); }
/** * Adds the given edge to those to be displayed in the viewer. Note that the edge must connect * nodes that have already been added to the viewer. This version will use the locations of the * two nodes to calculate their distance of separation. * * @param edge Edge to add to the display. * @return True if edge was added successfully. False if edge contains nodes that have not been * added to the viewer. */ public boolean addEdge(E edge) { Particle p1 = nodes.get(edge.getNode1()); if (p1 == null) { System.err.println("Warning: Node1 not found when creating edge."); return false; } Particle p2 = nodes.get(edge.getNode2()); if (p2 == null) { System.err.println("Warning: Node2 not found when creating edge."); return false; } // Only add edge if it does not already exist in the collection if (!edges.containsKey(edge)) { float x1 = p1.position().x(); float y1 = p1.position().y(); float x2 = p2.position().x(); float y2 = p2.position().y(); // Strength, damping, reset length edges.put( edge, physics.makeSpring( p1, p2, EDGE_STRENGTH, DAMPING, (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)))); } return true; }
public void update(float delta) { for (Particle particle : particles) { if (particle.active) { particle.update(delta); } } }
@Override public void draw(SpriteBatch spriteBatch) { delta = Math.min(0.06f, Gdx.graphics.getDeltaTime()); this.setOrigin(0, 0); for (int i = particles.size - 1; i >= 0; i--) { Particle particle = particles.get(i); if (particle.life > 0) { updateParticle(particle); float dx = this.getWidth() / 2 * particle.scale; float dy = this.getHeight() / 2 * particle.scale; this.setColor(1, 1, 1, Math.max(particle.life / this.life, 0)); this.setScale(particle.scale); this.setPosition(particle.position.x - dx, particle.position.y - dy); if (!(particle.position.y - dy >= -10 && particle.position.y - dy <= 10) && !(particle.position.x - dx >= -10 && particle.position.x - dx <= 10)) { super.draw(spriteBatch); } else { particle.life = 0; } } else { particles.removeIndex(i); freeParticles.free(particle); } } }
/*loops through particles and calls the MCC algorith for each*/ void CollideParticles() { Iterator iterator = particles.iterator(); while (iterator.hasNext()) { Particle part = (Particle) iterator.next(); part.collideMCC(dt); } }
private void integrate(float time) { for (int i = 0; i < modifers.size(); i++) { modifers.get(i).update(); } RigidBody obj; for (int i = 0; i < physObjs.size(); i++) { obj = physObjs.get(i); if (!obj.isGhost) { obj.f = obj.f.add(g.mul(obj.mass)); } obj.dcm.set(obj.v.mul(time)); obj.cm.set(obj.cm.add(obj.dcm)); obj.v.set(obj.v.add(obj.f.mul(time).div(obj.mass))); if (obj.isRotated) { obj.angVel += obj.torque * time / obj.inertia; obj.theta += obj.angVel * time; obj.angVel += obj.torque * time / obj.inertia; obj.torque = obj.angVel * time * -obj.angDamp * obj.inertia; } obj.f.set(obj.v.mul(time * -obj.damp * obj.mass)); } Particle part; for (int p = 0; p < particles.size(); p++) { part = particles.get(p); if (!part.isGhost) { part.f = part.f.add(g.mul(part.mass)); } part.cm.set(part.cm.add(part.v.mul(time))); } }
/** Remove all living particles and restart emitting. */ public void reset() { mIsActive = true; mElapsed = 0; for (mParticleIdx = 0; mParticleIdx < mParticleCount; ++mParticleIdx) { Particle p = mParticles[mParticleIdx]; p.timeToLive = 0; } }
public double getAccelerationX(Particle p) { if ((p.getRecY() >= this.y) && (p.getRecY() <= (this.y + this.height)) && this.haveDone) { p.setRecX(2 * p.getX() - p.getRecX()); this.haveDone = false; } return 0; }
/** * Gets the delta from dead reckoning and moves the distribution in this direction * * @param x delta x * @param y delta y */ public void updateAction(double x, double y) { // propagate position through motion model for (Particle particle : particleList) { final double val = nextGaussian() * sigmaAction * scale; particle.setXY(particle.getX() + x + val, particle.getY() + y + val); } showParticles(); }
private void applyForces(final double dt) { for (final Object object : this.particles.keySet()) { final Particle particle = this.particles.get(object); final Vector oldSpeed = particle.getSpeed(); final Vector newSpeed = oldSpeed.add(this.forces.get(object).scale(dt / particle.getMass())); particle.setSpeed(newSpeed); } }
public void addParticle(Vector2 position, Vector2 velocity, float life, float scale) { if (particles.size > maxParticle) return; if (Gdx.graphics.getFramesPerSecond() < 25 && !(this instanceof ExplosionParticleEmitter)) return; Particle particle = freeParticles.obtain(); particle.setup(position, velocity, life, scale); particles.add(particle); }
/** * Returns the minimum number of occurances that this ContentModelGroup must appear * * @return the minimum number of occurances that this ContentModelGroup must appear A negative (n * < 0) value indicates that the value is unspecified. */ public int getMinOccurs() { if (_contentModel.getParticleCount() > 0) { Particle particle = _contentModel.getParticle(0); if (particle instanceof ContentModelGroup) { return particle.getMinOccurs(); } } return _contentModel.getMinOccurs(); } // -- getMinOccurs
private void removeDeadParticles() { for (Particle p : particles) { if (p.killed()) { particlesRemove.add(p); } } for (Particle pr : particlesRemove) particles.remove(pr); particlesRemove.clear(); }
public double getAccelerationY(Particle p) { if ((p.getRecX() >= this.x) && (p.getRecX() <= (this.x + this.length)) && this.haveDone) { p.setRecY(2 * p.getY() - p.getRecY()); this.haveDone = false; } return 0; }
/** * @see * org.newdawn.slick.particles.ParticleEmitter#updateParticle(org.newdawn.slick.particles.Particle, * int) */ @SuppressWarnings("null") @Override public void updateParticle(Particle particle, int delta) { particleCount++; // adjust the particles if required particle.x += adjustx; particle.y += adjusty; particle.adjustVelocity( windFactor.getValue(0) * 0.00005f * delta, gravityFactor.getValue(0) * 0.00005f * delta); float offset = particle.getLife() / particle.getOriginalLife(); float inv = 1 - offset; float colOffset = 0; float colInv = 1; Color startColor = null; Color endColor = null; for (int i = 0; i < colors.size() - 1; i++) { ColorRecord rec1 = colors.get(i); ColorRecord rec2 = colors.get(i + 1); if ((inv >= rec1.pos) && (inv <= rec2.pos)) { startColor = rec1.col; endColor = rec2.col; float step = rec2.pos - rec1.pos; colOffset = inv - rec1.pos; colOffset /= step; colOffset = 1 - colOffset; colInv = 1 - colOffset; } } if (startColor != null) { float r = (startColor.r * colOffset) + (endColor.r * colInv); float g = (startColor.g * colOffset) + (endColor.g * colInv); float b = (startColor.b * colOffset) + (endColor.b * colInv); float a; if (alpha.isActive()) a = alpha.getValue(inv) / 255.0f; else a = ((startAlpha.getValue(0) / 255.0f) * offset) + ((endAlpha.getValue(0) / 255.0f) * inv); particle.setColor(r, g, b, a); } if (size.isActive()) { float s = size.getValue(inv); particle.setSize(s); } else particle.adjustSize(delta * growthFactor.getValue(0) * 0.001f); if (velocity.isActive()) particle.setSpeed(velocity.getValue(inv)); if (scaleY.isActive()) particle.setScaleY(scaleY.getValue(inv)); }
private void updateParticle(Particle particle) { delta = Math.min(0.06f, Gdx.graphics.getDeltaTime()); if (particle.life > 0) { particle.life -= delta; particle.position.add(particle.velocity.x * delta * 10, particle.velocity.y * delta * 10); particle.velocity.mul((float) Math.pow(damping, delta)); particle.scale += this.delta_scale * delta / 5f; } }
private void slowdownSpeeds(final double dt) { for (final Object object : this.particles.keySet()) { final Particle particle = this.particles.get(object); final Vector oldSpeed = particle.getSpeed(); final double oldSpeedValue = oldSpeed.getLength(); final double newSpeedValue = this.slowdownFunction.evaluate(oldSpeedValue, dt); final Vector newSpeed = oldSpeed.setLength(newSpeedValue); particle.setSpeed(newSpeed); } }
public void func_73774_a() { for (int i = 0; i < field_73776_a.size(); i++) { Particle particle = (Particle) field_73776_a.get(i); particle.func_78062_a(); particle.func_78063_a(this); if (particle.field_78078_h) { field_73776_a.remove(i--); } } }
public static void main(String[] args) { List<Frob> list = new ArrayList<Frob>(); Map<Frob, Fnorkle> map = new HashMap<Frob, Fnorkle>(); Quark<Fnorkle> quark = new Quark<Fnorkle>(); Particle<Long, Double> p = new Particle<Long, Double>(); System.out.println(Arrays.toString(list.getClass().getTypeParameters())); System.out.println(Arrays.toString(map.getClass().getTypeParameters())); System.out.println(Arrays.toString(quark.getClass().getTypeParameters())); System.out.println(Arrays.toString(p.getClass().getTypeParameters())); }
@Test public void testSimpleBarycenter() { Particle p1 = new Particle(1.0, vector(1, 1, 1)); Particle p2 = new Particle(1.0, vector(0, 0, 0)); Vector3D center = Particle.geometricCenter(particles(p1, p2)); Vector3D barycenter = Particle.barycenter(particles(p1, p2)); Vector3D expected = vector(0.5, 0.5, 0.5); assertEquals(expected, center); assertEquals(expected, barycenter); }
public String toString() { String result = "UnitCell [T= " + elapsedTime + " ] : "; for (Particle p : particles) { result += '\n'; result += '\t'; result += p.toString(); } return result; }
public void update() { for (int i = 0; i < particles.size(); i++) { Particle particle = (Particle) particles.get(i); particle.preUpdate(); particle.update(this); if (particle.isDead) { particles.remove(i--); } } }
public Particle getNewParticle(ParticleEmitter emitter, float life) { ParticlePool pool = particlesByEmitter.get(emitter); ArrayList<Particle> available = pool.available; if (available.size() > 0) { Particle p = available.remove(available.size() - 1); p.init(emitter, life); p.setImage(sprite); return p; } return dummy; }
/*loops over particles and moves them*/ void MoveParticles() { Iterator iterator = particles.iterator(); while (iterator.hasNext()) { Particle part = (Particle) iterator.next(); part.accelerate(dt); part.move(dt); /*make sure the particle is still in domain*/ if (!InDomain(part)) iterator.remove(); } }
public boolean collidesWith(Particle p) { float deltaX = this.getX() - p.getX(); float deltaY = this.getY() - p.getY(); float minDist = this.getR() + p.getR(); float distance = deltaX * deltaX + deltaY * deltaY; if (distance <= (minDist * minDist)) { return true; } return false; }
/* * The magnetic potential of an atom is always zero, because magnetic force does not do any work. But for a dipole * moment, it is not zero. * * FIXME: I didn't find a closed-form solution for an electric dipole's magnetic potential. */ double getPotential(Particle p, float time) { if (bounds != null && !bounds.contains(p.getRx(), p.getRy())) return 0; double poten = 0.0; if (p instanceof GayBerneParticle) { GayBerneParticle gb = (GayBerneParticle) p; if (Math.abs(gb.dipoleMoment) > 0) { double temp = Math.sin(gb.theta) * gb.vx - Math.cos(gb.theta) * gb.vy; if (o == OUTWARD) temp = -temp; poten = gb.dipoleMoment * b * temp; } } return poten; }
private Particle createRandomizedParticle() { Particle rc = new Particle(); float[] pos = rc.getPosition(); pos[0] = (float) Math.random() * boxWidth; pos[1] = (float) Math.random() * boxHeight; float[] vel = rc.getVelocity(); vel[0] = (float) Math.random() * 150 - 75; vel[1] = (float) Math.random() * 150 - 75; return rc; }
/** * Updates the particle view. This should be called on each draw cycle in order to update the * positions of all nodes and edges in the viewer. If you need to update the positions of * particles without drawing it (e.g. to speed up movement, call updateParticles() instead. */ public void draw() { parent.pushStyle(); parent.pushMatrix(); zoomer.transform(); updateCentroid(); centroid.tick(); parent.translate(width / 2, height / 2); parent.scale(centroid.getZ()); parent.translate(-centroid.getX(), -centroid.getY()); if (!isPaused) { updateParticles(); } // Ensure that any selected element is positioned at the mouse location. if (selectedNode != null) { Particle p = nodes.get(selectedNode); p.makeFixed(); float mX = (zoomer.getMouseCoord().x - (width / 2)) / centroid.getZ() + centroid.getX(); float mY = (zoomer.getMouseCoord().y - (height / 2)) / centroid.getZ() + centroid.getY(); p.position().set(mX, mY, 0); } // Draw edges if we have positive stroke weight. if (parent.g.strokeWeight > 0) { parent.stroke(0, 180); parent.noFill(); for (Map.Entry<E, Spring> row : edges.entrySet()) { E edge = row.getKey(); Spring spring = row.getValue(); Vector3D p1 = spring.getOneEnd().position(); Vector3D p2 = spring.getTheOtherEnd().position(); edge.draw(parent, p1.x(), p1.y(), p2.x(), p2.y()); } } // Draw nodes. parent.noStroke(); parent.fill(120, 50, 50, 180); for (Map.Entry<N, Particle> row : nodes.entrySet()) { N node = row.getKey(); Vector3D p = row.getValue().position(); node.draw(parent, p.x(), p.y()); } parent.popMatrix(); parent.popStyle(); }
/** * Get a new particle from the system. This should be used by emitters to request particles * * @param emitter The emitter requesting the particle * @param life The time the new particle should live for * @return A particle from the system */ public Particle getNewParticle(ParticleEmitter emitter, float life) { ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter); ArrayList available = pool.available; if (available.size() > 0) { Particle p = (Particle) available.remove(available.size() - 1); p.init(emitter, life); p.setImage(sprite); return p; } Log.warn("Ran out of particles (increase the limit)!"); return dummy; }
public static Simulation initSpring(int count, double radius) { Settings stt = new Settings(); stt.setTimeStep(1); stt.setSpeedOfLight(3); stt.setSimulationWidth(100); stt.setSimulationHeight(100); stt.addForce(new ConstantForce()); stt.addForce(new SpringForce()); stt.setNumOfParticles(count); stt.setParticleRadius(radius); stt.setParticleMaxSpeed(stt.getSpeedOfLight()); stt.setBoundary(GeneralBoundaryType.Periodic); stt.setParticleSolver(new EulerRichardson()); for (int k = 0; k < count; k++) { Particle par = new Particle(); par.setX(stt.getSimulationWidth() * Math.random()); par.setY(stt.getSimulationHeight() * Math.random()); par.setRadius(15); par.setVx(10 * Math.random()); par.setVy(0); par.setMass(1); par.setCharge(.001); stt.addParticle(par); } Simulation simulation = new Simulation(stt); return simulation; }