基于我第一次打开应用程序的位置的ARCore对象旋转

问题描述 投票:1回答:1

项目:我制作了ARCore应用。基本上,您放置2个点(Andy又名Android机器人),然后它将在这2个点的中间生成对象(橱柜)。

问题:基本上,我希望根据放置这两个点的位置来面对橱柜的门。但是,事实证明,当我第一次打开应用程序时,橱柜的门将面向我所面对的位置。

在模拟器上测试,在设备上也有相同问题

在模拟器上,我这样做:我打开应用程序,相机对准沙发。然后我将2个点随机放置(无论在哪里),生成的AR模型橱柜门将面向沙发。我导航该应用程序以使其面向窗口,将其关闭,然后再次打开它,同时使其面向窗口。然后,我再次随机放置2个点(没关系),现在生成的橱柜门将面对窗户。在这一点上,无论我在模拟器上到哪里/面对/旋转,橱柜门都将面对窗户。

任何想法如何根据放置点的位置旋转对象?

相关代码:

    //Slope
    float m_slope = (pose0.tz() - pose1.tz()) / (pose0.tx() - pose1.tx());
    float perpedicular_slope = -1f/m_slope;

    float middle_z = (pose0.tz() + pose1.tz())/2;
    float middle_x = (pose0.tx() + pose1.tx())/2;

    float b = middle_z - middle_x * perpedicular_slope;


    // backward/forward from middle
    float DEVIATION_X = 0f; // TODO: change this >0 to make it on side
    float new_x = middle_x + DEVIATION_X * side;
    float new_y = perpedicular_slope*new_x+b;

    float[] pos0_2 = { new_x , (pose0.ty() + pose1.ty())/2, new_y};
    float[] rotation0_2 = {0,0,0,1};

    /* BASICALLY Above is the code to positioning the cupboard Beside the middle of 2 points */

    Anchor anchor0_2 =  session.createAnchor(new Pose(pos0_2, rotation0_2));
    AnchorNode anchorNode0_2 = new AnchorNode(anchor0_2);
    anchorNode0_2.setParent(arFragment.getArSceneView().getScene());

    TransformableNode andy0_2 = new TransformableNode(arFragment.getTransformationSystem());
    andy0_2.setParent(anchorNode0_2);
    andy0_2.setRenderable(cupBoardRenderable);

    andy0_2.select();
    andy0_2.setWorldRotation(Quaternion.axisAngle(new Vector3(0, 1f, 0), 0f));

    //Already try something like this too, but pose0.qy() return very little number like 0.01-1 so i mult 100
    //andy0_2.setWorldRotation(Quaternion.axisAngle(new Vector3(0, 1f, 0), pose0.qy()*100f)); 

Facing the couch

Facing the windows

Cupboard

android rotation arcore quaternions
1个回答
0
投票

签出transform.LookAt()函数。通过提供转换,您希望资产查看Unity,将为您解决轮换问题。

© www.soinside.com 2019 - 2024. All rights reserved.