【问题标题】:Rotation of the camera around an object in an inclined orbit in OpenGL ES 2.0/3.0在 OpenGL ES 2.0/3.0 中围绕倾斜轨道中的物体旋转相机
【发布时间】:2020-08-13 07:06:00
【问题描述】:

要沿横坐标轴 (X) 围绕对象旋转相机,我使用以下代码:

private float k = 0f;
...
@Override
public void onDrawFrame(GL10 gl) {
    // Math.PI * 2 - full rotation
    k = (k >= Math.PI * 2) ? 0.0f : k + 0.01f; // gradually rotate the camera
    float radius = 2.6f;

    float x = (float) (radius * Math.cos(k));
    float z = (float) (radius * Math.sin(k));
    Matrix.setLookAtM(viewMatrix, 0, x, 0, z, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
    ...
}

沿纵坐标轴 (Y) 围绕对象旋转相机:

...
float y = (float) (radius * Math.cos(k));
float z = (float) (radius * Math.sin(k));
Matrix.setLookAtM(viewMatrix, 0, 0, y, z, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
...

但我不明白如何沿倾斜轴围绕物体旋转相机。这种情况下x、y、z的比例应该是多少?

感谢您的任何评论/回复!

注意:对象的中心与相机正在看的点 (0,0,0) 重合。

【问题讨论】:

    标签: android matrix trigonometry


    【解决方案1】:

    找到了这个解决方案:

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        ...
        Matrix.setLookAtM(viewMatrix, 0, 0f, 0f, 5f,
            0f, 0f, 0f, 0f, 1.0f, 0.0f);
    }
    
    @Override
    public void onDrawFrame(GL10 gl) {
        Matrix.rotateM(viewMatrix, 0, angle1, x:1, y:0, z:0);
        Matrix.rotateM(viewMatrix, 0, angle2, x:0, y:1, z:0);
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 2013-05-12
      相关资源
      最近更新 更多