@Override public void getRandomPoint(Vector3f store) { store.x = min.x + len.x * FastMath.nextRandomFloat(); store.y = min.y + len.y * FastMath.nextRandomFloat(); store.z = min.z + len.z * FastMath.nextRandomFloat(); }
/** * Returns a random integer between min and max. * * @return A random int between <tt>min</tt> (inclusive) to * <tt>max</tt> (inclusive). */ public static int nextRandomInt(int min, int max) { return (int) (nextRandomFloat() * (max - min + 1)) + min; }
/** * <code>randomColor</code> is a utility method that generates a random * opaque color. * @return a random <code>ColorRGBA</code> with an alpha set to 1. */ public static ColorRGBA randomColor() { ColorRGBA rVal = new ColorRGBA(0, 0, 0, 1); rVal.r = FastMath.nextRandomFloat(); rVal.g = FastMath.nextRandomFloat(); rVal.b = FastMath.nextRandomFloat(); return rVal; }
@Override protected void applyVelocityVariation(Particle particle) { temp.set(FastMath.nextRandomFloat() * velocityVariation, FastMath.nextRandomFloat() * velocityVariation, FastMath.nextRandomFloat() * velocityVariation); particle.velocity.addLocal(temp); }
@Override public void getRandomPoint(Vector3f store) { do { store.x = (FastMath.nextRandomFloat() * 2f - 1f); store.y = (FastMath.nextRandomFloat() * 2f - 1f); store.z = (FastMath.nextRandomFloat() * 2f - 1f); } while (store.lengthSquared() > 1); store.multLocal(radius); store.addLocal(center); }
/** * This method fills the point with coordinates of randomly selected point on a random face. * @param store * the variable to store with coordinates of randomly selected selected point on a random face */ @Override public void getRandomPoint(Vector3f store) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); // the index of the first vertex of a face (must be dividable by 3) int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1) * 3; // put the point somewhere between the first and the second vertex of a face float moveFactor = FastMath.nextRandomFloat(); store.set(Vector3f.ZERO); store.addLocal(vertices.get(meshIndex).get(vertIndex)); store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor); // move the result towards the last face vertex moveFactor = FastMath.nextRandomFloat(); store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor); }
private static Vector2f randomVector() { return new Vector2f(FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); }
/** * This method fills the point with coordinates of randomly selected point on a random face. * The normal param is filled with selected face's normal. * @param store * the variable to store with coordinates of randomly selected selected point on a random face * @param normal * filled with selected face's normal */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); // the index of the first vertex of a face (must be dividable by 3) int faceIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1); int vertIndex = faceIndex * 3; // put the point somewhere between the first and the second vertex of a face float moveFactor = FastMath.nextRandomFloat(); store.set(Vector3f.ZERO); store.addLocal(vertices.get(meshIndex).get(vertIndex)); store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor); // move the result towards the last face vertex moveFactor = FastMath.nextRandomFloat(); store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor); normal.set(normals.get(meshIndex).get(faceIndex)); } }
/** * This method fills the point with coordinates of randomly selected point inside a convex hull * of randomly selected mesh. * @param store * the variable to store with coordinates of randomly selected selected point inside a convex hull * of randomly selected mesh */ @Override public void getRandomPoint(Vector3f store) { super.getRandomPoint(store); // now move the point from the meshe's face towards the center of the mesh // the center is in (0, 0, 0) in the local coordinates store.multLocal(FastMath.nextRandomFloat()); }
/** * This method applies the variation to the particle with already set velocity. * @param particle * the particle to be affected */ protected void applyVelocityVariation(Particle particle) { particle.velocity.set(initialVelocity); temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); temp.multLocal(2f); temp.subtractLocal(1f, 1f, 1f); temp.multLocal(initialVelocity.length()); particle.velocity.interpolateLocal(temp, velocityVariation); }
@Override public void simpleUpdate(float tpf) { time += tpf; if (time > nextTime) { Vector3f v = new Vector3f(); v.setX(FastMath.nextRandomFloat()); v.setY(FastMath.nextRandomFloat()); v.setZ(FastMath.nextRandomFloat()); v.multLocal(40, 2, 40); v.subtractLocal(20, 1, 20); audioSource.setLocalTranslation(v); audioSource.playInstance(); time = 0; nextTime = FastMath.nextRandomFloat() * 2 + 0.5f; } } }
/** * This method fills the point with coordinates of randomly selected point inside a convex hull * of randomly selected mesh. * The normal param is not used. * @param store * the variable to store with coordinates of randomly selected selected point inside a convex hull * of randomly selected mesh * @param normal * not used in this class */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { super.getRandomPointAndNormal(store, normal); // now move the point from the meshe's face towards the center of the mesh // the center is in (0, 0, 0) in the local coordinates store.multLocal(FastMath.nextRandomFloat()); } }
/** * <code>random</code> 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. */ public Vector3f random(Vector3f result) { if (result == null) { result = new Vector3f(); } float s = FastMath.nextRandomFloat(); float t = FastMath.nextRandomFloat(); float aMod = 1.0f - s - t; result.set(a.mult(aMod).addLocal(b.mult(s).addLocal(c.mult(t)))); return result; }
/** * This method applies the variation to the particle with already set velocity. * @param particle * the particle to be affected */ @Override protected void applyVelocityVariation(Particle particle) { particle.velocity.set(initialVelocity); temp.set(particle.position).subtractLocal(origin).normalizeLocal().multLocal(radialVelocity); if (horizontal) { temp.y = 0; } particle.velocity.addLocal(temp); temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); temp.multLocal(2f); temp.subtractLocal(1f, 1f, 1f); temp.multLocal(initialVelocity.length()); particle.velocity.interpolateLocal(temp, velocityVariation); }
p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife); p.life = p.startlife; p.color.set(startColor); p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI; p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
/** * * <code>random</code> returns a random point within the ring. * * @param result Vector to store result in * @return a random point within the ring. */ public Vector3f random(Vector3f result) { if (result == null) { result = new Vector3f(); } // compute a random radius according to the ring area distribution float inner2 = innerRadius * innerRadius, outer2 = outerRadius * outerRadius, r = FastMath.sqrt(inner2 + FastMath.nextRandomFloat() * (outer2 - inner2)), theta = FastMath .nextRandomFloat() * FastMath.TWO_PI; up.cross(Vector3f.UNIT_X, b1); if (b1.lengthSquared() < FastMath.FLT_EPSILON) { up.cross(Vector3f.UNIT_Y, b1); } b1.normalizeLocal(); up.cross(b1, b2); result.set(b1).multLocal(r * FastMath.cos(theta)).addLocal(center); result.scaleAdd(r * FastMath.sin(theta), b2, result); return result; }
float dir = ((Float)child.getUserData("dir")).floatValue(); val += (dir + ((FastMath.nextRandomFloat() * 0.5f) - 0.25f)) * tpf;
t.setLocalScale(FastMath.nextRandomFloat() * 10f); t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]); rootNode.attachChild(t); t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
Geometry instance = createInstance(x, y); float height = (smoothstep(0, 1, FastMath.nextRandomFloat()) * 2.5f) - 1.25f; instance.setUserData("height", height); instance.setUserData("dir", 1f);
/** * This method applies the variation to the particle with already set velocity. * @param particle * the particle to be affected */ protected void applyVelocityVariation(Particle particle) { particle.velocity.set(initialVelocity); temp.set(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), FastMath.nextRandomFloat()); temp.multLocal(2f); temp.subtractLocal(1f, 1f, 1f); temp.multLocal(initialVelocity.length()); particle.velocity.interpolateLocal(temp, velocityVariation); }