当前位置: 首页>>代码示例>>Java>>正文


Java PAffineTransform.translate方法代码示例

本文整理汇总了Java中org.piccolo2d.util.PAffineTransform.translate方法的典型用法代码示例。如果您正苦于以下问题:Java PAffineTransform.translate方法的具体用法?Java PAffineTransform.translate怎么用?Java PAffineTransform.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.piccolo2d.util.PAffineTransform的用法示例。


在下文中一共展示了PAffineTransform.translate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAnimateToPositionScaleRotationHasProperSetup

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testAnimateToPositionScaleRotationHasProperSetup() {
    node.setBounds(0, 0, 100, 100);
    final PTransformActivity activity = node.animateToPositionScaleRotation(50, 50, 0.5, Math.PI, 50);

    assertEquals(50, activity.getDuration());
    assertEquals(PUtil.DEFAULT_ACTIVITY_STEP_RATE, activity.getStepRate());
    assertTrue(activity.getFirstLoop());
    assertFalse(activity.isStepping());

    final double[] resultTransform = activity.getDestinationTransform();

    final PAffineTransform expected = new PAffineTransform();
    expected.translate(50, 50);
    expected.scale(0.5, 0.5);
    expected.rotate(Math.PI);

    assertEquals(-0.5, resultTransform[0], 0.001);
    assertEquals(0, resultTransform[1], 0.001);
    assertEquals(0, resultTransform[2], 0.001);
    assertEquals(-0.5, resultTransform[3], 0.001);
    assertEquals(50.0, resultTransform[4], 0.001);
    assertEquals(50.0, resultTransform[5], 0.001);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:24,代码来源:PNodeTest.java

示例2: testAnimateToRelativePositionResultsInProperTransform

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testAnimateToRelativePositionResultsInProperTransform() {
    final PCanvas canvas = new PCanvas();
    final PNode A = new PNode();
    A.setBounds(0, 0, 50, 50);
    canvas.getLayer().addChild(A);
    final PNode B = new PNode();
    B.setBounds(0, 0, 100, 100);
    B.setOffset(100, 100);
    canvas.getLayer().addChild(B);

    final Point2D srcPt = new Point2D.Double(1.0, 0.0);
    final Point2D destPt = new Point2D.Double(0.0, 0.0);
    A.animateToRelativePosition(srcPt, destPt, B.getGlobalBounds(), 0);

    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.translate(50, 100);

    assertEquals(expectedTransform, A.getTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:20,代码来源:PNodeTest.java

示例3: testAnimateToPositionScaleRotationWithDuration0IsImmediate

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testAnimateToPositionScaleRotationWithDuration0IsImmediate() {
    node.setBounds(0, 0, 100, 100);
    final PActivity activity = node.animateToPositionScaleRotation(50, 50, 0.5, Math.PI, 0);

    assertNull(activity);

    final PAffineTransform resultTransform = node.getTransform();

    final PAffineTransform expected = new PAffineTransform();
    expected.translate(50, 50);
    expected.scale(0.5, 0.5);
    expected.rotate(Math.PI);

    assertEquals(expected, resultTransform);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:16,代码来源:PNodeTest.java

示例4: testRotateAboutPointVersion1AffectsTransformAsItShould

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testRotateAboutPointVersion1AffectsTransformAsItShould() {
    node.setBounds(25, 25, 50, 50);
    node.rotateAboutPoint(Math.PI, 50, 0); // It's top center point

    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.translate(100, 0);
    expectedTransform.rotate(Math.PI);

    assertEquals(expectedTransform, node.getTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:11,代码来源:PNodeTest.java

示例5: testRotateAboutPointVersion2AffectsTransformAsItShould

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testRotateAboutPointVersion2AffectsTransformAsItShould() {
    node.setBounds(25, 25, 50, 50);
    node.rotateAboutPoint(Math.PI, new Point2D.Double(50, 0)); // It's top
    // center
    // point

    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.translate(100, 0);
    expectedTransform.rotate(Math.PI);

    assertEquals(expectedTransform, node.getTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:13,代码来源:PNodeTest.java

示例6: testScaleAboutPointWorksAsExpected

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testScaleAboutPointWorksAsExpected() {
    node.setBounds(0, 0, 100, 100);
    node.scaleAboutPoint(2, new Point2D.Double(50, 50));
    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.translate(-50, -50);
    expectedTransform.scale(2, 2);

    assertEquals(expectedTransform, node.getTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:10,代码来源:PNodeTest.java

示例7: testGetInverseTransformWorks

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
public void testGetInverseTransformWorks() {
    node.translate(50, 50);
    node.rotate(Math.PI);

    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.rotate(-Math.PI);
    expectedTransform.translate(-50, -50);
    assertEquals(expectedTransform, node.getInverseTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:10,代码来源:PNodeTest.java

示例8: cacheViewBounds

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
/**
 * Caches the information necessary to animate from the current view bounds
 * to the specified centerBounds.
 */
private AffineTransform cacheViewBounds(final Rectangle2D centerBounds, final boolean scaleToFit) {
    final PBounds viewBounds = getViewBounds();

    // Initialize the image to the union of the current and destination
    // bounds
    final PBounds imageBounds = new PBounds(viewBounds);
    imageBounds.add(centerBounds);

    animateViewToCenterBounds(imageBounds, scaleToFit, 0);

    imageAnimateBounds = getViewBounds();

    // Now create the actual cache image that we will use to animate fast

    final BufferedImage buffer = getPaintBuffer();
    Paint fPaint = Color.white;
    if (getPaint() != null) {
        fPaint = getPaint();
    }
    toImage(buffer, fPaint);

    // Do this after the painting above!
    imageAnimate = true;

    // Return the bounds to the previous viewbounds
    animateViewToCenterBounds(viewBounds, scaleToFit, 0);

    // The code below is just copied from animateViewToCenterBounds to
    // create the correct transform to center the specified bounds

    final PDimension delta = viewBounds.deltaRequiredToCenter(centerBounds);
    final PAffineTransform newTransform = getViewTransform();
    newTransform.translate(delta.width, delta.height);

    if (scaleToFit) {
        final double s = Math.min(viewBounds.getWidth() / centerBounds.getWidth(), viewBounds.getHeight()
                / centerBounds.getHeight());
        newTransform.scaleAboutPoint(s, centerBounds.getCenterX(), centerBounds.getCenterY());
    }

    return newTransform;
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:47,代码来源:PCacheCamera.java

示例9: animateViewToCenterBounds

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
/**
 * Animate the camera's view from its current transform when the activity
 * starts to a new transform that centers the given bounds in the camera
 * layer's coordinate system into the cameras view bounds. If the duration is
 * 0 then the view will be transformed immediately, and null will be
 * returned. Else a new PTransformActivity will get returned that is set to
 * animate the camera's view transform to the new bounds. If shouldScale is
 * true, then the camera will also scale its view so that the given bounds
 * fit fully within the cameras view bounds, else the camera will maintain
 * its original scale.
 * 
 * @param centerBounds the bounds which the animation will pace at the
 *            center of the view
 * @param shouldScaleToFit whether the camera should scale the view while
 *            animating to it
 * @param duration how many milliseconds the animations should take
 * 
 * @return the scheduled PTransformActivity
 */
public PTransformActivity animateViewToCenterBounds(final Rectangle2D centerBounds, final boolean shouldScaleToFit,
        final long duration) {
    final PBounds viewBounds = getViewBounds();
    final PDimension delta = viewBounds.deltaRequiredToCenter(centerBounds);
    final PAffineTransform newTransform = getViewTransform();
    newTransform.translate(delta.width, delta.height);

    if (shouldScaleToFit) {
        final double s = Math.min(viewBounds.getWidth() / centerBounds.getWidth(), viewBounds.getHeight()
                / centerBounds.getHeight());
        if (s != Double.POSITIVE_INFINITY && s != 0) {
            newTransform.scaleAboutPoint(s, centerBounds.getCenterX(), centerBounds.getCenterY());
        }
    }

    return animateViewToTransform(newTransform, duration);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:37,代码来源:PCamera.java

示例10: animateToRelativePosition

import org.piccolo2d.util.PAffineTransform; //导入方法依赖的package包/类
/**
 * This will calculate the necessary transform in order to make this node
 * appear at a particular position relative to the specified bounding box.
 * The source point specifies a point in the unit square (0, 0) - (1, 1)
 * that represents an anchor point on the corresponding node to this
 * transform. The destination point specifies an anchor point on the
 * reference node. The position method then computes the transform that
 * results in transforming this node so that the source anchor point
 * coincides with the reference anchor point. This can be useful for layout
 * algorithms as it is straightforward to position one object relative to
 * another.
 * <p>
 * For example, If you have two nodes, A and B, and you call
 * 
 * <PRE>
 * Point2D srcPt = new Point2D.Double(1.0, 0.0);
 * Point2D destPt = new Point2D.Double(0.0, 0.0);
 * A.position(srcPt, destPt, B.getGlobalBounds(), 750, null);
 * </PRE>
 * 
 * The result is that A will move so that its upper-right corner is at the
 * same place as the upper-left corner of B, and the transition will be
 * smoothly animated over a period of 750 milliseconds.
 * 
 * @since 1.3
 * @param srcPt The anchor point on this transform's node (normalized to a
 *            unit square)
 * @param destPt The anchor point on destination bounds (normalized to a
 *            unit square)
 * @param destBounds The bounds (in global coordinates) used to calculate
 *            this transform's node
 * @param millis Number of milliseconds over which to perform the animation
 * 
 * @return newly scheduled activity or node if activity could not be
 *         scheduled
 */
public PActivity animateToRelativePosition(final Point2D srcPt, final Point2D destPt, final Rectangle2D destBounds,
        final int millis) {
    double srcx, srcy;
    double destx, desty;
    double dx, dy;
    Point2D pt1, pt2;

    if (parent == null) {
        return null;
    }
    else {
        // First compute translation amount in global coordinates
        final Rectangle2D srcBounds = getGlobalFullBounds();
        srcx = lerp(srcPt.getX(), srcBounds.getX(), srcBounds.getX() + srcBounds.getWidth());
        srcy = lerp(srcPt.getY(), srcBounds.getY(), srcBounds.getY() + srcBounds.getHeight());
        destx = lerp(destPt.getX(), destBounds.getX(), destBounds.getX() + destBounds.getWidth());
        desty = lerp(destPt.getY(), destBounds.getY(), destBounds.getY() + destBounds.getHeight());

        // Convert vector to local coordinates
        pt1 = new Point2D.Double(srcx, srcy);
        globalToLocal(pt1);
        pt2 = new Point2D.Double(destx, desty);
        globalToLocal(pt2);
        dx = pt2.getX() - pt1.getX();
        dy = pt2.getY() - pt1.getY();

        // Finally, animate change
        final PAffineTransform at = new PAffineTransform(getTransformReference(true));
        at.translate(dx, dy);
        return animateToTransform(at, millis);
    }
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:69,代码来源:PNode.java


注:本文中的org.piccolo2d.util.PAffineTransform.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。