Search in sources :

Example 71 with Vector3f

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());
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 72 with Vector3f

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);
    }
}
Also used : Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Example 73 with Vector3f

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);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) Vector3f(org.joml.Vector3f) GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) Test(org.junit.jupiter.api.Test)

Example 74 with Vector3f

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");
}
Also used : Vector3f(org.joml.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 75 with Vector3f

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;
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) LocationComponent(org.terasology.engine.logic.location.LocationComponent) HashSet(java.util.HashSet)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8