【问题标题】:Sphere rotation OpenGL球体旋转OpenGL
【发布时间】:2019-05-03 14:15:50
【问题描述】:

所以,我正在使用 OpenGL 开发一个 8 球台球游戏,而这些球让我很困扰。它们移动得很好,但它们目前沿着桌子滑动。我似乎无法弄清楚沿三个轴的旋转,因为它们似乎在旋转后发生了变化。 我只知道当前位置(curPos)和下一个位置(nextPos)。

velocityAng += (nextPos - curPos) / sphereRadius;
//and afterward I rotate on each axis
modelMatrix = glm::rotate(modelMatrix, velocityAng[2], glm::vec3(0, 0, 1));
modelMatrix = glm::rotate(modelMatrix, velocityAng[1], glm::vec3(0, 1, 0));
modelMatrix = glm::rotate(modelMatrix, velocityAng[0], glm::vec3(1, 0, 0));

我发现如果球处于初始位置并且我向上或向右射击它会很好,但是在我向右射击并将球旋转 90 度后,当我向上射击时它并不顺利了。很明显,在 0、90、180、270 以外的任何角度拍摄都会完全错误。 当我旋转它时,球的轴似乎发生了变化。

【问题讨论】:

  • 很遗憾,您可能需要了解四分位数。

标签: c++ visual-studio opengl


【解决方案1】:

你旋转太多了,你只需要一次旋转。该旋转的轴应垂直于 (nextPos - curPos) 向量,即您需要这样的东西(未经测试):

const float angle = ( nextPos – curPos ).length() / sphereRadius;
// Assuming the table is on the XY plane
const vec3 axis = cross( nextPos - curPos, glm::vec3( 0, 0, 1 ) );
modelMatrix = rotate( modelMatrix, angle, axis );

【讨论】:

    猜你喜欢
    • 2014-07-18
    • 2015-01-28
    • 1970-01-01
    • 2011-05-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    相关资源
    最近更新 更多