Mirror - tried adopting Mirror-Demo.py, but it's distorted

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 :confused: 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. :question:

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)

I think the field-of-view of your mirror lens is not precisely matching the camera’s field-of-view. Try using the same lens for both. Instead of this:

    camera = Camera('mirrorCamera')
    lens = PerspectiveLens()
    lens.setFilmSize(width, height)
    camera.setLens(lens)

Do this:

    camera = Camera('mirrorCamera')
    camera.setLens(base.camLens)

Also, since your playfield is unchanging, you might just set up your mirror polygon to exactly match your playfield, so you don’t need to move it around with a task.

David

Unfortunately, that didn’t help.
I’ll take a closer look at the Nature-Demo.py again.