gpt4 book ai didi

android - 如何将对象从一个 anchor 移动到另一个 anchor ?

转载 作者:行者123 更新时间:2023-11-29 14:26:13 24 4
gpt4 key购买 nike

我的用例是:

  1. 点击屏幕并将“点”保存为起始 anchor
  2. 第二次点击屏幕并将“点”保存为结束 anchor
  3. 按下按钮将对象从开始 anchor 移动到结束 anchor

我已经构建了自己的节点,该节点使用类似于太阳系示例中的 ObjectAnimator。我唯一的问题是我不知道如何确定评估者的起点和终点。我的第一个想法是从开始和结束 anchor 的 Pose 中获取 x,y,z

Vector3 start = new Vector3(startAnchor.getPose().tx(), startAnchor.getPose().ty(), startAnchor.getPose().tz());
Vector3 end = new Vector3(endAnchor.getPose().tx(), endAnchor.getPose().ty(), endAnchor.getPose().tz());

movingAnimation.setObjectValues(startingPoint, endPoint);
movingAnimation.setPropertyName("localPosition");
movingAnimation.setEvaluator(new Vector3Evaluator());

但是当我这样做时,动画是从完全不同的地方完成的。

我还没有找到任何关于此类操作的内置工具的引用资料。我正在使用 Sceneform。

那么问题来了:如何制作从 anchor A到 anchor B的流畅动画(一个简单的幻灯片就够了)?

最佳答案

我在 HelloSceneform 示例中这样做了。我创建了第一个 AnchorNode 并添加了“andy”节点作为子节点。在下一次点击时,我创建了 endPosition AnchorNode 并启动了移动到该位置的动画。

要记住的是,如果您正在使用具有不同父级的对象的位置,您需要使用 worldPosition 与 localPosition。

  private void onPlaneTap(HitResult hitResult, Plane plane, MotionEvent motionEvent) {
if (andyRenderable == null) {
return;
}
// Create the Anchor.
Anchor anchor = hitResult.createAnchor();

// Create the starting position.
if (startNode == null) {
startNode = new AnchorNode(anchor);
startNode.setParent(arFragment.getArSceneView().getScene());

// Create the transformable andy and add it to the anchor.
andy = new Node();
andy.setParent(startNode);
andy.setRenderable(andyRenderable);
} else {
// Create the end position and start the animation.
endNode = new AnchorNode(anchor);
endNode.setParent(arFragment.getArSceneView().getScene());
startWalking();
}
}

private void startWalking() {
objectAnimation = new ObjectAnimator();
objectAnimation.setAutoCancel(true);
objectAnimation.setTarget(andy);

// All the positions should be world positions
// The first position is the start, and the second is the end.
objectAnimation.setObjectValues(andy.getWorldPosition(), endNode.getWorldPosition());

// Use setWorldPosition to position andy.
objectAnimation.setPropertyName("worldPosition");

// The Vector3Evaluator is used to evaluator 2 vector3 and return the next
// vector3. The default is to use lerp.
objectAnimation.setEvaluator(new Vector3Evaluator());
// This makes the animation linear (smooth and uniform).
objectAnimation.setInterpolator(new LinearInterpolator());
// Duration in ms of the animation.
objectAnimation.setDuration(500);
objectAnimation.start();
}

关于android - 如何将对象从一个 anchor 移动到另一个 anchor ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51337504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com