use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class TelemetrySystem method recordDistanceTraveled.
private void recordDistanceTraveled() {
Vector3f position = localPlayer.getPosition(new Vector3f());
float distanceMoved = position.distance(previousPos);
gamePlayStatsComponent.distanceTraveled += distanceMoved;
previousPos.set(position);
localPlayer.getCharacterEntity().addOrSaveComponent(gamePlayStatsComponent);
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class BlockSelectionRenderer method buildBlockMesh.
private static void buildBlockMesh(StandardMeshData mesh, float size, Rectanglef texRect, Colorc c) {
Vector3f pos = new Vector3f();
Vector3f norm = new Vector3f();
Vector2f texCoord = new Vector2f();
final float sizeHalf = size / 2;
int firstIndex = mesh.position.getPosition();
// top
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(0, 1.0f, 0));
mesh.color0.put(c);
}
// left
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.minY, texRect.minY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(-1.0f, 0, 0));
mesh.color0.put(c);
}
// right
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(1.0f, 0, 0));
mesh.color0.put(c);
}
// back
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(0, 0, -1.0f));
mesh.color0.put(c);
}
// front
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, sizeHalf, sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.minY, texRect.minY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(0, 0, 1.0f));
mesh.color0.put(c);
}
// bottom
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, -sizeHalf));
mesh.position.put(pos.zero().add(sizeHalf, -sizeHalf, sizeHalf));
mesh.position.put(pos.zero().add(-sizeHalf, -sizeHalf, sizeHalf));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.minY));
mesh.uv0.put(texCoord.set(texRect.maxX, texRect.maxY));
mesh.uv0.put(texCoord.set(texRect.minX, texRect.maxY));
for (int i = 0; i < 4; i++) {
mesh.normal.put(norm.set(0, -1, 0f));
mesh.color0.put(c);
}
int lastIndex = mesh.position.getPosition();
for (int i = firstIndex; i < lastIndex - 2; i += 4) {
mesh.indices.put(i);
mesh.indices.put(i + 1);
mesh.indices.put(i + 2);
mesh.indices.put(i + 2);
mesh.indices.put(i + 3);
mesh.indices.put(i);
}
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class TessellatorHelper method addGUIQuadMesh.
public static void addGUIQuadMesh(Tessellator tessellator, Vector4f color, float sizeX, float sizeY) {
tessellator.resetParams();
tessellator.setColor(new Vector4f(color.x, color.y, color.z, color.w));
tessellator.setUseLighting(false);
tessellator.setUseNormals(false);
tessellator.addPoly(new Vector3f[] { new Vector3f(0, 0, 0), new Vector3f(sizeX, 0, 0), new Vector3f(sizeX, sizeY, 0), new Vector3f(0, sizeY, 0) }, new Vector2f[] { new Vector2f(0, 0), new Vector2f(1, 0), new Vector2f(1, 1), new Vector2f(0, 1) });
tessellator.setUseLighting(true);
tessellator.setUseNormals(true);
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class NetClient method sendNewChunks.
private void sendNewChunks(NetData.NetMessage.Builder message) {
if (!readyChunks.isEmpty()) {
chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
if (chunkSendCounter > 1.0f) {
chunkSendCounter -= 1.0f;
Vector3i center = new Vector3i();
LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
if (loc != null) {
Vector3f target = loc.getWorldPosition(new Vector3f());
if (target.isFinite()) {
// use center as temporary variable
center.set(target, RoundingMode.HALF_UP);
// update center to chunkPos
Chunks.toChunkPos(center, center);
}
}
Vector3i pos = null;
long distance = Integer.MAX_VALUE;
for (Vector3i chunkPos : readyChunks.keySet()) {
long chunkDistance = chunkPos.distanceSquared(center);
if (pos == null || chunkDistance < distance) {
pos = chunkPos;
distance = chunkDistance;
}
}
Chunk chunk = readyChunks.remove(pos);
relevantChunks.add(pos);
message.addChunkInfo(chunk.encode());
}
} else {
chunkSendCounter = 1.0f;
}
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class Bone method getLocalPosition.
public Vector3f getLocalPosition() {
Vector3f result = new Vector3f();
relativeTransform.transformPosition(result);
return result;
}
Aggregations