使用ARCore Frame旋转图像

问题描述

我在项目中使用arcore_flutter_plugin(https://pub.dev/packages/arcore_flutter_plugin)。我想将2D图像(指南针)旋转到蓝色球体。 See screenshot 当我在屏幕上点击时,球体就会出现。因此,我有球体姿势的ArCore姿势:{rotation:[x1,y1,z1,w],translation:[x2,y2,z2]}。 Pose.rotation是一个四元数。我试图从w获取角度:angle = 2 * acos(w),但是我错过了一些东西,因为它不能正常工作。如何从pose.rotation获取角度?预先谢谢你。

class _ScreenState extends State<Screen> {
 double rotationAngle;

 _ScreenState(this.rotationAngle);

 ArCoreController _arCoreController;

 @override
 Widget build(BuildContext context) {
  return MaterialApp(
    home: Stack(
      children: [
        ArCoreView(
          onArCoreViewCreated: _onArCoreViewCreated,enableTapRecognizer: true,),Column(
          children: [
            Spacer(),Container(
              height: 200,child: Compass(angle: this.rotationAngle),alignment: Alignment.bottomCenter,)
          ],],);
}

void _onArCoreViewCreated(ArCoreController controller) {
  this._arCoreController = controller;
  this._arCoreController.onPlaneTap = _handleOnPlaneTap;
}

void _handleOnPlaneTap(List<ArCoreHitTestResult> hits) {
  final hit = hits.first;
  _addObj(hit);
  final w = hit.pose.rotation[3];
  final angle = 2 * acos(w);
  setState(() {
    this.rotationAngle = angle;
  });
}

Future _addObj(ArCoreHitTestResult plane) async {
  final material = ArCoreMaterial(color: Colors.blue);
  final sphere = ArCoreSphere(
    materials: [material],radius: 0.05,);
  final node = ArCoreNode(
    shape: sphere,position: plane.pose.translation,rotation: plane.pose.rotation,);

  this._arCoreController.addArCoreNodeWithAnchor(node);
}

@override
void dispose() {
  this._arCoreController.dispose();
  super.dispose();
}

}

指南针:

class _CompassState extends State<Compass> with SingleTickerProviderStateMixin {
 AnimationController _controller;

 @override
 void initState() {
  super.initState();

  _controller =
    AnimationController(vsync: this,duration: Duration(milliseconds: 200));
}

@override
Widget build(BuildContext context) {
  return Container(
    alignment: Alignment.center,child: AnimatedBuilder(
      animation: _controller,builder: (_,child) {
        return Transform.rotate(
          angle: widget.angle,child: child,);
      },child: Container(
        child: Image.asset('lib/resources/images/compass.png'),);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)