繁体   English   中英

围绕位于openGL ES中居中位置的对象旋转相机

[英]Rotating camera around a object positioned at center in openGL ES

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

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

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

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

如果要围绕桌子的中心旋转,则必须平移相机,然后将其方向设置为指向中间。

圆上的位置非常容易计算。

    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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM