Search in sources :

Example 1 with Vector3fc

use of org.joml.Vector3fc in project chunkstories-core by Hugobros3.

the class EntityPlayer method drawEntityOverlay.

@Override
public void drawEntityOverlay(RenderingInterface renderer) {
    // super.drawEntityOverlay(renderer);
    if (this.equals(((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity())) {
        float scale = 2.0f;
        renderer.textures().getTexture("./textures/gui/hud/hud_survival.png").setLinearFiltering(false);
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 256 * 0.5f * scale, 64 + 64 + 16 - 32 * 0.5f * scale, 256 * scale, 32 * scale, 0, 32f / 256f, 1, 0, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, null);
        // Health bar
        int horizontalBitsToDraw = (int) (8 + 118 * Math2.clamp(getHealth() / getMaxHealth(), 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 128 * scale, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0, 64f / 256f, horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // Food bar
        horizontalBitsToDraw = (int) (0 + 126 * Math2.clamp(getFoodLevel() / 100f, 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 + 0 * 128 * scale + 0, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0.5f, 64f / 256f, 0.5f + horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // If we're using an item that can render an overlay
        if (this.getSelectedItemComponent().getSelectedItem() != null) {
            ItemPile pile = this.getSelectedItemComponent().getSelectedItem();
            if (pile.getItem() instanceof ItemOverlay)
                ((ItemOverlay) pile.getItem()).drawItemOverlay(renderer, pile);
        }
        // We don't want to render our own tag do we ?
        return;
    }
    // Renders the nametag above the player heads
    Vector3d pos = getLocation();
    // don't render tags too far out
    if (pos.distance(renderer.getCamera().getCameraPosition()) > 32f)
        return;
    // Don't render a dead player tag
    if (this.getHealth() <= 0)
        return;
    Vector3fc posOnScreen = renderer.getCamera().transform3DCoordinate(new Vector3f((float) (double) pos.x(), (float) (double) pos.y() + 2.0f, (float) (double) pos.z()));
    float scale = posOnScreen.z();
    // + rotH;
    String txt = name.getName();
    float dekal = renderer.getFontRenderer().defaultFont().getWidth(txt) * 16 * scale;
    // System.out.println("dekal"+dekal);
    if (scale > 0)
        renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), posOnScreen.x() - dekal / 2, posOnScreen.y(), txt, 16 * scale, 16 * scale, new Vector4f(1, 1, 1, 1));
}
Also used : Vector3fc(org.joml.Vector3fc) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) ItemOverlay(io.xol.chunkstories.api.item.interfaces.ItemOverlay) Vector3f(org.joml.Vector3f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 2 with Vector3fc

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

the class VertexResourceTest method testInterleave.

@Test
public void testInterleave() {
    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.put(new Vector3f(10, 0, -4));
    a2.put(UnsignedBytes.checkedCast(2));
    a2.put(UnsignedBytes.checkedCast(10));
    assertEquals(2, a2.getPosition());
    assertEquals(1, a1.getPosition());
    int stride = (Float.BYTES * 3) + Byte.BYTES;
    resource.writeBuffer(buffer -> {
        assertEquals(buffer.limit(), stride * 2);
        assertEquals(10, buffer.getFloat((0 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat((1 * Float.BYTES)), 0.001f);
        assertEquals(-4, buffer.getFloat(2 * Float.BYTES), 0.001f);
        assertEquals(2, buffer.get((3 * Float.BYTES)));
        assertEquals(0, buffer.getFloat(stride + (0 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat(stride + (1 * Float.BYTES)), 0.001f);
        assertEquals(0, buffer.getFloat(stride + (2 * Float.BYTES)), 0.001f);
        assertEquals(10, buffer.get(stride + (3 * Float.BYTES)));
    });
}
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 3 with Vector3fc

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

the class VertexResourceTest method testReplaceBufferedResource.

@Test
public void testReplaceBufferedResource() {
    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.replace(secondResource);
    assertEquals(1, a1.elements());
    VectorAssert.assertEquals(new Vector3f(13.0f, 0.0f, 1.5f), a1.get(0, 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) Test(org.junit.Test)

Example 4 with Vector3fc

use of org.joml.Vector3fc 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 5 with Vector3fc

use of org.joml.Vector3fc 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)

Aggregations

Vector3fc (org.joml.Vector3fc)19 Vector3f (org.joml.Vector3f)15 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)7 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 LocationComponent (org.terasology.engine.logic.location.LocationComponent)4 FloatBuffer (java.nio.FloatBuffer)2 Matrix4f (org.joml.Matrix4f)2 Quaternionf (org.joml.Quaternionf)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)2 VertexByteAttributeBinding (org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding)2 Color (org.terasology.nui.Color)2 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)1 com.badlogic.gdx.physics.bullet.collision.btCapsuleShape (com.badlogic.gdx.physics.bullet.collision.btCapsuleShape)1 com.badlogic.gdx.physics.bullet.collision.btConvexHullShape (com.badlogic.gdx.physics.bullet.collision.btConvexHullShape)1 com.badlogic.gdx.physics.bullet.collision.btCylinderShape (com.badlogic.gdx.physics.bullet.collision.btCylinderShape)1 com.badlogic.gdx.physics.bullet.collision.btManifoldPoint (com.badlogic.gdx.physics.bullet.collision.btManifoldPoint)1 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)1 ItemOverlay (io.xol.chunkstories.api.item.interfaces.ItemOverlay)1