This weekend I tried implementing a mirror.
I tried adopting MirrorDemo.py, as suggested in an quite old thread.
Well, it worked - in a way The mirror seems somehow distorted.
Please take a look at the screenshots showing the effect:
schlangengrube.blogspot.com/2007 … chive.html
Note that the smiley is reflected ok, but the more an object is away from the center of the mirror, the more its mirror image is displaced.
I don’t know why.
What I want to do: The opponents in this game are penguins, so I thought it would be nice if the ground is made of shining ice, such that everything is reflected.
I read through discourse.panda3d.org/viewtopic.php … ght=mirror
but I still don’t know what’s wrong with my code.
Here’s some explanation and an excerpt from the code:
(I’ll put it on p3dp.com as soon as that site will be repaired…)
The maze is in the XY-plane, the camera has a positive Z-index.
The player’s smiley has radius 0.5, the walls are made of 1x1x1-cubes.
In MirrorDemo.py, I added an additional argument “playerCam”,
and replaced references to base.camera with playerCam; now the moveCamera task starts with
def moveCamera(task, playerCam = playerCam, cameraNP = cameraNP, plane = plane, planeNP = planeNP, card = card, lens = lens, width = width, height = height): # Set the camera to the mirror-image position of the main camera. cameraNP.setMat(playerCam.getMat(planeNP) * plane.getReflectionMat())
setupMirror is called like this:
# Note: For 1-player game, playerCam is base.Camera npSpiegel = MirrorDemo.setupMirror("mirror%s" % id(playerCam), playerCam, 8.0, 6.0) npSpiegel.setHpr (-180, 90, 0)
A task keeps the mirror centered at the player’s smiley:
mirror.setPos (player.npSmiley.getPos()) mirror.setZ(0.01)