我有一个模型矩阵,用于跟踪网格在我的世界中的位置。每次调用 glRotate()
和 glTranslate()
时,我都会相应地调用 modelMatrix.rotate()
和 modelMatrix.translate()
,这似乎是正确的。
现在我需要更新与我的每个模型相关联的边界框。我正在使用 libGDX 框架,在 此处 的 BoundingBox
类中,有一个名为 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();
glLoadIdentity()
。 - DRiFTy