use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayoutTest method setup.
@Before
public void setup() {
zoomableLayout = new ZoomableLayout();
item1 = mock(ZoomableLayout.PositionalWidget.class);
item2 = mock(ZoomableLayout.PositionalWidget.class);
item3 = mock(ZoomableLayout.PositionalWidget.class);
canvas = mock(Canvas.class);
//
// +------+
// | 1 |
// +------+
// +-+
// |2|
// +-+
//
// +---+
// | 3 |
// | |
// +---+
// positions of the widgets in the world
pos1 = new Vector2f(10, 10);
pos2 = new Vector2f(40, 40);
pos3 = new Vector2f(80, 70);
when(item1.getPosition()).thenReturn(pos1);
when(item2.getPosition()).thenReturn(pos2);
when(item3.getPosition()).thenReturn(pos3);
// size of widgets
size1 = new Vector2f(20, 10);
size2 = new Vector2f(5, 10);
size3 = new Vector2f(10, 20);
when(item1.getSize()).thenReturn(size1);
when(item2.getSize()).thenReturn(size2);
when(item3.getSize()).thenReturn(size3);
when(item1.isVisible()).thenReturn(true);
when(item2.isVisible()).thenReturn(true);
when(item3.isVisible()).thenReturn(true);
Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
when(canvas.size()).thenReturn(availableSize);
zoomableLayout.setWindowSize(new Vector2f(WORLD_WIDTH, WORLD_HEIGHT));
zoomableLayout.addWidget(item1);
zoomableLayout.addWidget(item2);
zoomableLayout.addWidget(item3);
}
use of org.terasology.math.geom.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, Rect2i.createFromMinAndMax(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, Rect2i.createFromMinAndMax(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, Rect2i.createFromMinAndMax(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.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class ZoomableLayoutTest method testZoomInAndDrag.
@Test
public void testZoomInAndDrag() throws Exception {
zoomableLayout.onDraw(canvas);
// zoom in 2x towards left top corner
zoomableLayout.zoom(0.5f, 0.5f, new Vector2i(0, 0));
zoomableLayout.onDraw(canvas);
// world size halved
assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH, WORLD_HEIGHT / 2));
assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / WORLD_WIDTH, CANVAS_HEIGHT / (WORLD_HEIGHT / 2)));
verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x), ceilToInt(pos1.y)), new Vector2i(ceilToInt(pos1.x + size1.x), ceilToInt(pos1.y + size1.y))));
verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos2.x), ceilToInt(pos2.y)), new Vector2i(ceilToInt(pos2.x + size2.x), ceilToInt(pos2.y + size2.y))));
verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x), ceilToInt(pos3.y)), new Vector2i(ceilToInt(pos3.x + size3.x), ceilToInt(pos3.y + size3.y))));
// simulate drag to item2
zoomableLayout.setWindowPosition(pos2);
zoomableLayout.onDraw(canvas);
// item1 out of canvas
verify(canvas).drawWidget(item1, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos1.x - pos2.x), ceilToInt(pos1.y - pos2.y)), new Vector2i(ceilToInt(pos1.x + size1.x - pos2.x), ceilToInt(pos1.y + size1.y - pos2.y))));
verify(canvas).drawWidget(item2, Rect2i.createFromMinAndMax(Vector2i.zero(), new Vector2i(ceilToInt(size2.x), ceilToInt(size2.y))));
verify(canvas).drawWidget(item3, Rect2i.createFromMinAndMax(new Vector2i(ceilToInt(pos3.x - pos2.x), ceilToInt(pos3.y - pos2.y)), new Vector2i(ceilToInt(pos3.x + size3.x - pos2.x), ceilToInt(pos3.y + size3.y - pos2.y))));
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class Port method mid.
public Vector2f mid() {
Vector2f mid = new Vector2f(rect.size());
mid.scale(0.5f);
mid.add(rect.min());
return mid;
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class PerlinBaseSurfaceProvider method setSeed.
@Override
public void setSeed(long seed) {
BrownianNoise source = new BrownianNoise(new PerlinNoise(seed), 8);
surfaceNoise = new SubSampledNoise(source, new Vector2f(0.004f, 0.004f), SAMPLE_RATE);
}
Aggregations