use of org.joml.Vector2fc in project Terasology by MovingBlocks.
the class VertexGLAttributeTest method testVector2fBinding.
@Test
public void testVector2fBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector2fc, Vector2f> a1 = builder.add(0, GLAttributes.VECTOR_2_F_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.put(new Vector2f(10, 150));
a1.put(new Vector2f(15.1f, 15.04f));
a1.put(new Vector2f(16f, 150));
assertEquals(3, a1.getPosition());
int stride = Float.BYTES * 2;
resource.writeBuffer(buffer -> {
assertEquals(3 * 2 * Float.BYTES, buffer.limit());
assertEquals(10, buffer.getFloat(Float.BYTES * 0), 0.001f);
assertEquals(150, buffer.getFloat(Float.BYTES * 1), 0.001f);
assertEquals(15.1f, buffer.getFloat((stride) + Float.BYTES * 0), 0.001f);
assertEquals(15.04f, buffer.getFloat((stride) + Float.BYTES * 1), 0.001f);
assertEquals(16f, buffer.getFloat((stride * 2) + Float.BYTES * 0), 0.001f);
assertEquals(150f, buffer.getFloat((stride * 2) + Float.BYTES * 1), 0.001f);
});
}
use of org.joml.Vector2fc 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();
}
Aggregations