【问题标题】:OpenGL: Rotate around a point in 3D spaceOpenGL:围绕 3D 空间中的一个点旋转
【发布时间】:2015-10-19 16:40:10
【问题描述】:

我一直在寻找类似的问题,但无法准确找到我正在寻找的内容。

我正在尝试围绕 (0, 0, 0) 旋转一个对象,而不管它的 x、y 和 z 偏移量如何。

举个例子,考虑以下相关情况:

我有一个月亮,它围绕一个以 (0, 0, 0) 为中心的行星旋转。月球的初始偏移量为 (1, 1, 1)。我想在每一帧中围绕地球旋转月球和其他卫星。

为了实现这一点,我从以下代码开始:

    for (GMoon moon : moonList)
    {
        Point offset = moon.getOffset();

        float newRot = moon.getRotation() + moon.getRotSpeed();
        moon.setRotation(newRot);

        // Return to the identity matrix
        gl.glLoadIdentity();

        // Translate and rotate the planet
        gl.glTranslatef(0.0f, 0.0f, OBJECT_DISTANCE);
        gl.glRotatef(newRot, 0, 0, 1);
        gl.glTranslatef(offset.getX(), offset.getY(), offset.getZ());

        // Draw the moon
        moon.draw(gl);
    }

(出于查看目的,OBJECT_DISTANCE 等于 -10)。

它不是在行星前面旋转,而是简单地围绕它旋转。

我做错了什么吗?

非常感谢您的宝贵时间。


编辑:我假设我需要根据月球的偏移量将每个轴旋转某个组件。我不太确定应该如何计算这样的组件。

【问题讨论】:

    标签: android opengl-es 3d rotation


    【解决方案1】:

    我假设您想围绕地球及其中心点旋转月球。要达到这一点:

    我认为还有一个类似的问题: Rotating an object around a fixed point in opengl

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2021-10-28
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      • 2011-11-18
      相关资源
      最近更新 更多