Search in sources :

Example 36 with Vector2f

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);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Canvas(org.terasology.rendering.nui.Canvas) Vector2i(org.terasology.math.geom.Vector2i) Before(org.junit.Before)

Example 37 with Vector2f

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))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 38 with Vector2f

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))));
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) Vector2i(org.terasology.math.geom.Vector2i) Test(org.junit.Test)

Example 39 with Vector2f

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;
}
Also used : Vector2f(org.terasology.math.geom.Vector2f)

Example 40 with Vector2f

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);
}
Also used : Vector2f(org.terasology.math.geom.Vector2f) SubSampledNoise(org.terasology.utilities.procedural.SubSampledNoise) PerlinNoise(org.terasology.utilities.procedural.PerlinNoise) BrownianNoise(org.terasology.utilities.procedural.BrownianNoise)

Aggregations

Vector2f (org.terasology.math.geom.Vector2f)41 Vector3f (org.terasology.math.geom.Vector3f)8 IOException (java.io.IOException)5 TIntList (gnu.trove.list.TIntList)4 Vector2i (org.terasology.math.geom.Vector2i)4 TFloatList (gnu.trove.list.TFloatList)3 Map (java.util.Map)3 Test (org.junit.Test)3 Name (org.terasology.naming.Name)3 SubtextureData (org.terasology.rendering.assets.texture.subtexture.SubtextureData)3 BrownianNoise (org.terasology.utilities.procedural.BrownianNoise)3 PerlinNoise (org.terasology.utilities.procedural.PerlinNoise)3 SubSampledNoise (org.terasology.utilities.procedural.SubSampledNoise)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 InputStream (java.io.InputStream)2 Vector4f (org.terasology.math.geom.Vector4f)2 Bone (org.terasology.rendering.assets.skeletalmesh.Bone)2 BoneWeight (org.terasology.rendering.assets.skeletalmesh.BoneWeight)2 SkeletalMeshDataBuilder (org.terasology.rendering.assets.skeletalmesh.SkeletalMeshDataBuilder)2 BlockAppearance (org.terasology.world.block.BlockAppearance)2