Thanks for the answer, I looked into the clipping problem a bit better and I noticed in COpenGLDriver.cpp that the clipping plane is updated after the GL_MODELVIEW matrix is set in setTransform():
Code: Select all
void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)
{
Matrices[state] = mat;
Transformation3DChanged = true;
switch (state)
{
case ETS_VIEW:
case ETS_WORLD:
{
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
// we have to update the clip planes to the latest view matrix
for (u32 i=0; i<MaxUserClipPlanes; ++i)
if (UserClipPlanes[i].Enabled)
uploadClipPlane(i);
}
break;
The GL_MODELVIEW matrix is set to the combined ETS_VIEW and ETS_WORLD matrices, so the uploadClipPlane() applies the clipplane in the local node coordinates. This explains why all nodes are suddenly clipped in half.
I guess a discussion on what would be expected clipping behavior is in order. If I enable a clip plane using driver->setClipPlane(0, clipPlane, true) I expected it to be in world coordinates, especially since it is applied to all nodes in the scene manager. The current implementation makes it very hard to add 100 tree nodes with a different position using setPosition(), and then have one clip plane clipping the forrest. Right now I would have to assign each tree node to a different scene manager, so I can apply a different clip plane to each scene manager.
I think a solution to the problem would be to apply the clip plane only after the GL_MODELVIEW matrix has been set to the ETS_VIEW matrix. This ensures that all clip planes are applied in world coordinates. The proposed code below does this:
Code: Select all
void COpenGLDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)
{
Matrices[state] = mat;
Transformation3DChanged = true;
switch (state)
{
case ETS_VIEW:
case ETS_WORLD:
{
// OpenGL only has a model matrix, view and world is not existent. so lets fake these two.
glMatrixMode(GL_MODELVIEW);
// first load the viewing transformations
glLoadMatrixf((Matrices[ETS_VIEW]).pointer());
// we have to update the clip planes to the latest view matrix
for (u32 i=0; i<MaxUserClipPlanes; ++i)
if (UserClipPlanes[i].Enabled)
uploadClipPlane(i);
// now load the combined view and world matrices
glLoadMatrixf((Matrices[ETS_VIEW] * Matrices[ETS_WORLD]).pointer());
}
break;
And if someone still would like to apply a clip plane in local node coordinates this can be done by setting the plane3df object to the node position.
Is there any chance that the proposed patch can be applied to the next Irrlicht release?
cheers,
heda