Calculate the vectors of a camera pointing to a target point. Args: target_position: point the camera is pointing to. camera_offset: offset of the camera from the target point. Returns: Camera position, direction and up vectors
(
target_position: NDArray[np.float64], offset: Optional[NDArray[np.float64]] = None
)
| 21 | |
| 22 | |
| 23 | def camera_vectors_from_target_position( |
| 24 | target_position: NDArray[np.float64], offset: Optional[NDArray[np.float64]] = None |
| 25 | ) -> tuple[list[float], list[float], list[float]]: |
| 26 | """ |
| 27 | Calculate the vectors of a camera pointing to a target point. |
| 28 | |
| 29 | Args: |
| 30 | target_position: point the camera is pointing to. |
| 31 | camera_offset: offset of the camera from the target point. |
| 32 | |
| 33 | Returns: |
| 34 | Camera position, direction and up vectors |
| 35 | """ |
| 36 | camera_offset = np.array((5, 5, 5)) if offset is None else offset |
| 37 | camera_position = target_position + camera_offset |
| 38 | camera_direction = unit_vector(-camera_offset) # pylint: disable=invalid-unary-operand-type |
| 39 | camera_right = unit_vector(np.cross(np.array([0.0, 0.0, 1.0]), camera_direction)) |
| 40 | camera_up = unit_vector(np.cross(camera_direction, camera_right)) |
| 41 | return camera_position.tolist(), camera_direction.tolist(), camera_up.tolist() |
| 42 | |
| 43 | |
| 44 | def unit_vector(v: NDArray[np.float64]) -> NDArray[np.float64]: |
no test coverage detected