/** * Returns a random int between min and max. * * @return A random int between <tt>min</tt> (inclusive) to <tt>max</tt> (inclusive). */ public static int nextRandomInt(final int min, final int max) { return (int) (nextRandomFloat() * (max - min + 1)) + min; }
/** * Returns a random int between min and max. * * @return A random int between <tt>min</tt> (inclusive) to <tt>max</tt> (inclusive). */ public static int nextRandomInt(final int min, final int max) { return (int) (nextRandomFloat() * (max - min + 1)) + min; }
private double calcNewJitter() { return ((MathUtils.nextRandomFloat() * 2.0f) - 1.0f) * _wanderJitter; }
private double calcNewJitter() { return ((MathUtils.nextRandomFloat() * 2.0f) - 1.0f) * _wanderJitter; }
/** * @param store * the color to store the result in for return. If null, a new color object is created and returned. * @return a random, mutable opaque color. */ public static ColorRGBA randomColor(final ColorRGBA store) { ColorRGBA result = store; if (result == null) { result = new ColorRGBA(); } result._r = MathUtils.nextRandomFloat(); result._g = MathUtils.nextRandomFloat(); result._b = MathUtils.nextRandomFloat(); result._a = 1.0f; return result; }
/** * @param store * the color to store the result in for return. If null, a new color object is created and returned. * @return a random, mutable opaque color. */ public static ColorRGBA randomColor(final ColorRGBA store) { ColorRGBA result = store; if (result == null) { result = new ColorRGBA(); } result._r = MathUtils.nextRandomFloat(); result._g = MathUtils.nextRandomFloat(); result._b = MathUtils.nextRandomFloat(); result._a = 1.0f; return result; }
/** * Sets every color of this geometry's color array to a random color. */ public void setRandomColors() { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } else { colorBuf.rewind(); } for (int x = 0, cLength = colorBuf.limit(); x < cLength; x += 4) { colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(1); } colorBuf.flip(); }
/** * Sets every color of this geometry's color array to a random color. */ public void setRandomColors() { FloatBuffer colorBuf = _meshData.getColorBuffer(); if (colorBuf == null) { colorBuf = BufferUtils.createColorBuffer(_meshData.getVertexCount()); _meshData.setColorBuffer(colorBuf); } else { colorBuf.rewind(); } for (int x = 0, cLength = colorBuf.limit(); x < cLength; x += 4) { colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(MathUtils.nextRandomFloat()); colorBuf.put(1); } colorBuf.flip(); }
/** * generate a random lifespan between the min and max lifespan of the particle system. * * @return the generated lifespan value */ public double getRandomLifeSpan() { return getMinimumLifeTime() + ((getMaximumLifeTime() - getMinimumLifeTime()) * MathUtils.nextRandomFloat()); }
/** * Returns a random angle between the min and max angles. * * @return the random angle. */ public double getRandomAngle() { return getMinimumAngle() + MathUtils.nextRandomFloat() * (getMaximumAngle() - getMinimumAngle()); }
/** * generate a random lifespan between the min and max lifespan of the particle system. * * @return the generated lifespan value */ public double getRandomLifeSpan() { return getMinimumLifeTime() + ((getMaximumLifeTime() - getMinimumLifeTime()) * MathUtils.nextRandomFloat()); }
@Override public void apply(final double dt, final Particle p, final int index) { final double tStr = (_random ? MathUtils.nextRandomFloat() * _strength : _strength); _vector.scaleAdd(tStr * dt, p.getVelocity(), p.getVelocity()); }
/** * Returns a random angle between the min and max angles. * * @return the random angle. */ public double getRandomAngle() { return getMinimumAngle() + MathUtils.nextRandomFloat() * (getMaximumAngle() - getMinimumAngle()); }
@Override public void apply(final double dt, final Particle p, final int index) { final double tStr = (_random ? MathUtils.nextRandomFloat() * _strength : _strength); _vector.scaleAdd(tStr * dt, p.getVelocity(), p.getVelocity()); }
/** * random returns a random point within the plane defined by: A, B, C, and (B + C) - A. * * @param result * Vector to store result in * @return a random point within the rectangle. */ @Override public Vector3 random(Vector3 result) { if (result == null) { result = new Vector3(); } final double s = MathUtils.nextRandomFloat(); final double t = MathUtils.nextRandomFloat(); final double aMod = 1.0 - s - t; final Vector3 temp1 = Vector3.fetchTempInstance(); final Vector3 temp2 = Vector3.fetchTempInstance(); final Vector3 temp3 = Vector3.fetchTempInstance(); result.set(_a.multiply(aMod, temp1).addLocal(_b.multiply(s, temp2).addLocal(_c.multiply(t, temp3)))); Vector3.releaseTempInstance(temp1); Vector3.releaseTempInstance(temp2); Vector3.releaseTempInstance(temp3); return result; }
/** * random returns a random point within the plane defined by: A, B, C, and (B + C) - A. * * @param result * Vector to store result in * @return a random point within the rectangle. */ @Override public Vector3 random(Vector3 result) { if (result == null) { result = new Vector3(); } final double s = MathUtils.nextRandomFloat(); final double t = MathUtils.nextRandomFloat(); final double aMod = 1.0 - s - t; final Vector3 temp1 = Vector3.fetchTempInstance(); final Vector3 temp2 = Vector3.fetchTempInstance(); final Vector3 temp3 = Vector3.fetchTempInstance(); result.set(_a.multiply(aMod, temp1).addLocal(_b.multiply(s, temp2).addLocal(_c.multiply(t, temp3)))); Vector3.releaseTempInstance(temp1); Vector3.releaseTempInstance(temp2); Vector3.releaseTempInstance(temp3); return result; }
final double r = Math.sqrt(inner2 + MathUtils.nextRandomFloat() * (outer2 - inner2)); final double theta = MathUtils.nextRandomFloat() * MathUtils.TWO_PI;
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
/** * Generate a random velocity within the parameters of max angle and the rotation matrix. * * @param store * a vector to store the results in. */ protected Vector3 getRandomVelocity(final Vector3 store) { final double randDir = MathUtils.TWO_PI * MathUtils.nextRandomFloat(); final double randAngle = getRandomAngle(); Vector3 result = store; if (result == null) { result = new Vector3(); } result.setX(MathUtils.cos(randDir) * MathUtils.sin(randAngle)); result.setY(MathUtils.cos(randAngle)); result.setZ(MathUtils.sin(randDir) * MathUtils.sin(randAngle)); rotateVectorSpeed(result); result.multiplyLocal(getInitialVelocity()); return result; }
@Override public void apply(final double dt, final Particle p, final int index) { final double dtStr = dt * _strength * (_random ? MathUtils.nextRandomFloat() : 1f); p.getPosition().subtract(_line.getOrigin(), _v1); _line.getDirection().cross(_v1, v2); if (v2.length() == 0) { // particle is on the axis return; } v2.normalizeLocal(); if (_type == VT_CYLINDER) { _rot.apply(v2, v2); v2.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); return; } v2.cross(_line.getDirection(), _v1); _v1.multiplyLocal(_radius); _line.getDirection().scaleAdd(_height, _v1, _v1); _v1.addLocal(_line.getOrigin()); _v1.subtractLocal(p.getPosition()); if (_v1.length() == 0) { // particle is on the ring return; } _v1.normalizeLocal(); _v1.cross(v2, v3); _rot.fromAngleAxis(-_divergence, v2); _rot.apply(v3, v3); v3.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); }