Struct Matrix

Source
pub struct Matrix<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N> = [[T; N]; M]> { /* private fields */ }

Implementations§

Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Matrix<T, M, N, Storage>

Source

pub fn from_storage(storage: Storage) -> Self

Source

pub fn zeros() -> Self

Source

pub fn one() -> Self

Examples found in repository?
examples/math/main.rs (line 4)
3fn main() {
4    let m = Matrix::<f32, 4, 4>::one();
5
6    println!("{:10.2}", &m * &m);
7}
Source

pub fn build_with(f: impl FnMut() -> T) -> Self

Source

pub fn build_with_pos(f: impl FnMut(usize, usize) -> T) -> Self

Source

pub fn into_storage(self) -> Storage

Source

pub fn iter(&self) -> impl Iterator<Item = ((usize, usize), &T)>

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = ((usize, usize), &mut T)>

Source§

impl<T: Number + Float, const M: usize> Matrix<T, M, 1>

Source

pub fn normalized(&self) -> Self

Examples found in repository?
examples/run/main.rs (line 92)
27    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
28        let mut latest = Instant::now();
29        let mut v = Vec::<f32>::new();
30        let mut latest_second = Instant::now();
31        scene.add_send_system(
32            move |(events, write_events, id): &mut (
33                ReadE<CustomEvents>,
34                WriteE<CustomEvents>,
35                ReadSystemID,
36            )| {
37                let now = Instant::now();
38
39                v.push(1.0 / (now - latest).as_secs_f32());
40
41                if (now - latest_second).as_secs() > 0 {
42                    let fps = v.iter().sum::<f32>() / v.len() as f32;
43                    println!("fps: {:10.5}, {:10.5}", fps, 1.0 / fps);
44                    latest_second = now;
45                }
46                latest = now;
47            },
48        );
49        scene.add_send_startup_system(
50            |render_objs: &mut WriteC<RenderObject>,
51             transforms: &mut WriteC<Transform>,
52             camera: &mut WriteR<Camera, CustomEvents>| {
53                for i in 0..100 {
54                    for y in 0..100 {
55                        for z in 0..10 {
56                            let e = Entity::new();
57                            render_objs.insert(e, RenderObject::new(Cube, "./img.jpg".to_string()));
58                            transforms.insert(
59                                e,
60                                Transform::new_position(Vector3::new(
61                                    5. * i as f32,
62                                    5. * y as f32,
63                                    5. * z as f32,
64                                )),
65                            );
66                        }
67                    }
68                }
69
70                camera.insert_and_notify(Camera {
71                    eye: Vector3::new(0.0, 0.0, -1.),
72                    dir: Vector3::new(1., 0., 0.),
73                    up: Vector3::new(0., 1., 0.),
74                    aspect: 1.,
75                    fovy: PI / 4.,
76                    znear: 0.1,
77                    zfar: 1000.,
78                });
79            },
80        );
81
82        let mut yaw: f32 = 0.0; // Horizontal rotation around the y-axis
83        let mut pitch: f32 = 0.0; // Vertical rotation
84        scene.add_send_system(
85            move |camera: &mut WriteR<Camera, CustomEvents>, events: &mut ReadE<CustomEvents>| {
86                if let Some(camera) = camera.get_mut() {
87                    let dt = events.dt();
88                    let move_speed = dt * 10.;
89                    let rotation_speed = 4. * dt * camera.fovy / PI;
90
91                    // Get forward (z-axis), right (x-axis), and up (y-axis) direction vectors
92                    let forward = camera.dir.normalized();
93                    let right = forward.cross(&Vector3::unit_y()).normalized();
94                    let up = right.cross(&forward);
95
96                    if events.keyboard().is_pressed(KeyCode::KeyW) {
97                        camera.eye += &forward * move_speed;
98                    }
99                    if events.keyboard().is_pressed(KeyCode::KeyS) {
100                        camera.eye -= &forward * move_speed;
101                    }
102                    if events.keyboard().is_pressed(KeyCode::KeyA) {
103                        camera.eye -= &right * move_speed;
104                    }
105                    if events.keyboard().is_pressed(KeyCode::KeyD) {
106                        camera.eye += &right * move_speed;
107                    }
108                    if events.keyboard().is_pressed(KeyCode::Space) {
109                        camera.eye += &up * move_speed;
110                    }
111                    if events.keyboard().is_pressed(KeyCode::ControlLeft) {
112                        camera.eye -= &up * move_speed;
113                    }
114
115                    match events.mouse_wheel_delta() {
116                        dx if dx != 0. => {
117                            camera.fovy *= if dx.is_positive() { 0.5 } else { 2. };
118                        }
119                        _ => (),
120                    }
121
122                    let (x, y) = events.mouse_dx();
123                    yaw += x * rotation_speed;
124                    pitch -= y * rotation_speed;
125
126                    // Update the camera's direction (yaw and pitch)
127                    let (sin_yaw, cos_yaw) = yaw.sin_cos();
128                    let (sin_pitch, cos_pitch) = pitch.sin_cos();
129
130                    // Calculate the new forward direction after applying yaw and pitch
131                    let new_forward =
132                        Vector3::new(cos_pitch * cos_yaw, sin_pitch, cos_pitch * sin_yaw);
133
134                    camera.dir = new_forward.normalized();
135                }
136            },
137        );
138        let mut is_on = false;
139        scene.add_send_system(
140            move |transforms: &mut WriteC<Transform>,
141                  obj: &mut ReadC<RenderObject>,
142                  events: &mut ReadE<CustomEvents>| {
143                if events.keyboard().is_just_pressed(KeyCode::KeyG) {
144                    is_on = !is_on;
145                    println!("started {}", is_on);
146                }
147                if is_on {
148                    let dt = events.dt();
149                    (transforms.iter_mut(), obj.iter())
150                        .into_wrapper()
151                        .for_each(|(_, (t, _))| {
152                            *t.rotation.x_mut() += dt * 5.;
153                            t.update_raw();
154                        });
155                }
156            },
157        );
158    }
Source

pub fn dot(&self, rhs: &Self) -> T

Source§

impl<T: Number> Matrix<T, 3, 1>

Source

pub fn cross(&self, other: &Vector3<T>) -> Vector3<T>

Examples found in repository?
examples/run/main.rs (line 93)
27    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
28        let mut latest = Instant::now();
29        let mut v = Vec::<f32>::new();
30        let mut latest_second = Instant::now();
31        scene.add_send_system(
32            move |(events, write_events, id): &mut (
33                ReadE<CustomEvents>,
34                WriteE<CustomEvents>,
35                ReadSystemID,
36            )| {
37                let now = Instant::now();
38
39                v.push(1.0 / (now - latest).as_secs_f32());
40
41                if (now - latest_second).as_secs() > 0 {
42                    let fps = v.iter().sum::<f32>() / v.len() as f32;
43                    println!("fps: {:10.5}, {:10.5}", fps, 1.0 / fps);
44                    latest_second = now;
45                }
46                latest = now;
47            },
48        );
49        scene.add_send_startup_system(
50            |render_objs: &mut WriteC<RenderObject>,
51             transforms: &mut WriteC<Transform>,
52             camera: &mut WriteR<Camera, CustomEvents>| {
53                for i in 0..100 {
54                    for y in 0..100 {
55                        for z in 0..10 {
56                            let e = Entity::new();
57                            render_objs.insert(e, RenderObject::new(Cube, "./img.jpg".to_string()));
58                            transforms.insert(
59                                e,
60                                Transform::new_position(Vector3::new(
61                                    5. * i as f32,
62                                    5. * y as f32,
63                                    5. * z as f32,
64                                )),
65                            );
66                        }
67                    }
68                }
69
70                camera.insert_and_notify(Camera {
71                    eye: Vector3::new(0.0, 0.0, -1.),
72                    dir: Vector3::new(1., 0., 0.),
73                    up: Vector3::new(0., 1., 0.),
74                    aspect: 1.,
75                    fovy: PI / 4.,
76                    znear: 0.1,
77                    zfar: 1000.,
78                });
79            },
80        );
81
82        let mut yaw: f32 = 0.0; // Horizontal rotation around the y-axis
83        let mut pitch: f32 = 0.0; // Vertical rotation
84        scene.add_send_system(
85            move |camera: &mut WriteR<Camera, CustomEvents>, events: &mut ReadE<CustomEvents>| {
86                if let Some(camera) = camera.get_mut() {
87                    let dt = events.dt();
88                    let move_speed = dt * 10.;
89                    let rotation_speed = 4. * dt * camera.fovy / PI;
90
91                    // Get forward (z-axis), right (x-axis), and up (y-axis) direction vectors
92                    let forward = camera.dir.normalized();
93                    let right = forward.cross(&Vector3::unit_y()).normalized();
94                    let up = right.cross(&forward);
95
96                    if events.keyboard().is_pressed(KeyCode::KeyW) {
97                        camera.eye += &forward * move_speed;
98                    }
99                    if events.keyboard().is_pressed(KeyCode::KeyS) {
100                        camera.eye -= &forward * move_speed;
101                    }
102                    if events.keyboard().is_pressed(KeyCode::KeyA) {
103                        camera.eye -= &right * move_speed;
104                    }
105                    if events.keyboard().is_pressed(KeyCode::KeyD) {
106                        camera.eye += &right * move_speed;
107                    }
108                    if events.keyboard().is_pressed(KeyCode::Space) {
109                        camera.eye += &up * move_speed;
110                    }
111                    if events.keyboard().is_pressed(KeyCode::ControlLeft) {
112                        camera.eye -= &up * move_speed;
113                    }
114
115                    match events.mouse_wheel_delta() {
116                        dx if dx != 0. => {
117                            camera.fovy *= if dx.is_positive() { 0.5 } else { 2. };
118                        }
119                        _ => (),
120                    }
121
122                    let (x, y) = events.mouse_dx();
123                    yaw += x * rotation_speed;
124                    pitch -= y * rotation_speed;
125
126                    // Update the camera's direction (yaw and pitch)
127                    let (sin_yaw, cos_yaw) = yaw.sin_cos();
128                    let (sin_pitch, cos_pitch) = pitch.sin_cos();
129
130                    // Calculate the new forward direction after applying yaw and pitch
131                    let new_forward =
132                        Vector3::new(cos_pitch * cos_yaw, sin_pitch, cos_pitch * sin_yaw);
133
134                    camera.dir = new_forward.normalized();
135                }
136            },
137        );
138        let mut is_on = false;
139        scene.add_send_system(
140            move |transforms: &mut WriteC<Transform>,
141                  obj: &mut ReadC<RenderObject>,
142                  events: &mut ReadE<CustomEvents>| {
143                if events.keyboard().is_just_pressed(KeyCode::KeyG) {
144                    is_on = !is_on;
145                    println!("started {}", is_on);
146                }
147                if is_on {
148                    let dt = events.dt();
149                    (transforms.iter_mut(), obj.iter())
150                        .into_wrapper()
151                        .for_each(|(_, (t, _))| {
152                            *t.rotation.x_mut() += dt * 5.;
153                            t.update_raw();
154                        });
155                }
156            },
157        );
158    }
Source§

impl<T: Number + Float + Display> Matrix<T, 4, 4>

Source

pub fn look_to_rh( eye: &Vector3<T>, dir: &Vector3<T>, up: &Vector3<T>, ) -> Matrix4<T>

Source

pub fn perspective(fovy_rad: T, aspect: T, znear: T, zfar: T) -> Matrix4<T>

Source

pub fn from_position(position: &Vector3<T>) -> Self

Source

pub fn from_quaternion(quat: &Vector4<T>) -> Self

Source§

impl<T: Number + Float> Matrix<T, 4, 1>

Source

pub fn from_euler_to_quaternion(src: &Vector3<T>) -> Self

Source§

impl<T: Number> Matrix<T, 2, 1>

Source

pub fn new(x: T, y: T) -> Self

Source

pub fn x(&self) -> &T

Source

pub fn y(&self) -> &T

Source

pub fn x_mut(&mut self) -> &mut T

Source

pub fn y_mut(&mut self) -> &mut T

Source§

impl<T: Number> Matrix<T, 3, 1>

Source

pub fn new(x: T, y: T, z: T) -> Self

Examples found in repository?
examples/run/main.rs (lines 60-64)
27    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
28        let mut latest = Instant::now();
29        let mut v = Vec::<f32>::new();
30        let mut latest_second = Instant::now();
31        scene.add_send_system(
32            move |(events, write_events, id): &mut (
33                ReadE<CustomEvents>,
34                WriteE<CustomEvents>,
35                ReadSystemID,
36            )| {
37                let now = Instant::now();
38
39                v.push(1.0 / (now - latest).as_secs_f32());
40
41                if (now - latest_second).as_secs() > 0 {
42                    let fps = v.iter().sum::<f32>() / v.len() as f32;
43                    println!("fps: {:10.5}, {:10.5}", fps, 1.0 / fps);
44                    latest_second = now;
45                }
46                latest = now;
47            },
48        );
49        scene.add_send_startup_system(
50            |render_objs: &mut WriteC<RenderObject>,
51             transforms: &mut WriteC<Transform>,
52             camera: &mut WriteR<Camera, CustomEvents>| {
53                for i in 0..100 {
54                    for y in 0..100 {
55                        for z in 0..10 {
56                            let e = Entity::new();
57                            render_objs.insert(e, RenderObject::new(Cube, "./img.jpg".to_string()));
58                            transforms.insert(
59                                e,
60                                Transform::new_position(Vector3::new(
61                                    5. * i as f32,
62                                    5. * y as f32,
63                                    5. * z as f32,
64                                )),
65                            );
66                        }
67                    }
68                }
69
70                camera.insert_and_notify(Camera {
71                    eye: Vector3::new(0.0, 0.0, -1.),
72                    dir: Vector3::new(1., 0., 0.),
73                    up: Vector3::new(0., 1., 0.),
74                    aspect: 1.,
75                    fovy: PI / 4.,
76                    znear: 0.1,
77                    zfar: 1000.,
78                });
79            },
80        );
81
82        let mut yaw: f32 = 0.0; // Horizontal rotation around the y-axis
83        let mut pitch: f32 = 0.0; // Vertical rotation
84        scene.add_send_system(
85            move |camera: &mut WriteR<Camera, CustomEvents>, events: &mut ReadE<CustomEvents>| {
86                if let Some(camera) = camera.get_mut() {
87                    let dt = events.dt();
88                    let move_speed = dt * 10.;
89                    let rotation_speed = 4. * dt * camera.fovy / PI;
90
91                    // Get forward (z-axis), right (x-axis), and up (y-axis) direction vectors
92                    let forward = camera.dir.normalized();
93                    let right = forward.cross(&Vector3::unit_y()).normalized();
94                    let up = right.cross(&forward);
95
96                    if events.keyboard().is_pressed(KeyCode::KeyW) {
97                        camera.eye += &forward * move_speed;
98                    }
99                    if events.keyboard().is_pressed(KeyCode::KeyS) {
100                        camera.eye -= &forward * move_speed;
101                    }
102                    if events.keyboard().is_pressed(KeyCode::KeyA) {
103                        camera.eye -= &right * move_speed;
104                    }
105                    if events.keyboard().is_pressed(KeyCode::KeyD) {
106                        camera.eye += &right * move_speed;
107                    }
108                    if events.keyboard().is_pressed(KeyCode::Space) {
109                        camera.eye += &up * move_speed;
110                    }
111                    if events.keyboard().is_pressed(KeyCode::ControlLeft) {
112                        camera.eye -= &up * move_speed;
113                    }
114
115                    match events.mouse_wheel_delta() {
116                        dx if dx != 0. => {
117                            camera.fovy *= if dx.is_positive() { 0.5 } else { 2. };
118                        }
119                        _ => (),
120                    }
121
122                    let (x, y) = events.mouse_dx();
123                    yaw += x * rotation_speed;
124                    pitch -= y * rotation_speed;
125
126                    // Update the camera's direction (yaw and pitch)
127                    let (sin_yaw, cos_yaw) = yaw.sin_cos();
128                    let (sin_pitch, cos_pitch) = pitch.sin_cos();
129
130                    // Calculate the new forward direction after applying yaw and pitch
131                    let new_forward =
132                        Vector3::new(cos_pitch * cos_yaw, sin_pitch, cos_pitch * sin_yaw);
133
134                    camera.dir = new_forward.normalized();
135                }
136            },
137        );
138        let mut is_on = false;
139        scene.add_send_system(
140            move |transforms: &mut WriteC<Transform>,
141                  obj: &mut ReadC<RenderObject>,
142                  events: &mut ReadE<CustomEvents>| {
143                if events.keyboard().is_just_pressed(KeyCode::KeyG) {
144                    is_on = !is_on;
145                    println!("started {}", is_on);
146                }
147                if is_on {
148                    let dt = events.dt();
149                    (transforms.iter_mut(), obj.iter())
150                        .into_wrapper()
151                        .for_each(|(_, (t, _))| {
152                            *t.rotation.x_mut() += dt * 5.;
153                            t.update_raw();
154                        });
155                }
156            },
157        );
158    }
Source

pub fn unit_y() -> Self

Examples found in repository?
examples/run/main.rs (line 93)
27    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
28        let mut latest = Instant::now();
29        let mut v = Vec::<f32>::new();
30        let mut latest_second = Instant::now();
31        scene.add_send_system(
32            move |(events, write_events, id): &mut (
33                ReadE<CustomEvents>,
34                WriteE<CustomEvents>,
35                ReadSystemID,
36            )| {
37                let now = Instant::now();
38
39                v.push(1.0 / (now - latest).as_secs_f32());
40
41                if (now - latest_second).as_secs() > 0 {
42                    let fps = v.iter().sum::<f32>() / v.len() as f32;
43                    println!("fps: {:10.5}, {:10.5}", fps, 1.0 / fps);
44                    latest_second = now;
45                }
46                latest = now;
47            },
48        );
49        scene.add_send_startup_system(
50            |render_objs: &mut WriteC<RenderObject>,
51             transforms: &mut WriteC<Transform>,
52             camera: &mut WriteR<Camera, CustomEvents>| {
53                for i in 0..100 {
54                    for y in 0..100 {
55                        for z in 0..10 {
56                            let e = Entity::new();
57                            render_objs.insert(e, RenderObject::new(Cube, "./img.jpg".to_string()));
58                            transforms.insert(
59                                e,
60                                Transform::new_position(Vector3::new(
61                                    5. * i as f32,
62                                    5. * y as f32,
63                                    5. * z as f32,
64                                )),
65                            );
66                        }
67                    }
68                }
69
70                camera.insert_and_notify(Camera {
71                    eye: Vector3::new(0.0, 0.0, -1.),
72                    dir: Vector3::new(1., 0., 0.),
73                    up: Vector3::new(0., 1., 0.),
74                    aspect: 1.,
75                    fovy: PI / 4.,
76                    znear: 0.1,
77                    zfar: 1000.,
78                });
79            },
80        );
81
82        let mut yaw: f32 = 0.0; // Horizontal rotation around the y-axis
83        let mut pitch: f32 = 0.0; // Vertical rotation
84        scene.add_send_system(
85            move |camera: &mut WriteR<Camera, CustomEvents>, events: &mut ReadE<CustomEvents>| {
86                if let Some(camera) = camera.get_mut() {
87                    let dt = events.dt();
88                    let move_speed = dt * 10.;
89                    let rotation_speed = 4. * dt * camera.fovy / PI;
90
91                    // Get forward (z-axis), right (x-axis), and up (y-axis) direction vectors
92                    let forward = camera.dir.normalized();
93                    let right = forward.cross(&Vector3::unit_y()).normalized();
94                    let up = right.cross(&forward);
95
96                    if events.keyboard().is_pressed(KeyCode::KeyW) {
97                        camera.eye += &forward * move_speed;
98                    }
99                    if events.keyboard().is_pressed(KeyCode::KeyS) {
100                        camera.eye -= &forward * move_speed;
101                    }
102                    if events.keyboard().is_pressed(KeyCode::KeyA) {
103                        camera.eye -= &right * move_speed;
104                    }
105                    if events.keyboard().is_pressed(KeyCode::KeyD) {
106                        camera.eye += &right * move_speed;
107                    }
108                    if events.keyboard().is_pressed(KeyCode::Space) {
109                        camera.eye += &up * move_speed;
110                    }
111                    if events.keyboard().is_pressed(KeyCode::ControlLeft) {
112                        camera.eye -= &up * move_speed;
113                    }
114
115                    match events.mouse_wheel_delta() {
116                        dx if dx != 0. => {
117                            camera.fovy *= if dx.is_positive() { 0.5 } else { 2. };
118                        }
119                        _ => (),
120                    }
121
122                    let (x, y) = events.mouse_dx();
123                    yaw += x * rotation_speed;
124                    pitch -= y * rotation_speed;
125
126                    // Update the camera's direction (yaw and pitch)
127                    let (sin_yaw, cos_yaw) = yaw.sin_cos();
128                    let (sin_pitch, cos_pitch) = pitch.sin_cos();
129
130                    // Calculate the new forward direction after applying yaw and pitch
131                    let new_forward =
132                        Vector3::new(cos_pitch * cos_yaw, sin_pitch, cos_pitch * sin_yaw);
133
134                    camera.dir = new_forward.normalized();
135                }
136            },
137        );
138        let mut is_on = false;
139        scene.add_send_system(
140            move |transforms: &mut WriteC<Transform>,
141                  obj: &mut ReadC<RenderObject>,
142                  events: &mut ReadE<CustomEvents>| {
143                if events.keyboard().is_just_pressed(KeyCode::KeyG) {
144                    is_on = !is_on;
145                    println!("started {}", is_on);
146                }
147                if is_on {
148                    let dt = events.dt();
149                    (transforms.iter_mut(), obj.iter())
150                        .into_wrapper()
151                        .for_each(|(_, (t, _))| {
152                            *t.rotation.x_mut() += dt * 5.;
153                            t.update_raw();
154                        });
155                }
156            },
157        );
158    }
Source

pub fn x(&self) -> &T

Source

pub fn y(&self) -> &T

Source

pub fn z(&self) -> &T

Source

pub fn x_mut(&mut self) -> &mut T

Examples found in repository?
examples/run/main.rs (line 152)
27    fn build(&self, scene: &mut matrix_engine::engine::scene::Scene<CustomEvents>) {
28        let mut latest = Instant::now();
29        let mut v = Vec::<f32>::new();
30        let mut latest_second = Instant::now();
31        scene.add_send_system(
32            move |(events, write_events, id): &mut (
33                ReadE<CustomEvents>,
34                WriteE<CustomEvents>,
35                ReadSystemID,
36            )| {
37                let now = Instant::now();
38
39                v.push(1.0 / (now - latest).as_secs_f32());
40
41                if (now - latest_second).as_secs() > 0 {
42                    let fps = v.iter().sum::<f32>() / v.len() as f32;
43                    println!("fps: {:10.5}, {:10.5}", fps, 1.0 / fps);
44                    latest_second = now;
45                }
46                latest = now;
47            },
48        );
49        scene.add_send_startup_system(
50            |render_objs: &mut WriteC<RenderObject>,
51             transforms: &mut WriteC<Transform>,
52             camera: &mut WriteR<Camera, CustomEvents>| {
53                for i in 0..100 {
54                    for y in 0..100 {
55                        for z in 0..10 {
56                            let e = Entity::new();
57                            render_objs.insert(e, RenderObject::new(Cube, "./img.jpg".to_string()));
58                            transforms.insert(
59                                e,
60                                Transform::new_position(Vector3::new(
61                                    5. * i as f32,
62                                    5. * y as f32,
63                                    5. * z as f32,
64                                )),
65                            );
66                        }
67                    }
68                }
69
70                camera.insert_and_notify(Camera {
71                    eye: Vector3::new(0.0, 0.0, -1.),
72                    dir: Vector3::new(1., 0., 0.),
73                    up: Vector3::new(0., 1., 0.),
74                    aspect: 1.,
75                    fovy: PI / 4.,
76                    znear: 0.1,
77                    zfar: 1000.,
78                });
79            },
80        );
81
82        let mut yaw: f32 = 0.0; // Horizontal rotation around the y-axis
83        let mut pitch: f32 = 0.0; // Vertical rotation
84        scene.add_send_system(
85            move |camera: &mut WriteR<Camera, CustomEvents>, events: &mut ReadE<CustomEvents>| {
86                if let Some(camera) = camera.get_mut() {
87                    let dt = events.dt();
88                    let move_speed = dt * 10.;
89                    let rotation_speed = 4. * dt * camera.fovy / PI;
90
91                    // Get forward (z-axis), right (x-axis), and up (y-axis) direction vectors
92                    let forward = camera.dir.normalized();
93                    let right = forward.cross(&Vector3::unit_y()).normalized();
94                    let up = right.cross(&forward);
95
96                    if events.keyboard().is_pressed(KeyCode::KeyW) {
97                        camera.eye += &forward * move_speed;
98                    }
99                    if events.keyboard().is_pressed(KeyCode::KeyS) {
100                        camera.eye -= &forward * move_speed;
101                    }
102                    if events.keyboard().is_pressed(KeyCode::KeyA) {
103                        camera.eye -= &right * move_speed;
104                    }
105                    if events.keyboard().is_pressed(KeyCode::KeyD) {
106                        camera.eye += &right * move_speed;
107                    }
108                    if events.keyboard().is_pressed(KeyCode::Space) {
109                        camera.eye += &up * move_speed;
110                    }
111                    if events.keyboard().is_pressed(KeyCode::ControlLeft) {
112                        camera.eye -= &up * move_speed;
113                    }
114
115                    match events.mouse_wheel_delta() {
116                        dx if dx != 0. => {
117                            camera.fovy *= if dx.is_positive() { 0.5 } else { 2. };
118                        }
119                        _ => (),
120                    }
121
122                    let (x, y) = events.mouse_dx();
123                    yaw += x * rotation_speed;
124                    pitch -= y * rotation_speed;
125
126                    // Update the camera's direction (yaw and pitch)
127                    let (sin_yaw, cos_yaw) = yaw.sin_cos();
128                    let (sin_pitch, cos_pitch) = pitch.sin_cos();
129
130                    // Calculate the new forward direction after applying yaw and pitch
131                    let new_forward =
132                        Vector3::new(cos_pitch * cos_yaw, sin_pitch, cos_pitch * sin_yaw);
133
134                    camera.dir = new_forward.normalized();
135                }
136            },
137        );
138        let mut is_on = false;
139        scene.add_send_system(
140            move |transforms: &mut WriteC<Transform>,
141                  obj: &mut ReadC<RenderObject>,
142                  events: &mut ReadE<CustomEvents>| {
143                if events.keyboard().is_just_pressed(KeyCode::KeyG) {
144                    is_on = !is_on;
145                    println!("started {}", is_on);
146                }
147                if is_on {
148                    let dt = events.dt();
149                    (transforms.iter_mut(), obj.iter())
150                        .into_wrapper()
151                        .for_each(|(_, (t, _))| {
152                            *t.rotation.x_mut() += dt * 5.;
153                            t.update_raw();
154                        });
155                }
156            },
157        );
158    }
Source

pub fn y_mut(&mut self) -> &mut T

Source

pub fn z_mut(&mut self) -> &mut T

Source§

impl<T: Number> Matrix<T, 4, 1>

Source

pub fn new(x: T, y: T, z: T, w: T) -> Self

Source

pub fn x(&self) -> &T

Source

pub fn y(&self) -> &T

Source

pub fn z(&self) -> &T

Source

pub fn w(&self) -> &T

Source

pub fn x_mut(&mut self) -> &mut T

Source

pub fn y_mut(&mut self) -> &mut T

Source

pub fn z_mut(&mut self) -> &mut T

Source

pub fn w_mut(&mut self) -> &mut T

Trait Implementations§

Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Add for &Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Number + AddAssign<T>, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> AddAssign for Matrix<T, M, N, Storage>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<T: Number + Display, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Display for Matrix<T, M, N, Storage>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Div<T> for &Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the / operator.
Source§

fn div(self, other: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Index<(usize, usize)> for Matrix<T, M, N, Storage>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> IndexMut<(usize, usize)> for Matrix<T, M, N, Storage>

Source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, const P: usize, StorageA: MatrixStoragable<T, M, N>, StorageB: MatrixStoragable<T, N, P>> Mul<&Matrix<T, N, P, StorageB>> for &Matrix<T, M, N, StorageA>

Source§

type Output = Matrix<T, M, P, <StorageA as MatrixStoragable<T, M, N>>::SelfWith<M, P>>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Matrix<T, N, P, StorageB>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Mul<T> for &Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Neg for &Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Neg for Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Number, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> Sub for &Matrix<T, M, N, Storage>

Source§

type Output = Matrix<T, M, N, Storage>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Number + SubAssign<T>, const M: usize, const N: usize, Storage: MatrixStoragable<T, M, N>> SubAssign for Matrix<T, M, N, Storage>

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T, const M: usize, const N: usize, Storage> Freeze for Matrix<T, M, N, Storage>
where Storage: Freeze,

§

impl<T, const M: usize, const N: usize, Storage> RefUnwindSafe for Matrix<T, M, N, Storage>
where Storage: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, const M: usize, const N: usize, Storage> Send for Matrix<T, M, N, Storage>
where Storage: Send, T: Send,

§

impl<T, const M: usize, const N: usize, Storage> Sync for Matrix<T, M, N, Storage>
where Storage: Sync, T: Sync,

§

impl<T, const M: usize, const N: usize, Storage> Unpin for Matrix<T, M, N, Storage>
where Storage: Unpin, T: Unpin,

§

impl<T, const M: usize, const N: usize, Storage> UnwindSafe for Matrix<T, M, N, Storage>
where Storage: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeIDable for T
where T: 'static,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Component for T
where T: Send + Sync + Any,

Source§

impl<T> Resource for T
where T: Send + 'static + ?Sized,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,