use of org.joml.Vector3fc in project Terasology by MovingBlocks.
the class VertexResourceTest method testReserveVertexResource.
@Test
public void testReserveVertexResource() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.reserve(10);
a1.put(new Vector3f(10, 10, 10));
a1.put(new Vector3f(5, 10, 10));
a1.put(new Vector3f(15, 10, 10));
assertEquals(3, a1.getPosition());
resource.writeBuffer(buffer -> {
assertNotNull(buffer);
assertEquals(Float.BYTES * 3 * 10, buffer.capacity());
assertEquals(Float.BYTES * 3 * 3, buffer.limit());
int index = 0;
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(5.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(15.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
assertEquals(10.0f, buffer.getFloat((index++) * Float.BYTES), 0.001f);
});
}
use of org.joml.Vector3fc in project Terasology by MovingBlocks.
the class Mesh method getBound.
protected AABBf getBound(AABBf dest) {
VertexAttributeBinding<Vector3fc, Vector3f> vertices = this.vertices();
if (elementCount() == 0) {
dest.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
return dest;
}
Vector3f pos = new Vector3f();
for (int x = 0; x < elementCount(); x++) {
dest.union(vertices.get(x, pos));
}
return dest;
}
use of org.joml.Vector3fc in project Terasology by MovingBlocks.
the class AABBRenderer method generateDisplayListSolid.
private void generateDisplayListSolid() {
MeshBuilder builder = new MeshBuilder();
builder.addBox(aabb.extent(new Vector3f()).mul(-1.0f), aabb.extent(new Vector3f()).mul(2.0f), 0.0f, 0.0f).setTextureMapper(new MeshBuilder.TextureMapper() {
@Override
public void initialize(Vector3fc offset, Vector3fc size) {
}
@Override
public Vector2fc map(int vertexIndex, float u, float v) {
switch(vertexIndex) {
// Front face
case 0:
return new Vector2f(0f, 1f);
case 1:
return new Vector2f(1f, 1f);
case 2:
return new Vector2f(1f, 1);
case 3:
return new Vector2f(0f, 1);
// Back face
case 4:
return new Vector2f(1f, 1f);
case 5:
return new Vector2f(1f, 1);
case 6:
return new Vector2f(0f, 1);
case 7:
return new Vector2f(0f, 1f);
// Top face
case 8:
return new Vector2f(1f, 0f);
case 9:
return new Vector2f(1f, 1f);
case 10:
return new Vector2f(0f, 1f);
case 11:
return new Vector2f(0f, 0f);
// Bottom face
case 12:
return new Vector2f(1f, 0f);
case 13:
return new Vector2f(0f, 0f);
case 14:
return new Vector2f(0f, 1f);
case 15:
return new Vector2f(1f, 1f);
// Right face
case 16:
return new Vector2f(1f, 1f);
case 17:
return new Vector2f(1f, 1);
case 18:
return new Vector2f(0f, 1);
case 19:
return new Vector2f(0f, 1f);
// Left face
case 20:
return new Vector2f(0f, 0f);
case 21:
return new Vector2f(1f, 0f);
case 22:
return new Vector2f(1f, 1.0f);
case 23:
return new Vector2f(0f, 1.0f);
default:
throw new RuntimeException("Unreachable state.");
}
}
});
for (int x = 0; x < 24; x++) {
builder.addColor(new Color(solidColor.x, solidColor.y, solidColor.z, solidColor.w));
}
solidMesh = builder.build();
}
use of org.joml.Vector3fc in project Terasology by MovingBlocks.
the class FloatingTextRenderer method render.
private void render(Iterable<EntityRef> floatingTextEntities) {
Vector3fc cameraPosition = camera.getPosition();
Matrix4f model = new Matrix4f();
Matrix4f modelView = new Matrix4f();
Vector3f worldPos = new Vector3f();
for (EntityRef entity : floatingTextEntities) {
FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null) {
logger.warn("location component is not defined can't render text: {}", floatingText.text);
continue;
}
location.getWorldPosition(worldPos);
if (!worldProvider.isBlockRelevant(worldPos) || !worldPos.isFinite()) {
continue;
}
String[] linesOfText = floatingText.text.split("\n");
Color baseColor = floatingText.textColor;
Color shadowColor = floatingText.textShadowColor;
boolean underline = false;
int textWidth = 0;
for (String singleLine : linesOfText) {
if (font.getWidth(singleLine) > textWidth) {
textWidth = font.getWidth(singleLine);
}
}
FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
if (meshMap == null) {
meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
entityMeshCache.put(entity, meshMap);
}
if (floatingText.isOverlay) {
glDisable(GL_DEPTH_TEST);
}
float scale = METER_PER_PIXEL * floatingText.scale;
model.setTranslation(worldPos.sub(cameraPosition));
modelView.set(camera.getViewMatrix()).mul(model).m00(1.0f).m10(0.0f).m20(0.0f).m01(0.0f).m11(1.0f).m21(0.0f).m02(0.0f).m12(0.0f).m22(1.0f);
modelView.scale(scale, -scale, scale);
modelView.translate(-textWidth / 2.0f, 0.0f, 0.0f);
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
Material material = meshMapEntry.getKey();
material.enable();
material.bindTextures();
material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
material.setMatrix4("modelViewMatrix", modelView);
material.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
material.setFloat2("offset", 0.0f, 0.0f);
material.setFloat("alpha", 1.0f);
mesh.render();
}
// Revert to default state
if (floatingText.isOverlay) {
glEnable(GL_DEPTH_TEST);
}
}
}
Aggregations