@Override public void onEmission(EnergyRangeGeneratorComponent component, ParticleData particleData, Random random) { particleData.energy = random.nextFloat(component.minEnergy, component.maxEnergy); } }
/** * Randomises a provided Vector3f so its components range from min (inclusive) to max * * @param min * @param max * @param output * @return */ public Vector3f nextVector3f(float min, float max, Vector3f output) { output.set(nextFloat(min, max), nextFloat(min, max), nextFloat(min, max)); return output; }
private void randomWalk(Vector3f worldPos, HierarchicalAIComponent ai) { // if ai flies if (ai.flying) { float targetY = 0; do { targetY = worldPos.y + random.nextFloat(-100.0f, 100.0f); } while (targetY > ai.maxAltitude); ai.movementTarget.set( worldPos.x + random.nextFloat(-500.0f, 500.0f), targetY, worldPos.z + random.nextFloat(-500.0f, 500.0f)); } else { ai.movementTarget.set( worldPos.x + random.nextFloat(-500.0f, 500.0f), worldPos.y, worldPos.z + random.nextFloat(-500.0f, 500.0f)); } ai.lastChangeOfDirectionAt = time.getGameTimeInMs(); }
private static void randomizeParticle(final ParticlePool pool, final int index) { final int index3 = index * 3; final int index4 = index * 4; pool.energy[index] = random.nextFloat(); for (int i = 0; i < 3; i++) { pool.position[index3 + i] = random.nextFloat(); pool.previousPosition[index3 + i] = random.nextFloat(); pool.velocity[index3 + i] = random.nextFloat(); pool.scale[index3 + i] = random.nextFloat(); } for (int i = 0; i < 4; i++) { pool.color[index4 + i] = random.nextFloat(); } }
private void createSamplesBuffer() { ssaoSamples = BufferUtils.createFloatBuffer(SSAO_KERNEL_ELEMENTS * 3); for (int i = 0; i < SSAO_KERNEL_ELEMENTS; ++i) { Vector3f vec = new Vector3f(); vec.x = randomGenerator.nextFloat(-1.0f, 1.0f); vec.y = randomGenerator.nextFloat(-1.0f, 1.0f); vec.z = randomGenerator.nextFloat(); vec.normalize(); vec.scale(randomGenerator.nextFloat(0.0f, 1.0f)); float scale = i / (float) SSAO_KERNEL_ELEMENTS; scale = TeraMath.lerp(0.25f, 1.0f, scale * scale); vec.scale(scale); ssaoSamples.put(vec.x); ssaoSamples.put(vec.y); ssaoSamples.put(vec.z); } ssaoSamples.flip(); }
private void runAway(EntityRef entity, HierarchicalAIComponent ai) { Vector3f tempTarget = localPlayer.getPosition(); if (ai.forgiving != 0) { ai.movementTarget.set(new Vector3f( -tempTarget.x + random.nextFloat(-ai.forgiving, ai.forgiving), -tempTarget.y + random.nextFloat(-ai.forgiving, ai.forgiving), -tempTarget.z + random.nextFloat(-ai.forgiving, ai.forgiving) )); } else { ai.movementTarget .set(new Vector3f(tempTarget.x * -1, tempTarget.y * -1, tempTarget.z * -1)); } entity.saveComponent(ai); ai.inDanger = true; }
@Override public void onEmission(final PositionRangeGeneratorComponent component, final ParticleData particleData, final Random random ) { particleData.position.set( random.nextFloat(component.minPosition.x(), component.maxPosition.x()), random.nextFloat(component.minPosition.y(), component.maxPosition.y()), random.nextFloat(component.minPosition.z(), component.maxPosition.z()) ); } }
private Texture generateNoiseTexture() { Optional<Texture> texture = Assets.getTexture("engine:ssaoNoise"); if (!texture.isPresent()) { ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4); for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) { Vector3f noiseVector = new Vector3f(randomGenerator.nextFloat(-1.0f, 1.0f), randomGenerator.nextFloat(-1.0f, 1.0f), 0.0f); noiseVector.normalize(); noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f)); noiseValues.put((byte) 0x0); } noiseValues.flip(); return Assets.generateAsset(new ResourceUrn("engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE, new ByteBuffer[]{noiseValues}, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class); } return texture.get(); } }
@Override public void onEmission(final ScaleRangeGeneratorComponent component, final ParticleData particleData, final Random random ) { particleData.scale.set( random.nextFloat(component.minScale.x(), component.maxScale.x()), random.nextFloat(component.minScale.y(), component.maxScale.y()), random.nextFloat(component.minScale.z(), component.maxScale.z()) ); } }
@Override public void onEmission(final VelocityRangeGeneratorComponent component, final ParticleData particleData, final Random random) { particleData.velocity.setX(random.nextFloat(component.minVelocity.x(), component.maxVelocity.x())); particleData.velocity.setY(random.nextFloat(component.minVelocity.y(), component.maxVelocity.y())); particleData.velocity.setZ(random.nextFloat(component.minVelocity.z(), component.maxVelocity.z())); } }
@Override public void onEmission(final ColorRangeGeneratorComponent component, final ParticleData particleData, final Random random ) { particleData.color.setX(random.nextFloat(component.minColorComponents.x(), component.maxColorComponents.x())); particleData.color.setY(random.nextFloat(component.minColorComponents.y(), component.maxColorComponents.y())); particleData.color.setZ(random.nextFloat(component.minColorComponents.z(), component.maxColorComponents.z())); particleData.color.setW(random.nextFloat(component.minColorComponents.w(), component.maxColorComponents.w())); } }
@Test public void testMinMax() { float min = Float.POSITIVE_INFINITY; float max = Float.NEGATIVE_INFINITY; for (int i = 0; i < 5000000; i++) { float posX = rng.nextFloat() * 100f; float posY = rng.nextFloat() * 100f; float posZ = rng.nextFloat() * 100f; float noise = noiseGen.noise(posX, posY, posZ); if (noise < min) { min = noise; } if (noise > max) { max = noise; } } Assert.assertTrue(min >= -1); Assert.assertTrue(max <= 1); Assert.assertEquals(-1, min, 0.05); Assert.assertEquals(1, max, 0.05); }
if (random.nextFloat() < chanceOfBlockDrop) { List<String> blockDrops = blockDrop.blockDrops; List<String> itemDrops = blockDrop.itemDrops; if (pipeIndex > -1) { float chance = Float.parseFloat(dropResult.substring(0, pipeIndex)); if (random.nextFloat() >= chance) { dropping = false; if (pipeIndex > -1) { float chance = Float.parseFloat(dropResult.substring(0, pipeIndex)); if (random.nextFloat() >= chance) { dropping = false;
@Override public void generate(BlockManager blockManager, CoreChunk view, Random rand, int posX, int posY, int posZ) { Vector3f position = new Vector3f(0f, 0f, 0f); Matrix4f rotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), (float) Math.PI / 2f), Vector3f.ZERO, 1.0f); float angleOffset = rand.nextFloat(-MAX_ANGLE_OFFSET, MAX_ANGLE_OFFSET); Block bark = blockManager.getBlock(barkType); Block leaf = blockManager.getBlock(leafType); recursiveGenerator.recurse(view, rand, posX, posY, posZ, angleOffset, new CharSequenceIterator(initialAxiom), position, rotation, bark, leaf, 0, this); }
public void commonDefaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, Vector3i location, Block block) { BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class); float chanceOfBlockDrop = 1; if (blockDamageModifierComponent != null) { chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance; } if (random.nextFloat() < chanceOfBlockDrop) { EntityRef item = blockItemFactory.newInstance(block.getBlockFamily(), entity); entity.send(new OnBlockToItem(item)); if (shouldDropToWorld(event, block, blockDamageModifierComponent, item)) { float impulsePower = 0; if (blockDamageModifierComponent != null) { impulsePower = blockDamageModifierComponent.impulsePower; } processDropping(item, location, impulsePower); } } }
/** * Execute the final post processing on the rendering of the scene obtained so far. * * It uses the data stored in multiple FBOs as input and the FINAL FBO to store its output, rendering everything to a quad. */ @Override public void process() { PerformanceMonitor.startActivity("rendering/" + getUri()); postMaterial.setFloat("focalDistance", cameraTargetSystem.getFocalDistance(), true); //for use in DOF effect if (isFilmGrainEnabled) { postMaterial.setFloat("grainIntensity", filmGrainIntensity, true); postMaterial.setFloat("noiseOffset", randomGenerator.nextFloat(), true); postMaterial.setFloat2("noiseSize", noiseTextureSize, noiseTextureSize, true); postMaterial.setFloat2("renderTargetSize", lastUpdatedGBuffer.width(), lastUpdatedGBuffer.height(), true); } if (isMotionBlurEnabled) { postMaterial.setMatrix4("invViewProjMatrix", activeCamera.getInverseViewProjectionMatrix(), true); postMaterial.setMatrix4("prevViewProjMatrix", activeCamera.getPrevViewProjectionMatrix(), true); } renderFullscreenQuad(); if (screenGrabber.isTakingScreenshot()) { screenGrabber.saveScreenshot(); } PerformanceMonitor.endActivity(); }
particleEffects++; if (random.nextFloat() < tunnelActionComponent.thoroughness) { EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos); blockEntity.send(new DoDamageEvent(tunnelActionComponent.damageAmount, tunnelActionComponent.damageType));