Search in sources :

Example 6 with Vector2f

use of org.joml.Vector2f 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);
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Vector2fc(org.joml.Vector2fc) Vector2f(org.joml.Vector2f) Test(org.junit.Test)

Example 7 with Vector2f

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

the class ZoomableLayoutTest method testZoomOut.

@Test
public void testZoomOut() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom out 2x from top left corner
    zoomableLayout.zoom(2, 2, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size doubled
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2)));
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 8 with Vector2f

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

the class ZoomableLayoutTest method testScaling.

@Test
public void testScaling() throws Exception {
    zoomableLayout.onDraw(canvas);
    // world size scaled to fit ratio of screen size - world size now 200 x 100
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2, WORLD_HEIGHT));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2), CANVAS_HEIGHT / WORLD_HEIGHT));
    // coordinates on widgets scaled down by half
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x / 2), ceilToInt(pos1.y / 2)), new Vector2i(ceilToInt((pos1.x + size1.x) / 2), ceilToInt((pos1.y + size1.y) / 2))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x / 2), ceilToInt(pos2.y / 2)), new Vector2i(ceilToInt((pos2.x + size2.x) / 2), ceilToInt((pos2.y + size2.y) / 2))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 2), ceilToInt(pos3.y / 2)), new Vector2i(ceilToInt((pos3.x + size3.x) / 2), ceilToInt((pos3.y + size3.y) / 2))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 9 with Vector2f

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

the class BehaviorEditor method copyNode.

public void copyNode(RenderableNode node) {
    BehaviorTreeBuilder treeBuilder = CoreRegistry.get(BehaviorTreeBuilder.class);
    String json = treeBuilder.toJson(node.getNode());
    BehaviorNode nodeCopy = treeBuilder.fromJson(json);
    List<RenderableNode> renderables = createRenderables(nodeCopy);
    if (renderables.size() > 0) {
        newNode = renderables.get(0);
        Vector2f oldPos = new Vector2f(newNode.getPosition());
        layout(newNode);
        oldPos.sub(newNode.getPosition());
        newNode.move(oldPos);
    }
}
Also used : BehaviorTreeBuilder(org.terasology.engine.logic.behavior.core.BehaviorTreeBuilder) Vector2f(org.joml.Vector2f) BehaviorNode(org.terasology.engine.logic.behavior.core.BehaviorNode)

Example 10 with Vector2f

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

the class RenderableNode method move.

public void move(Vector2f diff) {
    position = new Vector2f(position);
    position.add(diff);
    for (RenderableNode child : children) {
        child.move(diff);
    }
}
Also used : Vector2f(org.joml.Vector2f)

Aggregations

Vector2f (org.joml.Vector2f)47 Vector3f (org.joml.Vector3f)13 Test (org.junit.jupiter.api.Test)6 Vector2i (org.joml.Vector2i)5 Vector4f (org.joml.Vector4f)5 Rectanglei (org.terasology.joml.geom.Rectanglei)5 Rectanglef (org.terasology.joml.geom.Rectanglef)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Vector3i (org.joml.Vector3i)3 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)3 Name (org.terasology.gestalt.naming.Name)3 Vector2fc (org.joml.Vector2fc)2 Vector3d (org.joml.Vector3d)2 MeshBuilder (org.terasology.engine.rendering.assets.mesh.MeshBuilder)2 TFloatList (gnu.trove.list.TFloatList)1 TObjectIntMap (gnu.trove.map.TObjectIntMap)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 Location (io.xol.chunkstories.api.Location)1 Controller (io.xol.chunkstories.api.entity.Controller)1