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   pub position: Vec3,
12   pub orientation: Quat,
13   /// Vertical field of view in degrees.
14   /// 垂直视野,以度为单位。
15   pub fov_y_degrees: f32,
16   /// Near clipping plane distance.
17   /// 近裁剪平面距离。
18   pub near: f32,
19}
20
21impl Camera {
22   pub const fn new(position: Vec3, orientation: Quat, fov_y_degrees: f32) -> Self {
23      Self {
24         position,
25         orientation,
26         fov_y_degrees,
27         near: DEFAULT_NEAR,
28      }
29   }
30}
31
32impl Default for Camera {
33   fn default() -> Self {
34      Self {
35         position: Vec3::new(0.0, 0.0, 5.0),
36         orientation: Quat::IDENTITY,
37         fov_y_degrees: 90.0,
38         near: DEFAULT_NEAR,
39      }
40   }
41}