我有一个模型矩阵,可以随时跟踪网格物体在我的世界中的位置。每次调用glRotate()
和glTranslate()
时,我都有一个相应的modelMatrix.rotate()
和modelMatrix.translate()
调用,它们似乎正常工作。
现在,我需要更新与每个模型关联的边界框。我正在libGDX框架和BoundingBox
类found here中工作,有一种方法mul()
应该允许我将矩阵应用于边界框,但是值未正确更新,我认为这可能是我的方法尝试应用它。有任何想法吗?
这是我的相关代码:
gl.glPushMatrix();
// Set the model matrix to the identity matrix
modelMatrix.idt();
// Update the orbit value of this model
orbit = (orbit + ORBIT_SPEED * delta) % 360;
gl.glRotatef(orbit, 1.0f, 1.0f, 0);
// Update the model matrix rotation
modelMatrix.rotate(1.0f, 1.0f, 0, orbit);
// Move the model to it's specified radius
gl.glTranslatef(0, 0, -ORBIT_DISTANCE);
// Update the model matrix translation
modelMatrix.translate(0, 0, -ORBIT_DISTANCE);
// Update the bounding box
boundingBox.mul(modelMatrix);
if (GameState.DEBUG)
{
renderBoundingBox(gl, delta);
}
// Bind the texture and draw
texture.bind();
mesh.render(GL10.GL_TRIANGLES);
gl.glPopMatrix();
最佳答案
矩阵乘法的计算顺序很重要。您可以代替ModelMatrix * Box吗。我认为这就是问题所在。