Search in sources :

Example 11 with Vector3fc

use of org.joml.Vector3fc in project Terasology by MovingBlocks.

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3ic minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3fc storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3ic viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3fc spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : Vector3fc(org.joml.Vector3fc) PlayerStore(org.terasology.engine.persistence.PlayerStore) Vector3ic(org.joml.Vector3ic) Client(org.terasology.engine.network.Client) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 12 with Vector3fc

use of org.joml.Vector3fc in project chunkstories by Hugobros3.

the class ChunkMeshesRenderer method updatePVSSet.

@Override
public void updatePVSSet(CameraInterface camera) {
    // Updates these once
    cameraChunkX = Math2.floor((camera.getCameraPosition().x()) / 32f);
    cameraChunkY = Math2.floor((camera.getCameraPosition().y()) / 32f);
    cameraChunkZ = Math2.floor((camera.getCameraPosition().z()) / 32f);
    Vector3fc cameraFloatPosition = new Vector3f((float) camera.getCameraPosition().x(), (float) camera.getCameraPosition().y(), (float) camera.getCameraPosition().z());
    // Do a floodfill arround the entity
    List<ClientChunk> floodFillResults = floodFillArround(cameraFloatPosition, (int) world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance") / 32);
    culledChunksNormal.clear();
    // Check they have render data & submit them if they don't
    for (ClientChunk chunk : floodFillResults) {
        ChunkRenderCommand command = new ChunkRenderCommand(chunk, camera.getCameraPosition());
        // Cull against the camera, security to always render the chunk we're on
        boolean shouldShowChunk = chunk.getChunkX() == cameraChunkX && chunk.getChunkY() == cameraChunkY && chunk.getChunkZ() == cameraChunkZ;
        if (!shouldShowChunk) {
            Vector3f center = new Vector3f(command.displayWorldX + 16, command.displayWorldY + 16, command.displayWorldZ + 16);
            shouldShowChunk = camera.isBoxInFrustrum(center, new Vector3f(32, 32, 32));
        }
        if (shouldShowChunk)
            culledChunksNormal.add(command);
    }
    culledChunksShadow = updateShadowPVS(camera.getCameraPosition());
}
Also used : Vector3fc(org.joml.Vector3fc) Vector3f(org.joml.Vector3f) ClientChunk(io.xol.chunkstories.world.chunk.ClientChunk)

Example 13 with Vector3fc

use of org.joml.Vector3fc in project Terasology by MovingBlocks.

the class PlayerSystem method setSpawnLocationOnRespawnRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
    ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
    EntityRef character = clientComponent.character;
    EntityRef clientInfo = clientComponent.clientInfo;
    Vector3fc spawnPosition;
    if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
        spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
    } else {
        spawnPosition = worldGenerator.getSpawnPosition(entity);
    }
    LocationComponent loc = character.getComponent(LocationComponent.class);
    loc.setWorldPosition(spawnPosition);
    // reset rotation
    loc.setLocalRotation(new Quaternionf());
    character.saveComponent(loc);
}
Also used : Vector3fc(org.joml.Vector3fc) Quaternionf(org.joml.Quaternionf) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 14 with Vector3fc

use of org.joml.Vector3fc in project Terasology by MovingBlocks.

the class VertexAttributeBindingTest method testPutAllBindingVector.

@Test
public void testPutAllBindingVector() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    builder.build();
    a1.put(new Vector3fc[] { new Vector3f(10, 5, 2), new Vector3f(2, 15, 2), new Vector3f(1, 5, 13), new Vector3f(1, 1, 1) });
    VectorAssert.assertEquals(new Vector3f(10, 5, 2), a1.get(0, new Vector3f()), 0.001f);
    VectorAssert.assertEquals(new Vector3f(2, 15, 2), a1.get(1, new Vector3f()), 0.001f);
    VectorAssert.assertEquals(new Vector3f(1, 5, 13), a1.get(2, new Vector3f()), 0.001f);
    VectorAssert.assertEquals(new Vector3f(1, 1, 1), a1.get(3, new Vector3f()), 0.001f);
}
Also used : Vector3fc(org.joml.Vector3fc) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 15 with Vector3fc

use of org.joml.Vector3fc in project Terasology by MovingBlocks.

the class VertexResourceTest method testPutWithBufferedResource.

@Test
public void testPutWithBufferedResource() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource firstResource = builder.build();
    a1.put(new Vector3f(12.0f, 0.0f, 13.0f));
    a1.put(new Vector3f(12.5f, 13f, 1.5f));
    builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> b2 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource secondResource = builder.build();
    b2.put(new Vector3f(13.0f, 0.0f, 1.5f));
    firstResource.put(secondResource);
    assertEquals(3, a1.elements());
    VectorAssert.assertEquals(new Vector3f(12.0f, 0.0f, 13.0f), a1.get(0, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(12.5f, 13f, 1.5f), a1.get(1, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(13.0f, 0.0f, 1.5f), a1.get(2, new Vector3f()), .0001f);
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Aggregations

Vector3fc (org.joml.Vector3fc)19 Vector3f (org.joml.Vector3f)15 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)7 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 LocationComponent (org.terasology.engine.logic.location.LocationComponent)4 FloatBuffer (java.nio.FloatBuffer)2 Matrix4f (org.joml.Matrix4f)2 Quaternionf (org.joml.Quaternionf)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)2 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)2 Color (org.terasology.nui.Color)2 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)1 com.badlogic.gdx.physics.bullet.collision.btCapsuleShape (com.badlogic.gdx.physics.bullet.collision.btCapsuleShape)1 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)1 com.badlogic.gdx.physics.bullet.collision.btCylinderShape (com.badlogic.gdx.physics.bullet.collision.btCylinderShape)1 com.badlogic.gdx.physics.bullet.collision.btManifoldPoint (com.badlogic.gdx.physics.bullet.collision.btManifoldPoint)1 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)1 ItemOverlay (io.xol.chunkstories.api.item.interfaces.ItemOverlay)1