Search in sources :

Example 36 with Vector3f

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

the class VertexResourceTest method testAllocation.

@Test
public void testAllocation() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.allocate(10);
    int stride = (Float.BYTES * 3) + Byte.BYTES;
    resource.writeBuffer(buffer -> {
        assertEquals(buffer.limit(), stride * 10);
        assertEquals(buffer.capacity(), stride * 10);
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) Vector3fc(org.joml.Vector3fc) VertexByteAttributeBinding(org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector3f(org.joml.Vector3f) Test(org.junit.Test)

Example 37 with Vector3f

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

the class VertexResourceTest method testPutWithByteBuffer.

@Test
public void testPutWithByteBuffer() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    ByteBuffer buffer = BufferUtils.createByteBuffer(Float.BYTES * 6);
    buffer.putFloat(0 * Float.BYTES, 12.0f);
    buffer.putFloat(1 * Float.BYTES, 20.0f);
    buffer.putFloat(2 * Float.BYTES, 50.0f);
    buffer.putFloat(3 * Float.BYTES, 25.0f);
    buffer.putFloat(4 * Float.BYTES, 15.0f);
    buffer.putFloat(5 * Float.BYTES, 1.5f);
    resource.put(buffer);
    resource.put(buffer);
    assertEquals(4, a1.elements());
    VectorAssert.assertEquals(new Vector3f(12.0f, 20.0f, 50.0f), a1.get(0, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(25.0f, 15.0f, 1.5f), a1.get(1, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(12.0f, 20.0f, 50.0f), a1.get(2, new Vector3f()), .0001f);
    VectorAssert.assertEquals(new Vector3f(25.0f, 15.0f, 1.5f), a1.get(3, 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) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 38 with Vector3f

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

the class VertexGLAttributeTest method testVector3fBinding.

@Test
public void testVector3fBinding() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(new Vector3f(10, 150, 1.5f));
    a1.put(new Vector3f(15.1f, 15.04f, 15.5f));
    a1.put(new Vector3f(16f, 150, 31.5f));
    assertEquals(3, a1.getPosition());
    int stride = Float.BYTES * 3;
    resource.writeBuffer(buffer -> {
        assertEquals(3 * 3 * Float.BYTES, buffer.limit());
        assertEquals(10, buffer.getFloat(Float.BYTES * 0), 0.001f);
        assertEquals(150, buffer.getFloat(Float.BYTES * 1), 0.001f);
        assertEquals(1.5f, buffer.getFloat(Float.BYTES * 2), 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(15.5f, buffer.getFloat((stride) + Float.BYTES * 2), 0.001f);
        assertEquals(16f, buffer.getFloat((stride * 2) + Float.BYTES * 0), 0.001f);
        assertEquals(150f, buffer.getFloat((stride * 2) + Float.BYTES * 1), 0.001f);
        assertEquals(31.5f, buffer.getFloat((stride * 2) + Float.BYTES * 2), 0.001f);
    });
}
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)

Example 39 with Vector3f

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

the class ChunkTest method testGetAabb.

@Test
public void testGetAabb() {
    AABBfc aabb = chunk.getAABB();
    assertEquals(new Vector3f(-.5f, -.5f, -.5f), new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ()));
    assertEquals(new Vector3f(Chunks.SIZE_X - .5f, Chunks.SIZE_Y - .5f, Chunks.SIZE_Z - .5f), new Vector3f(aabb.maxX(), aabb.maxY(), aabb.maxZ()));
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Vector3f(org.joml.Vector3f) Test(org.junit.jupiter.api.Test)

Example 40 with Vector3f

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

the class ByteCodeReflectFactoryTest method testCreateFieldAccessorWithGetterSetter.

@Test
public void testCreateFieldAccessorWithGetterSetter() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor<GetterSetterComponent, Vector3f> fieldAccessor = reflectFactory.createFieldAccessor(GetterSetterComponent.class, GetterSetterComponent.class.getDeclaredField("value"), Vector3f.class);
    GetterSetterComponent comp = new GetterSetterComponent();
    Vector3f newVal = new Vector3f(1, 2, 3);
    fieldAccessor.setValue(comp, newVal);
    assertTrue(comp.setterUsed);
    assertEquals(newVal, fieldAccessor.getValue(comp));
    assertTrue(comp.getterUsed);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) Vector3f(org.joml.Vector3f) GetterSetterComponent(org.terasology.unittest.stubs.GetterSetterComponent) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8