Java Code Examples for com.jme3.math.FastMath#nextRandomInt()
The following examples show how to use
com.jme3.math.FastMath#nextRandomInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CubeField.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Randomly Places a cube on the map between 30 and 90 paces away from player */ private void randomizeCube() { Geometry cube = fcube.clone(); int playerX = (int) player.getLocalTranslation().getX(); int playerZ = (int) player.getLocalTranslation().getZ(); // float x = FastMath.nextRandomInt(playerX + difficulty + 10, playerX + difficulty + 150); float x = FastMath.nextRandomInt(playerX + difficulty + 30, playerX + difficulty + 90); float z = FastMath.nextRandomInt(playerZ - difficulty - 50, playerZ + difficulty + 50); cube.getLocalTranslation().set(x, 0, z); // playerX+difficulty+30,playerX+difficulty+90 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); if (!solidBox){ mat.getAdditionalRenderState().setWireframe(true); } mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1))); cube.setMaterial(mat); rootNode.attachChild(cube); cubeField.add(cube); }
Example 2
Source File: EmitterMeshFaceShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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)); }
Example 3
Source File: CubeField.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Randomly Places a cube on the map between 30 and 90 paces away from player */ private void randomizeCube() { Geometry cube = fcube.clone(); int playerX = (int) player.getLocalTranslation().getX(); int playerZ = (int) player.getLocalTranslation().getZ(); // float x = FastMath.nextRandomInt(playerX + difficulty + 10, playerX + difficulty + 150); float x = FastMath.nextRandomInt(playerX + difficulty + 30, playerX + difficulty + 90); float z = FastMath.nextRandomInt(playerZ - difficulty - 50, playerZ + difficulty + 50); cube.getLocalTranslation().set(x, 0, z); // playerX+difficulty+30,playerX+difficulty+90 Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); if (!solidBox){ mat.getAdditionalRenderState().setWireframe(true); } mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1))); cube.setMaterial(mat); rootNode.attachChild(cube); cubeField.add(cube); }
Example 4
Source File: EmitterMeshFaceShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * 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)); }
Example 5
Source File: TestInstanceNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Geometry createInstance(float x, float z) { Mesh mesh; if (FastMath.nextRandomInt(0, 1) == 1) mesh = mesh2; else mesh = mesh1; Geometry geometry = new Geometry("randomGeom", mesh); geometry.setMaterial(materials[FastMath.nextRandomInt(0, materials.length - 1)]); geometry.setLocalTranslation(x, 0, z); return geometry; }
Example 6
Source File: ParticleEmitter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Particle emitParticle(Vector3f min, Vector3f max) { int idx = lastUsed + 1; if (idx >= particles.length) { return null; } Particle p = particles[idx]; if (selectRandomImage) { p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1); } p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife); p.life = p.startlife; p.color.set(startColor); p.size = startSize; //shape.getRandomPoint(p.position); particleInfluencer.influenceParticle(p, shape); if (worldSpace) { worldTransform.transformVector(p.position, p.position); worldTransform.getRotation().mult(p.velocity, p.velocity); // TODO: Make scale relevant somehow?? } if (randomAngle) { p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI; } if (rotateSpeed != 0) { p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f); } temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); ++lastUsed; firstUnUsed = idx + 1; return p; }
Example 7
Source File: EmitterMeshVertexShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * This method fills the point with coordinates of randomly selected mesh vertex. * @param store * the variable to store with coordinates of randomly selected mesh vertex */ @Override public void getRandomPoint(Vector3f store) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1); store.set(vertices.get(meshIndex).get(vertIndex)); }
Example 8
Source File: EmitterMeshFaceShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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); }
Example 9
Source File: MyParticleEmitter.java From OpenRTS with MIT License | 5 votes |
private Particle emitParticle(Vector3f min, Vector3f max) { int idx = lastUsed + 1; if (idx >= particles.length) { return null; } Particle p = particles[idx]; if (selectRandomImage) { p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1); } p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife); p.life = p.startlife; p.color.set(startColor); p.size = startSize; //shape.getRandomPoint(p.position); particleInfluencer.influenceParticle(p, shape); if (worldSpace) { worldTransform.transformVector(p.position, p.position); worldTransform.getRotation().mult(p.velocity, p.velocity); // TODO: Make scale relevant somehow?? } if (randomAngle) { p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI; } if (rotateSpeed != 0) { p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f); } temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); ++lastUsed; firstUnUsed = idx + 1; return p; }
Example 10
Source File: ParticleEmitter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private Particle emitParticle(Vector3f min, Vector3f max) { int idx = lastUsed + 1; if (idx >= particles.length) { return null; } Particle p = particles[idx]; if (selectRandomImage) { p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1); } p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife); p.life = p.startlife; p.color.set(startColor); p.size = startSize; //shape.getRandomPoint(p.position); particleInfluencer.influenceParticle(p, shape); if (worldSpace) { worldTransform.transformVector(p.position, p.position); worldTransform.getRotation().mult(p.velocity, p.velocity); // TODO: Make scale relevant somehow?? } if (randomAngle) { p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI; } if (rotateSpeed != 0) { p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f); } temp.set(p.position).addLocal(p.size, p.size, p.size); max.maxLocal(temp); temp.set(p.position).subtractLocal(p.size, p.size, p.size); min.minLocal(temp); ++lastUsed; firstUnUsed = idx + 1; return p; }
Example 11
Source File: EmitterMeshVertexShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method fills the point with coordinates of randomly selected mesh vertex. * @param store * the variable to store with coordinates of randomly selected mesh vertex */ @Override public void getRandomPoint(Vector3f store) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1); store.set(vertices.get(meshIndex).get(vertIndex)); }
Example 12
Source File: EmitterMeshFaceShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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); }
Example 13
Source File: TestInstanceNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleUpdate(float tpf) { time += tpf; if (time > 1f) { time = 0f; for (Spatial instance : instancedNode.getChildren()) { if (!(instance instanceof InstancedGeometry)) { Geometry geom = (Geometry) instance; geom.setMaterial(materials[FastMath.nextRandomInt(0, materials.length - 1)]); Mesh mesh; if (FastMath.nextRandomInt(0, 1) == 1) mesh = mesh2; else mesh = mesh1; geom.setMesh(mesh); } } } for (Spatial child : instancedNode.getChildren()) { if (!(child instanceof InstancedGeometry)) { float val = ((Float)child.getUserData("height")).floatValue(); float dir = ((Float)child.getUserData("dir")).floatValue(); val += (dir + ((FastMath.nextRandomFloat() * 0.5f) - 0.25f)) * tpf; if (val > 1f) { val = 1f; dir = -dir; } else if (val < 0f) { val = 0f; dir = -dir; } Vector3f translation = child.getLocalTranslation(); translation.y = (smoothstep(0, 1, val) * 2.5f) - 1.25f; child.setUserData("height", val); child.setUserData("dir", dir); child.setLocalTranslation(translation); } } }
Example 14
Source File: EmitterMeshVertexShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * This method fills the point with coordinates of randomly selected mesh vertex. * The normal param is filled with selected vertex's normal. * @param store * the variable to store with coordinates of randomly selected mesh vertex * @param normal * filled with selected vertex's normal */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1); store.set(vertices.get(meshIndex).get(vertIndex)); normal.set(normals.get(meshIndex).get(vertIndex)); }
Example 15
Source File: EmitterMeshVertexShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 3 votes |
/** * This method fills the point with coordinates of randomly selected mesh vertex. * The normal param is filled with selected vertex's normal. * @param store * the variable to store with coordinates of randomly selected mesh vertex * @param normal * filled with selected vertex's normal */ @Override public void getRandomPointAndNormal(Vector3f store, Vector3f normal) { int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1); int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() - 1); store.set(vertices.get(meshIndex).get(vertIndex)); normal.set(normals.get(meshIndex).get(vertIndex)); }