By default, Vizard will automatically compute the near/far clipping planes based on what geometry is in view. The clip planes in the matrix returned by
viz.MainWindow.getProjectionMatrix() won't match the clip planes that will be used to perform the rendering. This is why the ground shows up on top of the box.
You can use the
viz.MainWindow.clip command to specify static clip planes. This will ensure the projection matrix is the same as the one being used to render the scene.
Here is an updated version of the script:
Code:
import viz, vizcam, vizshape, vizfx.postprocess, vizact
vizcam.PivotNavigate(center=[0, 0.1, 0], distance=5)
viz.go()
box = viz.addChild('box.wrl')
ground = viz.addChild('ground.osgb')
vertCode = """
uniform vec4 S1, S2, S3, S4;
void main()
{
gl_Position = mat4(S1, S2, S3, S4) * gl_ModelViewMatrix * gl_Vertex;
}
"""
fragCode = """
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
"""
shader = viz.addShader(vert=vertCode, frag=fragCode)
box.apply(shader)
# Use static clip plane so projection matrix doesn't change
viz.MainWindow.clip(0.1,100)
m = viz.MainWindow.getProjectionMatrix()
S1 = viz.addUniformFloat('S1', m[0:4])
S2 = viz.addUniformFloat('S2', m[4:8])
S3 = viz.addUniformFloat('S3', m[8:12])
S4 = viz.addUniformFloat('S4', m[12:16])
box.apply(S1)
box.apply(S2)
box.apply(S3)
box.apply(S4)