• <legend id='c6oQT'><style id='c6oQT'><dir id='c6oQT'><q id='c6oQT'></q></dir></style></legend>
  • <small id='c6oQT'></small><noframes id='c6oQT'>

    <i id='c6oQT'><tr id='c6oQT'><dt id='c6oQT'><q id='c6oQT'><span id='c6oQT'><b id='c6oQT'><form id='c6oQT'><ins id='c6oQT'></ins><ul id='c6oQT'></ul><sub id='c6oQT'></sub></form><legend id='c6oQT'></legend><bdo id='c6oQT'><pre id='c6oQT'><center id='c6oQT'></center></pre></bdo></b><th id='c6oQT'></th></span></q></dt></tr></i><div id='c6oQT'><tfoot id='c6oQT'></tfoot><dl id='c6oQT'><fieldset id='c6oQT'></fieldset></dl></div>

    1. <tfoot id='c6oQT'></tfoot>

          <bdo id='c6oQT'></bdo><ul id='c6oQT'></ul>
      1. 安卓.如何沿它所面对的方向移动对象(使用 Vect

        时间:2023-07-27

          <small id='whsh4'></small><noframes id='whsh4'>

          <legend id='whsh4'><style id='whsh4'><dir id='whsh4'><q id='whsh4'></q></dir></style></legend>
        1. <i id='whsh4'><tr id='whsh4'><dt id='whsh4'><q id='whsh4'><span id='whsh4'><b id='whsh4'><form id='whsh4'><ins id='whsh4'></ins><ul id='whsh4'></ul><sub id='whsh4'></sub></form><legend id='whsh4'></legend><bdo id='whsh4'><pre id='whsh4'><center id='whsh4'></center></pre></bdo></b><th id='whsh4'></th></span></q></dt></tr></i><div id='whsh4'><tfoot id='whsh4'></tfoot><dl id='whsh4'><fieldset id='whsh4'></fieldset></dl></div>

            <bdo id='whsh4'></bdo><ul id='whsh4'></ul>
            <tfoot id='whsh4'></tfoot>
                <tbody id='whsh4'></tbody>
                  本文介绍了安卓.如何沿它所面对的方向移动对象(使用 Vector3 和四元数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 libGDX(实际上对它来说很新)和 Android.我想将 3d 对象朝它所面对的方向移动(使用一些速度).我认为这是一个基本问题,但找不到直接的答案.我有一个表示对象旋转(方向)的四元数,我有一个表示对象位置的 Vector3.问题是如何使用来自四元数的信息更新位置 Vector3,以便在四元数表示的方向上移动对象.(另一种方法是从四元数中提取滚动俯仰和偏航,并通过应用三角计算获得新坐标.但我认为必须有一种方法可以使用 Vector3 和 Quat 来实现.)

                  I'm using libGDX (quite new to it in fact) and Android. And I want to move 3d object in the direction it is facing (using some speed). I thinks it's a basic question but can't find a straight nswer for it. I have a Quaternion representing object rotation(direction) and I have a Vector3 representing the object position. The question is how to update the position Vector3 using info from Quaternion in order to move object in the direction represented by Quaternion. (An alternative to this is extract roll pitch and yaw from Quaternion and get the new coords by applying trigonometric calculations. But i think there must be a way to achieve this using Vector3 and Quat.)

                  推荐答案

                  四元数用于指定旋转.您首先需要指定不应用旋转时的方向.例如,如果您想在未应用旋转时沿 X 轴移动:

                  Quaternion is used to specify a rotation. You first need to specify the direction when no rotation is applied. For example if you want to move along the X axis when no rotation is applied:

                  Vector3 baseDirection = new Vector3(1,0,0);
                  

                  确保基准方向是标准化的(长度=1),您可以使用nor()方法以确保安全:

                  Make sure the base direction is normalized (length = 1),you can use the nor() method to be safe:

                  Vector3 baseDirection = new Vector3(1,0,0).nor();
                  

                  接下来您需要使用四元数旋转方向:

                  Next you'll need to rotate the direction using the Quaternion:

                  Vector3 direction = new Vector3();
                  Quaternion rotation = your_quaternion;
                  direction.set(baseDirection);
                  direction.mul(rotation);
                  

                  现在您已经有了方向,您可以按照您想要移动的量对其进行缩放.您可能希望每帧都执行此操作,具体取决于自上一帧以来经过的时间.

                  Now that you have the direction, you can scale it with the amount you want to move it. You'll probably want to do this every frame and depending on the time elapsed since the last frame.

                  final float speed = 5f; // 5 units per second
                  Vector3 translation = new Vector3();
                  translation.set(direction);
                  translation.scl(speed * Gdx.graphics.getDeltaTime());
                  

                  最后你需要将翻译添加到位置

                  Finally you need to add the translation to the position

                  position.add(translation);
                  

                  当然,根据您的实际实现,您可以批处理多个操作,例如:

                  Of course, depending on your actual implementation you can batch multiple operations, e.g.:

                  translation.set(baseDirection).mul(rotation).scl(speed * Gdx.graphics.getDeltaTime());
                  position.add(translation);
                  

                  更新:从 Xoppa 的评论中添加工作代码:

                  Update: Adding working code from Xoppa's comment:

                  translation.set(baseDirection).rot(modelInstance.transform).nor().scl(speed * delta)
                  

                  这篇关于安卓.如何沿它所面对的方向移动对象(使用 Vector3 和四元数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我的 Admob 广告没有绘图,但有吗?(LibGDX Admob 6.4 下一篇:使用 libgdx 绘制带纹理的多边形

                  相关文章

                  最新文章

                  1. <small id='gTfj7'></small><noframes id='gTfj7'>

                    <tfoot id='gTfj7'></tfoot>

                        <bdo id='gTfj7'></bdo><ul id='gTfj7'></ul>

                      <i id='gTfj7'><tr id='gTfj7'><dt id='gTfj7'><q id='gTfj7'><span id='gTfj7'><b id='gTfj7'><form id='gTfj7'><ins id='gTfj7'></ins><ul id='gTfj7'></ul><sub id='gTfj7'></sub></form><legend id='gTfj7'></legend><bdo id='gTfj7'><pre id='gTfj7'><center id='gTfj7'></center></pre></bdo></b><th id='gTfj7'></th></span></q></dt></tr></i><div id='gTfj7'><tfoot id='gTfj7'></tfoot><dl id='gTfj7'><fieldset id='gTfj7'></fieldset></dl></div>

                    1. <legend id='gTfj7'><style id='gTfj7'><dir id='gTfj7'><q id='gTfj7'></q></dir></style></legend>