Camera

Slut uses the concept of a camera to change the viewpoint of a scene. The active camera is a member of the world and is named "camera". The following transformations can be used to move, rotate, orbit and zoom around in the world.

Relevant examples: camera_all.py, ALL

In Context

class Atlantis(World):
    def onSetup(self):
        self.camera.moveBy(1.5, 0, 0)
        self.camera.moveBy(Tween(-2, 0, 0, 3))
        self.camera.orbitBy(Thrust(0, 45, 0))

Moving the camera backward makes all objects in perspective space (the ones drawn by onDraw() and sprites) look smaller or objects can be drawn at a bigger scale:

self.camera.moveBy(0.0, 0.0, -20.0)

Default Camera Movement

By default Slut hooks up mouse event handlers to camera transformations as defined in the slut.interaction.Interaction class. This provides simple navigation of the scene.

[CTRL] + LMB + [mouse movement] orbits the camera around the origin.
[SHIFT] + LMB + [mouse movement] moves the camera along the x an y axis.
[CTRL] + [SHIFT] + LMB + [mouse movement] moves the camera along the z axis (dolly in/out).

This behavior can be changed by defining a custom interaction class and assigning it to the world:

custom_interaction.py

onMouseMove(), in the above example, is changed so that camera orbiting is done by simply [LMB] + [mouse movement]. This newly defined AtlantisInteraction class has to be assigned to the world's ia member variable to redefine the default interaction.

Initiated by Stephan Hechenberger
Thanks to CADRE's 103