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));
}
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations