lookAt
Creates and returns a 4x4 view matrix that transforms coordinates from world space to camera (view) space. This is a standard "look-at" matrix, robustly handling common edge cases.
The resulting matrix defines a view where the camera is positioned at eye, looks towards target, and its orientation is influenced by the upInput vector (which typically defines the "world's up" direction). The camera is oriented to look down its local negative Z-axis in a right-handed coordinate system.
Edge cases handled:
If
eyeandtargetare coincident (distance < 1e-6f), an identity matrix is returned.upInputmust be a non-negligible vector (length > 1e-6f), otherwise, anIllegalArgumentExceptionis thrown.If
upInputis collinear with the viewing direction (target - eye), a stable orthogonal basis is computed by choosing an alternative "up" direction.
The matrix is suitable for post-multiplying column vectors (e.g., P_view = ViewMatrix * P_world).
Return
A new Matrix4 view matrix. Returns an identity matrix if eye and target are coincident.
Parameters
The position of the camera (the "eye" point) in world space.
The point in world space that the camera is looking at.
A vector indicating the general "up" direction in the world (e.g., Vector3(0f, 1f, 0f) for Y-up). Must be a non-zero vector (length greater than 1e-6f).
Throws
if upInput's length is less than or equal to 1e-6f.