Skip to main content

he3d_core/
camera.rs

1use he3d_math::{Quat, Vec3};
2
3/// Default distance to the near clipping plane, matching the reference renderer's `HE3D_NEAR_Z`.
4/// 近裁剪平面的默认距离,与参考渲染器的 `HE3D_NEAR_Z` 一致。
5pub const DEFAULT_NEAR: f32 = 0.1;
6
7/// A pinhole camera. A plain value type; it is never stored inside a renderer.
8/// 针孔相机。一个普通的数值类型;它从不被存放在渲染器内部。
9#[derive(Clone, Copy, PartialEq, Debug)]
10pub struct Camera {
11   /// Camera position in world space.
12   /// 相机在世界空间中的位置。
13   pub position: Vec3,
14   /// Camera orientation in world space.
15   /// 相机在世界空间中的朝向。
16   pub orientation: Quat,
17   /// Vertical field of view in degrees.
18   /// 垂直视野,以度为单位。
19   pub fov_y_degrees: f32,
20   /// Near clipping plane distance.
21   /// 近裁剪平面距离。
22   pub near: f32,
23}
24
25impl Camera {
26   /// Construct a camera with the default near-plane distance.
27   /// 用默认的近平面距离构造一个相机。
28   #[must_use]
29   pub const fn new(position: Vec3, orientation: Quat, fov_y_degrees: f32) -> Self {
30      Self {
31         position,
32         orientation,
33         fov_y_degrees,
34         near: DEFAULT_NEAR,
35      }
36   }
37}
38
39impl Default for Camera {
40   fn default() -> Self {
41      Self {
42         position: Vec3::new(0.0, 0.0, 5.0),
43         orientation: Quat::IDENTITY,
44         fov_y_degrees: 90.0,
45         near: DEFAULT_NEAR,
46      }
47   }
48}