Camera

moderngl_window.scene.Camera[source]

Simple camera class containing projection.

# create a camera
camera = Camera(fov=60.0, aspect_ratio=1.0, near=1.0, far=100.0)

# Get the current camera matrix as numpy array
print(camera.matrix)

# Get projection matrix as numpy array
print(camera.projection.matrix)

Methods

Camera.__init__(fov=60.0, aspect_ratio=1.0, near=1.0, far=100.0)[source]

Initialize camera using a specific projection

Keyword Arguments
  • fov (float) – Field of view

  • aspect_ratio (float) – Aspect ratio

  • near (float) – Near plane

  • far (float) – Far plane

Camera.set_position(x, y, z) → None[source]

Set the 3D position of the camera.

Parameters
  • x (float) – x position

  • y (float) – y position

  • z (float) – z position

Camera.set_rotation(yaw, pitch) → None[source]

Set the rotation of the camera.

Parameters
  • yaw (float) – yaw rotation

  • pitch (float) – pitch rotation

Camera.look_at(vec=None, pos=None) → numpy.ndarray[source]

Look at a specific point

Either vec or pos needs to be supplied.

Keyword Arguments
  • vec (pyrr.Vector3) – position

  • pos (tuple/list) – list of tuple [x, y, x] / (x, y, x)

Returns

Camera matrix

Return type

numpy.ndarray

Attributes

Camera.pitch

The current pitch angle.

Type

float

Camera.yaw

The current yaw angle.

Type

float

Camera.matrix

The current view matrix for the camera

Type

numpy.ndarray

Camera.projection

The 3D projection

Type

Projection3D