use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class SpriteParticleRenderer method renderAlphaBlend.
@Override
public void renderAlphaBlend() {
Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
material.enable();
Vector3f camPos = worldRenderer.getActiveCamera().getPosition();
particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(p -> drawParticles(material, p, camPos));
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class ParticleUpdaterImpl method checkCollision.
// == particles =====================================================================================================
private void checkCollision(final ParticlePool pool, final int offset) {
final Vector3f vel = new Vector3f();
final Vector3f halfVelDir = new Vector3f();
final Vector3f curr = new Vector3f();
for (int i = offset; i < pool.livingParticles(); i += PHYSICS_SKIP_NR) {
int i3 = i * 3;
curr.set(pool.position[i3 + 0], pool.position[i3 + 1], pool.position[i3 + 2]);
vel.set(pool.velocity[i3 + 0], pool.velocity[i3 + 1], pool.velocity[i3 + 2]);
halfVelDir.scale(0).add(vel).normalize().scale(0.5f);
curr.sub(halfVelDir);
float dist = (vel.length() + 0.5f) * movingAvgDelta * PHYSICS_SKIP_NR * 1.5f;
vel.normalize();
HitResult hitResult = physics.rayTrace(curr, vel, dist, StandardCollisionGroup.WORLD);
if (hitResult.isHit()) {
pool.energy[i] = 0;
}
}
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class AnimationScreen method initialise.
@Override
public void initialise() {
spawnEntityIdButton = find("spawnEntityIdButton", UIButton.class);
entityDropdown = find("entityDropdown", UIDropdownScrollable.class);
logger.info("Number of available skeletal meshes: " + assetManager.getAvailableAssets(SkeletalMesh.class).size());
ArrayList skeletalMesh = new ArrayList(assetManager.getAvailableAssets(SkeletalMesh.class));
if (entityDropdown != null) {
entityDropdown.setOptions(skeletalMesh);
}
animationSpeedSlider = find("entityAnimationSpeedSlider", UISlider.class);
if (animationSpeedSlider != null) {
animationSpeedSlider.setMinimum(-0.0f);
animationSpeedSlider.setIncrement(0.1f);
animationSpeedSlider.setRange(10.0f);
animationSpeedSlider.setPrecision(1);
}
spawnEntityIdButton.subscribe(widget -> {
Vector3f localPlayerPosition = localPlayer.getPosition();
Quat4f localPlayerRotation = localPlayer.getRotation();
Vector3f offset = localPlayer.getViewDirection();
offset.scale(2.0f);
offset.y = 0;
localPlayerPosition.add(offset);
Optional<Prefab> prefab = assetManager.getAsset(entityDropdown.getSelection(), Prefab.class);
if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
entityRef = entityManager.create(prefab.get(), localPlayerPosition, localPlayerRotation);
SkeletalMeshComponent skeletalMeshComponent = entityRef.getComponent(SkeletalMeshComponent.class);
skeletalMeshComponent.animationRate = animationSpeedSlider.getValue();
entityRef.saveComponent(skeletalMeshComponent);
CharacterMovementComponent movementComponent = entityRef.getComponent(CharacterMovementComponent.class);
movementComponent.speedMultiplier = animationSpeedSlider.getValue();
entityRef.saveComponent(movementComponent);
}
});
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class DoorSystem method placeDoor.
@ReceiveEvent(components = { DoorComponent.class, ItemComponent.class })
public void placeDoor(ActivateEvent event, EntityRef entity) {
DoorComponent door = entity.getComponent(DoorComponent.class);
BlockComponent targetBlockComp = event.getTarget().getComponent(BlockComponent.class);
if (targetBlockComp == null) {
event.consume();
return;
}
Vector3f horizDir = new Vector3f(event.getDirection());
horizDir.y = 0;
Side facingDir = Side.inDirection(horizDir);
if (!facingDir.isHorizontal()) {
event.consume();
return;
}
Vector3f offset = new Vector3f(event.getHitPosition());
offset.sub(targetBlockComp.getPosition().toVector3f());
Side offsetDir = Side.inDirection(offset);
Vector3i primePos = new Vector3i(targetBlockComp.getPosition());
primePos.add(offsetDir.getVector3i());
Block primeBlock = worldProvider.getBlock(primePos);
if (!primeBlock.isReplacementAllowed()) {
event.consume();
return;
}
Block belowBlock = worldProvider.getBlock(primePos.x, primePos.y - 1, primePos.z);
Block aboveBlock = worldProvider.getBlock(primePos.x, primePos.y + 1, primePos.z);
// Determine top and bottom blocks
Vector3i bottomBlockPos;
Vector3i topBlockPos;
if (belowBlock.isReplacementAllowed()) {
bottomBlockPos = new Vector3i(primePos.x, primePos.y - 1, primePos.z);
topBlockPos = primePos;
} else if (aboveBlock.isReplacementAllowed()) {
bottomBlockPos = primePos;
topBlockPos = new Vector3i(primePos.x, primePos.y + 1, primePos.z);
} else {
event.consume();
return;
}
Side attachSide = determineAttachSide(facingDir, offsetDir, bottomBlockPos, topBlockPos);
if (attachSide == null) {
event.consume();
return;
}
Side closedSide = facingDir.reverse();
if (closedSide == attachSide || closedSide.reverse() == attachSide) {
closedSide = attachSide.yawClockwise(1);
}
Block newBottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
Block newTopBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, bottomBlockPos, closedSide, Side.TOP);
Map<Vector3i, Block> blockMap = new HashMap<>();
blockMap.put(bottomBlockPos, newBottomBlock);
blockMap.put(topBlockPos, newTopBlock);
PlaceBlocks blockEvent = new PlaceBlocks(blockMap, event.getInstigator());
worldProvider.getWorldEntity().send(blockEvent);
if (!blockEvent.isConsumed()) {
EntityRef newDoor = entityManager.create(door.doorRegionPrefab);
entity.removeComponent(MeshComponent.class);
newDoor.addComponent(new BlockRegionComponent(Region3i.createBounded(bottomBlockPos, topBlockPos)));
Vector3f doorCenter = bottomBlockPos.toVector3f();
doorCenter.y += 0.5f;
newDoor.addComponent(new LocationComponent(doorCenter));
DoorComponent newDoorComp = newDoor.getComponent(DoorComponent.class);
newDoorComp.closedSide = closedSide;
newDoorComp.openSide = attachSide.reverse();
newDoorComp.isOpen = false;
newDoor.saveComponent(newDoorComp);
newDoor.send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
logger.info("Closed Side: {}", newDoorComp.closedSide);
logger.info("Open Side: {}", newDoorComp.openSide);
newDoor.send(new DoorPlacedEvent(event.getInstigator()));
}
}
use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.
the class TreeGeneratorLSystem method generate.
@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);
}
Aggregations