【问题标题】:Rotating camera around a object positioned at center in openGL ES围绕位于openGL ES中心的对象旋转相机
【发布时间】:2017-07-21 13:53:40
【问题描述】:

我正在阅读适用于 Android 的 OpenGL ES 2。 第 8 章的问题是围绕桌子的中心旋转相机。

换句话说... 我设置视图矩阵的方式如下。

setLookAtM(viewMatrix, 0, 0f, 1.2f, 2.2f, 0f, 0f, 0f, 0f, 1f, 0f);

现在我想围绕 Y 轴围绕原点旋转它 我应该为此编写什么代码。

【问题讨论】:

    标签: android opengl-es


    【解决方案1】:

    如果你想绕桌子的中心旋转,你必须平移相机,然后设置它的方向指向中间。

    圆上的位置很容易计算。

        float angle = 30.0f;
        float radius = 2.0f;
    
        float x = (float)( radius * Math.cos(angle));
        float y = (float)( radius * Math.sin(angle));
    
        Matrix.translateM(viewMatrix, 0, -x, 0, -y);
        Matrix.setLookAtM(viewMatrix, 0, 0f, 1.2f, 2.2f, 0f, 0f, 0f, 0f, 1f, 0f);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      相关资源
      最近更新 更多