I’m trying to put water into my game, and I’m stuck right now. I’m trying to get the correct placement for the water camera, but nothing I’ve tried works. I’m thinking It may have something to do with my nesting/parenting. (Main camera is parented to a dummy node that’s in turn parented to a physics controller, however the dummy done does pitch independently) I’ve tried using getNetTransform, and I’ve also tried adding a parameter to getMat. None of these produce the desired effect. Here’s the important snippets.
This is the water creation code
self.waterReflectionBuffer=base.win.makeTextureBuffer("waterreflectionbuffer", 1024, 1024)
self.waterReflectionBuffer.setClearColor( Vec4( 0, 0, 0, 1 ) )
self.waterReflectionCam=base.makeCamera(self.waterReflectionBuffer)
self.waterReflectionCam.node().getLens().setFov(75) //the same as my main camera, should I be setting this?
self.waterPlane = Plane(Vec3(0, 0, 4.0), Point3(0, 0, 3.0))
self.PlaneNP = NodePath(PlaneNode("waterPlane", self.waterPlane))
np = NodePath('np')
np.setAttrib(CullFaceAttrib.makeReverse())
np.setClipPlane(self.PlaneNP)
self.waterReflectionCam.node().setInitialState(np.getState())
maker = CardMaker( 'waterMaker' )
maker.setFrame( -50, 50, -50, 50 )
self.waterNP = render.attachNewNode( maker.generate( ) )
self.waterNP.setPos( 0, 0, 3 )
self.waterNP.setP( -90 )
tex0 = self.waterReflectionBuffer.getTexture( )
ts0 = TextureStage( 'reflection' )
self.waterNP.setTexture( ts0, tex0 )
This goes in my update task.
# Water reflections
mc = base.camera.getMat()
mf = self.waterPlane.getReflectionMat()
self.waterReflectionCam.setMat(mc * mf)