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);
});
}
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))));
}
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))));
}
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);
}
}
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);
}
}
Aggregations