Search in sources :

Example 1 with Point

use of pythagoras.f.Point in project playn by threerings.

the class LayerUtilTest method testTransformWithTrans.

@Test
public void testTransformWithTrans() {
    TestGroupLayer root = new TestGroupLayer();
    TestGroupLayer middle = new TestGroupLayer();
    TestLayer child = new TestLayer();
    root.add(middle);
    middle.add(child);
    middle.setTranslation(10, -10);
    Point point = new Point(100f, 100f);
    Point pointOnChild = new Point(0f, 0f);
    Layer.Util.screenToLayer(child, point, pointOnChild);
    assertEquals(point.x() - 10, pointOnChild.x(), tol);
    assertEquals(point.y() + 10, pointOnChild.y(), tol);
    Point pointOnParent = new Point(0f, 0f);
    Layer.Util.layerToScreen(child, pointOnChild, pointOnParent);
    assertEquals(point.x(), pointOnParent.x(), tol);
    assertEquals(point.y(), pointOnParent.y(), tol);
    root.clear();
}
Also used : Point(pythagoras.f.Point) Test(org.junit.Test)

Example 2 with Point

use of pythagoras.f.Point in project playn by threerings.

the class LayerUtilTest method testTransformWithRot.

@Test
public void testTransformWithRot() {
    TestGroupLayer root = new TestGroupLayer();
    TestGroupLayer middle = new TestGroupLayer();
    TestLayer child = new TestLayer();
    root.add(middle);
    middle.add(child);
    middle.setRotation((float) (Math.PI / 4.0));
    Point point = new Point(100f, 100f);
    Point pointOnChild = new Point(0f, 0f);
    Layer.Util.screenToLayer(child, point, pointOnChild);
    assertEquals(141.421356, pointOnChild.x(), tol);
    assertEquals(0, pointOnChild.y(), tol);
    Point pointOnParent = new Point(0f, 0f);
    Layer.Util.layerToScreen(child, pointOnChild, pointOnParent);
    assertEquals(point.x(), pointOnParent.x(), tol);
    assertEquals(point.y(), pointOnParent.y(), tol);
    root.clear();
}
Also used : Point(pythagoras.f.Point) Test(org.junit.Test)

Example 3 with Point

use of pythagoras.f.Point in project playn by threerings.

the class LayerUtilTest method testTransformWithScaleRotTrans.

@Test
public void testTransformWithScaleRotTrans() {
    TestGroupLayer root = new TestGroupLayer();
    TestGroupLayer middle = new TestGroupLayer();
    TestLayer child = new TestLayer();
    root.add(middle);
    middle.add(child);
    middle.setRotation((float) (Math.PI / 4.0));
    middle.setTranslation(10, -10);
    middle.setScale(10f, 0.5f);
    Point point = new Point(100f, 100f);
    Point pointOnChild = new Point(0f, 0f);
    Layer.Util.screenToLayer(child, point, pointOnChild);
    Point pointOnParent = new Point(0f, 0f);
    Layer.Util.layerToScreen(child, pointOnChild, pointOnParent);
    assertEquals(point.x(), pointOnParent.x(), tol);
    assertEquals(point.y(), pointOnParent.y(), tol);
    root.clear();
}
Also used : Point(pythagoras.f.Point) Test(org.junit.Test)

Example 4 with Point

use of pythagoras.f.Point in project playn by threerings.

the class JavaLWJGLMouse method update.

@Override
void update() {
    while (Mouse.next()) {
        double time = (double) (Mouse.getEventNanoseconds() / 1000000);
        int btn = getButton(Mouse.getEventButton());
        Point m = new Point(Mouse.getEventX(), Display.getHeight() - Mouse.getEventY() - 1);
        platform.graphics().transformMouse(m);
        int dx = Mouse.getEventDX(), dy = -Mouse.getEventDY();
        if (btn != -1) {
            if (Mouse.getEventButtonState()) {
                onMouseDown(time, m.x, m.y, btn);
            } else {
                onMouseUp(time, m.x, m.y, btn);
            }
        } else if (Mouse.getEventDWheel() != 0) {
            int delta = Mouse.getEventDWheel() > 0 ? -1 : 1;
            onMouseWheelScroll(time, m.x, m.y, delta);
        } else {
            onMouseMove(time, m.x, m.y, dx, dy);
        }
    }
}
Also used : Point(pythagoras.f.Point) Point(pythagoras.f.Point)

Example 5 with Point

use of pythagoras.f.Point in project playn by threerings.

the class GroupLayerImpl method add.

/**
   * @return the index into the children array at which the layer was inserted (based on depth).
   */
public int add(GroupLayer self, L child) {
    // optimization if we're requested to add a child that's already added
    GroupLayer parent = child.parent();
    if (parent == self) {
        return findChild(child, child.depth());
    }
    // if this child has equal or greater depth to the last child, we can append directly and avoid
    // a log(N) search; this is helpful when all children have the same depth
    int count = children.size(), index;
    if (count == 0 || children.get(count - 1).depth() <= child.depth()) {
        index = count;
    } else {
        // otherwise find the appropriate insertion point via binary search
        index = findInsertion(child.depth());
    }
    // remove the child from any existing parent, preventing multiple parents
    if (parent != null) {
        child.parent().remove(child);
    }
    children.add(index, child);
    child.setParent(self);
    child.onAdd();
    // if this child is active, we need to become active
    if (child.interactive())
        self.setInteractive(true);
    return index;
}
Also used : Point(pythagoras.f.Point)

Aggregations

Point (pythagoras.f.Point)14 Test (org.junit.Test)4 PointerImpl (playn.core.PointerImpl)2 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 TouchImpl (playn.core.TouchImpl)1 NoninvertibleTransformException (pythagoras.util.NoninvertibleTransformException)1