 | Introduction |  |
In 3D graphics, the camera is a virtual viewpoint through which we see the scene. Like a physical camera, a virtual camera determines what part of a scene is visible and how it’s displayed. This chapter explores how to set up, manipulate, and animate a camera in WebGPU, discussing concepts like camera positioning, movement, and the math behind transformations. We’ll also examine how to animate a camera along a path to create smooth scene transitions and dynamic viewpoints.
Camera Motion vs. Scene Motion
It’s essential to differentiate between moving the camera and moving objects in the scene. Moving the camera alters the viewpoint from which we observe the scene, while moving an object changes its position within the scene. When the camera moves, the entire scene appears to shift in the opposite direction, as though the viewer's perspective itself is moving.
A Camera Definition
In WebGPU, a camera is defined by its position in space, the direction it points, and the up vector, which determines the camera's orientation. The `lookAt` function in `glMatrix` is often used to set up a camera in WebGPU. This function creates a view matrix that orients the camera correctly based on these parameters.
Specifying a Virtual Camera
To set up a virtual camera, we define three key properties:
• Position: The camera’s location in 3D space.
• Target: The point in space the camera is looking at.
• Up Vector: Specifies the camera's vertical direction, typically `[0, 1, 0]` for a camera with a standard upright orientation.
Example code to specify a camera with lookAt :
|