taichi.ui.camera
#
- class taichi.ui.camera.Camera#
The Camera class.
You should also manually set the camera parameters like camera.position, camera.lookat, camera.up, etc. The default settings may not work for your scene.
Example:
>>> scene = window.get_scene() # assumes you have a window
>>>
>>> camera = ti.ui.Camera()
>>> camera.position(1, 1, 1) # set camera position
>>> camera.lookat(0, 0, 0) # set camera lookat
>>> camera.up(0, 1, 0) # set camera up vector
>>> scene.set_camera(camera)
>>>
>>> # you can also control camera movement in a window
>>> window = ti.ui.Window("GGUI Camera", res=(640, 480), vsync=True)
>>> camera.track_user_inputs(window, movement_speed=0.03, hold_key=ti.ui.RMB)- bottom(self, bottom)#
Set the offset of the bottom clipping plane in camera frustum.
- Parameters:
bottom (
taichi.types.primitive_types
) – offset of the bottom clipping plane.
Example:
>>> camera.bottom(1.0)
- fov(self, fov)#
Set the camera fov angle (field of view) in degrees.
- Parameters:
fov (
taichi.types.primitive_types
) – Angle in range (0, 180).
Example:
>>> camera.fov(45)
- get_projection_matrix(self, aspect)#
Get the projection matrix(in row major) of the camera.
- Parameters:
aspect (
taichi.types.primitive_types
) – aspect ratio of the camera
Example:
>>> camera.get_projection_matrix(1080/720)
- get_view_matrix(self)#
Get the view matrix(in row major) of the camera.
Example:
>>> camera.get_view_matrix()
- left(self, left)#
Set the offset of the left clipping plane in camera frustum.
- Parameters:
left (
taichi.types.primitive_types
) – offset of the left clipping plane.
Example:
>>> camera.left(-1.0)
- lookat(self, x, y, z)#
Set the camera lookat.
- Parameters:
args (
taichi.types.primitive_types
) – 3D coordinates.
Example:
>>> camera.lookat(0, 0, 0)
- position(self, x, y, z)#
Set the camera position.
- Parameters:
args (
taichi.types.primitive_types
) – 3D coordinates.
Example:
>>> camera.position(1, 1, 1)
- projection_mode(self, mode)#
Camera projection mode, 0 for perspective and 1 for orthogonal.
- right(self, right)#
Set the offset of the right clipping plane in camera frustum.
- Parameters:
right (
taichi.types.primitive_types
) – offset of the right clipping plane.
Example:
>>> camera.right(1.0)
- top(self, top)#
Set the offset of the top clipping plane in camera frustum.
- Parameters:
top (
taichi.types.primitive_types
) – offset of the top clipping plane.
Example:
>>> camera.top(-1.0)
- track_user_inputs(self, window, movement_speed: float = 1.0, yaw_speed: float = 2.0, pitch_speed: float = 2.0, hold_key=None)#
Move the camera according to user inputs. Press w, s, a, d, e, q to move the camera formard, back, left, right, head up, head down, accordingly.
- Parameters:
window (
Window
) – a windown instance.movement_speed (
primitive_types
) – camera movement speed.yaw_speed (
primitive_types
) – speed of changes in yaw angle.pitch_speed (
primitive_types
) – speed of changes in pitch angle.hold_key (
ui
) – User defined key for holding the camera movement.
- up(self, x, y, z)#
Set the camera up vector.
- Parameters:
args (
taichi.types.primitive_types
) – 3D coordinates.
Example:
>>> camera.up(0, 1, 0)
- z_far(self, z_far)#
Set the offset of the far clipping plane in camera frustum.
- Parameters:
far (
taichi.types.primitive_types
) – offset of the far clipping plane.
Example:
>>> camera.left(1000.0)
- z_near(self, z_near)#
Set the offset of the near clipping plane in camera frustum.
- Parameters:
near (
taichi.types.primitive_types
) – offset of the near clipping plane.
Example:
>>> camera.near(0.1)