【问题标题】:Rotate plane used to find world coordinates用于查找世界坐标的旋转平面
【发布时间】:2018-04-16 20:12:24
【问题描述】:

我正在尝试从Plane 上的屏幕坐标中找到世界坐标,其中mCameraPerspectiveCamera

public Vector3 getWorldCoordinates(float x, float y) {
    // Use an imaginary plane at z=0 to intersect ray
    Plane plane = new Plane();
    plane.set(0, 0, 1, 0);
    Ray ray = mCamera.getPickRay(x, y);
    Vector3 pos = new Vector3();
    Intersector.intersectRayPlane(ray, plane, pos);
    return pos;
}

如何修改此例程以在找到坐标之前在 X 轴上旋转 Plane x 度数?

是否有任何简单的内置 libgdx 例程用于旋转平面,例如使用 Camera.rotate(Vector3.X, degrees)Camera

【问题讨论】:

  • 将 Vector3 设置为 0, 0, 1 并旋转它。然后用它来设置你的飞机。
  • 谢谢。奇迹般有效。您可以将其添加为答案,我会接受吗?

标签: android libgdx opengl-es-2.0


【解决方案1】:

将 Vector3 设置为您想要的方向并使用它来设置平面。所以在你的情况下

vector3.set(0, 0, 1);
vector3.rotateX(0.5f); // for example
plane.set(vector3.x, vector3.y, vector3.z, 0);

如果您在每一帧上都这样做,您可能需要考虑在类构造函数中实例化您的向量和平面一次并重用它们,这样您就不会偶尔触发 GC,这可能会导致卡顿。

【讨论】:

    猜你喜欢
    • 2020-07-06
    • 2019-06-19
    • 1970-01-01
    • 2011-04-12
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    相关资源
    最近更新 更多