three_rs/cameras/
array_camera.rs1use std::ops::{Deref, DerefMut};
4
5use super::{PerspectiveCamera, RenderCamera};
6use crate::core::Layers;
7use crate::math::{CoordinateSystem, Matrix4};
8
9#[derive(Clone)]
21pub struct ArrayCamera {
22 pub camera: PerspectiveCamera,
25 pub cameras: Vec<PerspectiveCamera>,
27}
28
29impl ArrayCamera {
30 pub fn new(cameras: Vec<PerspectiveCamera>) -> Self {
33 Self {
34 camera: PerspectiveCamera::new(50.0, 1.0, 0.1, 2000.0),
35 cameras,
36 }
37 }
38}
39
40impl Deref for ArrayCamera {
41 type Target = PerspectiveCamera;
42 fn deref(&self) -> &PerspectiveCamera {
43 &self.camera
44 }
45}
46
47impl DerefMut for ArrayCamera {
48 fn deref_mut(&mut self) -> &mut PerspectiveCamera {
49 &mut self.camera
50 }
51}
52
53impl RenderCamera for ArrayCamera {
54 fn far(&self) -> f64 {
55 self.camera.far
56 }
57 fn near(&self) -> f64 {
58 self.camera.near
59 }
60 fn is_perspective_camera(&self) -> bool {
61 true
62 }
63 fn update_matrix_world(&mut self) {
64 self.camera.update_matrix_world();
65 }
66 fn set_view_offset(
70 &mut self,
71 full_width: f64,
72 full_height: f64,
73 x: f64,
74 y: f64,
75 width: f64,
76 height: f64,
77 ) {
78 self.camera
79 .set_view_offset(full_width, full_height, x, y, width, height);
80 }
81 fn clear_view_offset(&mut self) {
82 self.camera.clear_view_offset();
83 }
84 fn projection_matrix(&self) -> Matrix4 {
85 self.camera.projection_matrix
86 }
87 fn projection_matrix_inverse(&self) -> Matrix4 {
88 self.camera.projection_matrix_inverse
89 }
90 fn matrix_world_inverse(&self) -> Matrix4 {
91 self.camera.matrix_world_inverse
92 }
93 fn coordinate_system(&self) -> CoordinateSystem {
94 self.camera.coordinate_system
95 }
96 fn matrix_world(&self) -> Matrix4 {
97 self.camera.node.borrow().matrix_world
98 }
99 fn layers(&self) -> Layers {
100 self.camera.node.borrow().layers
101 }
102 fn id(&self) -> u32 {
103 self.camera.node.borrow().id
104 }
105 fn sub_cameras(&self) -> &[PerspectiveCamera] {
106 &self.cameras
107 }
108}