use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class BlockEntitySystem method defaultDropsHandling.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
if (blockComponent.block != null) {
if (entity.hasComponent(BlockRegionComponent.class)) {
BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
if (blockComponent.dropBlocksInRegion) {
// loop through all the blocks in this region and drop them
for (Vector3ic location : blockRegion.region) {
Block blockInWorld = worldProvider.getBlock(location);
commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
}
} else {
// just drop the ActAsBlock block
Vector3i location = new Vector3i(blockRegion.region.center(new Vector3f()), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
} else if (entity.hasComponent(LocationComponent.class)) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
Vector3i location = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.HALF_UP);
commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
}
}
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class BlockItemSystem method getSideHitPosition.
/**
* Returns the position at which the block side was hit, relative to the side.
* <p/>
* The specified hit position is expected to be on the surface of the cubic block at the specified position.
* Example: The front side was hit right in the center. The result will be (0.5, 0.5), representing the relative hit
* position on the side's surface.
*
* @param hitPosition the hit position
* @param blockPosition the block position relative to its center (block (0, 0, 0) has block position (0.5, 0.5,
* 0.5))
* @return the 2D hit position relative to the side that was hit
*/
private Vector2f getSideHitPosition(Vector3fc hitPosition, Vector3fc blockPosition) {
float epsilon = 0.0001f;
Vector3f relativeHitPosition = new Vector3f(hitPosition).sub(blockPosition);
if (Math.abs(relativeHitPosition.x) > 0.5f - epsilon) {
return new Vector2f(relativeHitPosition.z, relativeHitPosition.y).add(0.5f, 0.5f);
} else if (Math.abs(relativeHitPosition.y) > 0.5f - epsilon) {
return new Vector2f(relativeHitPosition.x, relativeHitPosition.z).add(0.5f, 0.5f);
} else {
return new Vector2f(relativeHitPosition.x, relativeHitPosition.y).add(0.5f, 0.5f);
}
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class ByteCodeReflectFactoryTest method testCreateFieldAccessorWithGetterSetter.
@Test
public void testCreateFieldAccessorWithGetterSetter() throws Exception {
ReflectFactory reflectFactory = new ByteCodeReflectFactory();
FieldAccessor<GetterSetterComponent, Vector3f> fieldAccessor = reflectFactory.createFieldAccessor(GetterSetterComponent.class, GetterSetterComponent.class.getDeclaredField("value"), Vector3f.class);
GetterSetterComponent comp = new GetterSetterComponent();
Vector3f newVal = new Vector3f(1, 2, 3);
fieldAccessor.setValue(comp, newVal);
assertTrue(comp.setterUsed);
assertEquals(newVal, fieldAccessor.getValue(comp));
assertTrue(comp.getterUsed);
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class OpenALManager method updateListener.
@Override
public void updateListener(Vector3fc position, Quaternionfc orientation, Vector3fc velocity) {
AL10.alListener3f(AL10.AL_VELOCITY, velocity.x(), velocity.y(), velocity.z());
OpenALException.checkState("Setting listener velocity");
Vector3f dir = new Vector3f(Direction.FORWARD.asVector3f()).rotate(orientation);
Vector3f up = new Vector3f(Direction.UP.asVector3f()).rotate(orientation);
FloatBuffer listenerOri = BufferUtils.createFloatBuffer(6).put(new float[] { dir.x, dir.y, dir.z, up.x, up.y, up.z });
listenerOri.flip();
AL10.alListenerfv(AL10.AL_ORIENTATION, listenerOri);
OpenALException.checkState("Setting listener orientation");
listenerPosition.set(position);
AL10.alListener3f(AL10.AL_POSITION, position.x(), position.y(), position.z());
OpenALException.checkState("Setting listener position");
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class SectorUtil method getWatchedChunks.
/**
* Watched chunks are defined as the union of:
* <ul>
* <li>The chunk in which the {@link LocationComponent#getWorldPosition(Vector3f)} resides, if any</li>
* <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
* </ul>
*
* @param entity the entity to query the watched chunks of
* @return the set of positions of this entity's watched chunks
*/
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
Set<Vector3i> chunks = new HashSet<>();
LocationComponent loc = entity.getComponent(LocationComponent.class);
Vector3f position = loc.getWorldPosition(new Vector3f());
if (position.isFinite()) {
chunks.add(Chunks.toChunkPos(position, new Vector3i()));
}
SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
if (regionComponent != null) {
// potential leaky abstraction. component exposes its internal vectors
chunks.addAll(regionComponent.chunks);
}
return chunks;
}
Aggregations