he3d_core/camera.rs
1use he3d_math::{Quat, Vec3};
2
3/// Default distance to the near clipping plane.
4///
5/// It is small but not zero: a near plane at the eye would push the far end of the
6/// inverse-depth range to infinity and destroy depth precision up close.
7/// 近裁剪平面的默认距离。它很小但不为零:若近平面落在眼睛处,逆深度范围远端的精度会被
8/// 推到无穷,近处深度精度随之毁掉。
9pub const DEFAULT_NEAR: f32 = 0.1;
10
11/// A pinhole camera. A plain value type; it is never stored inside a renderer.
12/// 针孔相机。一个普通的数值类型;它从不被存放在渲染器内部。
13#[derive(Clone, Copy, PartialEq, Debug)]
14pub struct Camera {
15 /// Camera position in world space.
16 /// 相机在世界空间中的位置。
17 pub position: Vec3,
18 /// Camera orientation in world space.
19 /// 相机在世界空间中的朝向。
20 pub orientation: Quat,
21 /// Vertical field of view in degrees.
22 /// 垂直视野,以度为单位。
23 pub fov_y_degrees: f32,
24 /// Near clipping plane distance.
25 /// 近裁剪平面距离。
26 pub near: f32,
27}
28
29impl Camera {
30 /// Construct a camera with the default near-plane distance.
31 /// 用默认的近平面距离构造一个相机。
32 #[must_use]
33 pub const fn new(position: Vec3, orientation: Quat, fov_y_degrees: f32) -> Self {
34 Self {
35 position,
36 orientation,
37 fov_y_degrees,
38 near: DEFAULT_NEAR,
39 }
40 }
41}
42
43impl Default for Camera {
44 fn default() -> Self {
45 Self {
46 position: Vec3::new(0.0, 0.0, 5.0),
47 orientation: Quat::IDENTITY,
48 fov_y_degrees: 90.0,
49 near: DEFAULT_NEAR,
50 }
51 }
52}