Mat4

Struct Mat4 

Source
pub struct Mat4 { /* private fields */ }
Expand description

a matrix often used for transformations in glium

Implementations§

Source§

impl Mat4

Source

pub const IDENTITY: Mat4

Source

pub const fn from_column_major_array(array: [[f32; 4]; 4]) -> Mat4

Source

pub const fn into_column_major_array(self) -> [[f32; 4]; 4]

Source

pub const fn from_row_major_array(array: [[f32; 4]; 4]) -> Mat4

Source

pub const fn into_row_major_array(self) -> [[f32; 4]; 4]

Source

pub const fn from_scale(scale: Vec3) -> Mat4

Examples found in repository?
examples/simple-fxaa.rs (line 177)
13fn main() {
14    use Action::*;
15    let event_loop = EventLoop::new().unwrap();
16    event_loop.set_control_flow(ControlFlow::Poll);
17
18    let mut colour = ResizableTexture2d::default();
19    let mut depth = ResizableDepthTexture2d::default();
20
21    let input = { use base_input_codes::*; input_map!(
22        (Left,    ArrowLeft,  KeyA, LeftStickLeft ),
23        (Right,   ArrowRight, KeyD, LeftStickRight),
24        (Forward, ArrowUp,    KeyW, LeftStickUp   ),
25        (Back,    ArrowDown,  KeyS, LeftStickDown ),
26        (LookRight, MouseMoveRight, RightStickRight),
27        (LookLeft,  MouseMoveLeft,  RightStickLeft ),
28        (LookUp,    MouseMoveUp,    RightStickUp   ),
29        (LookDown,  MouseMoveDown,  RightStickDown ),
30        (FXAA,      KeyF,       GamepadInput::North)
31    ) };
32    struct Graphics {
33        screen_indices: IndexBuffer<u32>,
34        screen_vertices: VertexBuffer<Vertex>,
35        screen_uvs: VertexBuffer<TextureCoords>,
36
37        teapot_indices: IndexBuffer<u16>,
38        teapot_vertices: VertexBuffer<Vertex>,
39        teapot_uvs: VertexBuffer<TextureCoords>,
40        teapot_normals: VertexBuffer<Normal>,
41
42        fxaa: Program, normal: Program, program: Program
43    }
44    let graphics: Rc<RefCell<Option<Graphics>>> = Rc::default();
45    let graphics_setup = graphics.clone();
46
47    let draw_parameters = DrawParameters {
48        backface_culling: draw_parameters::BackfaceCullingMode::CullClockwise,
49        ..params::alias_3d()
50    };
51    let mut fxaa_on = true;
52    
53    let mut pos = vec3(0.0, 0.0, -30.0);
54    let mut rot = vec2(0.0, 0.0);
55    
56    let mut frame_start = Instant::now();
57
58    thin_engine::builder(input).with_setup(|display, window, _| {
59        window.set_title("FXAA Test");
60        let _ = window.set_cursor_grab(CursorGrabMode::Confined);
61        let _ = window.set_cursor_grab(CursorGrabMode::Locked);
62        window.set_cursor_visible(false);
63
64        let (screen_indices, screen_vertices, screen_uvs) = mesh!(
65            display, &screen::INDICES, &screen::VERTICES, &screen::UVS
66        ).unwrap();
67        let (teapot_indices, teapot_vertices, teapot_uvs, teapot_normals) = mesh!(
68            display, &teapot::INDICES, &teapot::VERTICES, &[] as &[TextureCoords; 0], &teapot::NORMALS
69        ).unwrap();
70
71        let program = Program::from_source(
72            display,
73            "#version 140
74            in vec3 position;
75            in vec3 normal;
76            
77            out vec3 v_normal;
78
79            uniform mat4 model;
80            uniform mat4 perspective;
81            uniform mat4 camera;
82
83            void main() {
84                mat3 norm_mat = transpose(inverse(mat3(camera * model)));
85                v_normal = normalize(norm_mat * normal);
86                gl_Position = perspective * camera * model * vec4(position, 1);
87            }",
88            "#version 140
89            out vec4 colour;
90            in vec3 v_normal;
91            uniform vec3 light;
92            uniform mat4 camera;
93            uniform vec3 ambient;
94            uniform vec3 albedo;
95            uniform float shine;
96            void main() {
97                vec3 camera_dir = inverse(mat3(camera)) * vec3(0, 0, -1);
98                vec3 half_dir = normalize(camera_dir + light);
99                float specular = pow(max(dot(half_dir, v_normal), 0.0), shine);
100                float light_level = max(dot(light, v_normal), 0.0);
101                colour = vec4(albedo * light_level + ambient + vec3(specular), 1.0);
102            }", None
103        ).unwrap();
104        let fxaa = shaders::fxaa_shader(display).unwrap();
105        let normal = Program::from_source(
106            display,
107            "#version 140
108            in vec2 texture_coords;
109            out vec2 uv;
110            in vec3 position;
111            void main() {
112                uv = texture_coords;
113                gl_Position = vec4(position, 1);
114            }", 
115            "#version 140
116            in vec2 uv;
117            uniform sampler2D tex;
118            out vec4 colour;
119            void main() {
120                colour = texture(tex, uv);
121            }", None
122        ).unwrap();
123        graphics_setup.replace(Some(Graphics {
124            screen_indices, screen_vertices, screen_uvs,
125            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
126            program, normal, fxaa
127        }));
128    }).with_update(|input, display, _, _, _| {
129        let graphics = graphics.borrow();
130        let Graphics {
131            screen_indices, screen_vertices, screen_uvs,
132            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
133            program, normal, fxaa
134        } = graphics.as_ref().unwrap();
135        let teapot_mesh = (teapot_vertices, teapot_normals, teapot_uvs);
136        let screen_mesh = (screen_vertices, screen_uvs);
137
138        let delta_time = frame_start.elapsed().as_secs_f32();
139        frame_start = Instant::now();
140
141        // using a small resolution to better show the effect of fxaa.
142        let size = (380, 216);
143        display.resize(size);
144        depth.resize_to_display(&display);
145        colour.resize_to_display(&display);
146
147        // press f or gamepad north to toggle FXAA
148        if input.pressed(FXAA) { fxaa_on = !fxaa_on }
149
150        let colour = colour.texture();
151        let depth = depth.texture();
152        let mut frame = SimpleFrameBuffer::with_depth_buffer(
153            display, colour, depth
154        ).unwrap();
155
156        let perspective = Mat4::perspective_3d(size, 1.0, 1024.0, 0.1);
157
158        // set camera rotation
159        let look_move = input.dir(LookRight, LookLeft, LookUp, LookDown);
160        rot += look_move.scale(delta_time * 15.0);
161        rot.y = rot.y.clamp(-PI / 2.0, PI / 2.0);
162        let rx = Quat::from_y_rot(rot.x);
163        let ry = Quat::from_x_rot(-rot.y);
164        let rot = rx * ry;
165
166        // move player based on camera
167        let dir = input.dir_max_len_1(Right, Left, Forward, Back);
168        let move_dir = vec3(dir.x, 0.0, dir.y).scale(5.0*delta_time);
169        pos += Mat3::from_rot(rx) * move_dir;
170
171        frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
172        // draw teapot
173        frame.draw(
174            teapot_mesh, teapot_indices,
175            program, &uniform! {
176                perspective: perspective,
177                model: Mat4::from_scale(Vec3::splat(0.1)),
178                camera: Mat4::from_inverse_transform(pos, Vec3::ONE, rot),
179                light:   vec3(0.1, 0.25, -1.0).normalise(),
180                albedo:  vec3(0.5, 0.1,   0.4),
181                ambient: vec3(0.0, 0.05,  0.1),
182                shine: 50.0f32,
183            },
184            &draw_parameters,
185        ).unwrap();
186
187        let mut frame = display.draw();
188        frame.draw(
189            screen_mesh, screen_indices, if fxaa_on { fxaa } else { normal },
190            &shaders::fxaa_uniforms(colour), &DrawParameters::default()
191        ).unwrap();
192        frame.finish().unwrap();
193    }).build(event_loop).unwrap();
194}
Source

pub fn from_transform(pos: Vec3, scale: Vec3, rot: Quat) -> Mat4

transform from position, scale and rotation. much quicker than multiplying position * rot * scale matrices while having the same result.

Source

pub fn from_inverse_transform(pos: Vec3, scale: Vec3, rot: Quat) -> Mat4

makes inverse of from_transform, useful for making camera transform.

Examples found in repository?
examples/simple-fxaa.rs (line 178)
13fn main() {
14    use Action::*;
15    let event_loop = EventLoop::new().unwrap();
16    event_loop.set_control_flow(ControlFlow::Poll);
17
18    let mut colour = ResizableTexture2d::default();
19    let mut depth = ResizableDepthTexture2d::default();
20
21    let input = { use base_input_codes::*; input_map!(
22        (Left,    ArrowLeft,  KeyA, LeftStickLeft ),
23        (Right,   ArrowRight, KeyD, LeftStickRight),
24        (Forward, ArrowUp,    KeyW, LeftStickUp   ),
25        (Back,    ArrowDown,  KeyS, LeftStickDown ),
26        (LookRight, MouseMoveRight, RightStickRight),
27        (LookLeft,  MouseMoveLeft,  RightStickLeft ),
28        (LookUp,    MouseMoveUp,    RightStickUp   ),
29        (LookDown,  MouseMoveDown,  RightStickDown ),
30        (FXAA,      KeyF,       GamepadInput::North)
31    ) };
32    struct Graphics {
33        screen_indices: IndexBuffer<u32>,
34        screen_vertices: VertexBuffer<Vertex>,
35        screen_uvs: VertexBuffer<TextureCoords>,
36
37        teapot_indices: IndexBuffer<u16>,
38        teapot_vertices: VertexBuffer<Vertex>,
39        teapot_uvs: VertexBuffer<TextureCoords>,
40        teapot_normals: VertexBuffer<Normal>,
41
42        fxaa: Program, normal: Program, program: Program
43    }
44    let graphics: Rc<RefCell<Option<Graphics>>> = Rc::default();
45    let graphics_setup = graphics.clone();
46
47    let draw_parameters = DrawParameters {
48        backface_culling: draw_parameters::BackfaceCullingMode::CullClockwise,
49        ..params::alias_3d()
50    };
51    let mut fxaa_on = true;
52    
53    let mut pos = vec3(0.0, 0.0, -30.0);
54    let mut rot = vec2(0.0, 0.0);
55    
56    let mut frame_start = Instant::now();
57
58    thin_engine::builder(input).with_setup(|display, window, _| {
59        window.set_title("FXAA Test");
60        let _ = window.set_cursor_grab(CursorGrabMode::Confined);
61        let _ = window.set_cursor_grab(CursorGrabMode::Locked);
62        window.set_cursor_visible(false);
63
64        let (screen_indices, screen_vertices, screen_uvs) = mesh!(
65            display, &screen::INDICES, &screen::VERTICES, &screen::UVS
66        ).unwrap();
67        let (teapot_indices, teapot_vertices, teapot_uvs, teapot_normals) = mesh!(
68            display, &teapot::INDICES, &teapot::VERTICES, &[] as &[TextureCoords; 0], &teapot::NORMALS
69        ).unwrap();
70
71        let program = Program::from_source(
72            display,
73            "#version 140
74            in vec3 position;
75            in vec3 normal;
76            
77            out vec3 v_normal;
78
79            uniform mat4 model;
80            uniform mat4 perspective;
81            uniform mat4 camera;
82
83            void main() {
84                mat3 norm_mat = transpose(inverse(mat3(camera * model)));
85                v_normal = normalize(norm_mat * normal);
86                gl_Position = perspective * camera * model * vec4(position, 1);
87            }",
88            "#version 140
89            out vec4 colour;
90            in vec3 v_normal;
91            uniform vec3 light;
92            uniform mat4 camera;
93            uniform vec3 ambient;
94            uniform vec3 albedo;
95            uniform float shine;
96            void main() {
97                vec3 camera_dir = inverse(mat3(camera)) * vec3(0, 0, -1);
98                vec3 half_dir = normalize(camera_dir + light);
99                float specular = pow(max(dot(half_dir, v_normal), 0.0), shine);
100                float light_level = max(dot(light, v_normal), 0.0);
101                colour = vec4(albedo * light_level + ambient + vec3(specular), 1.0);
102            }", None
103        ).unwrap();
104        let fxaa = shaders::fxaa_shader(display).unwrap();
105        let normal = Program::from_source(
106            display,
107            "#version 140
108            in vec2 texture_coords;
109            out vec2 uv;
110            in vec3 position;
111            void main() {
112                uv = texture_coords;
113                gl_Position = vec4(position, 1);
114            }", 
115            "#version 140
116            in vec2 uv;
117            uniform sampler2D tex;
118            out vec4 colour;
119            void main() {
120                colour = texture(tex, uv);
121            }", None
122        ).unwrap();
123        graphics_setup.replace(Some(Graphics {
124            screen_indices, screen_vertices, screen_uvs,
125            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
126            program, normal, fxaa
127        }));
128    }).with_update(|input, display, _, _, _| {
129        let graphics = graphics.borrow();
130        let Graphics {
131            screen_indices, screen_vertices, screen_uvs,
132            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
133            program, normal, fxaa
134        } = graphics.as_ref().unwrap();
135        let teapot_mesh = (teapot_vertices, teapot_normals, teapot_uvs);
136        let screen_mesh = (screen_vertices, screen_uvs);
137
138        let delta_time = frame_start.elapsed().as_secs_f32();
139        frame_start = Instant::now();
140
141        // using a small resolution to better show the effect of fxaa.
142        let size = (380, 216);
143        display.resize(size);
144        depth.resize_to_display(&display);
145        colour.resize_to_display(&display);
146
147        // press f or gamepad north to toggle FXAA
148        if input.pressed(FXAA) { fxaa_on = !fxaa_on }
149
150        let colour = colour.texture();
151        let depth = depth.texture();
152        let mut frame = SimpleFrameBuffer::with_depth_buffer(
153            display, colour, depth
154        ).unwrap();
155
156        let perspective = Mat4::perspective_3d(size, 1.0, 1024.0, 0.1);
157
158        // set camera rotation
159        let look_move = input.dir(LookRight, LookLeft, LookUp, LookDown);
160        rot += look_move.scale(delta_time * 15.0);
161        rot.y = rot.y.clamp(-PI / 2.0, PI / 2.0);
162        let rx = Quat::from_y_rot(rot.x);
163        let ry = Quat::from_x_rot(-rot.y);
164        let rot = rx * ry;
165
166        // move player based on camera
167        let dir = input.dir_max_len_1(Right, Left, Forward, Back);
168        let move_dir = vec3(dir.x, 0.0, dir.y).scale(5.0*delta_time);
169        pos += Mat3::from_rot(rx) * move_dir;
170
171        frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
172        // draw teapot
173        frame.draw(
174            teapot_mesh, teapot_indices,
175            program, &uniform! {
176                perspective: perspective,
177                model: Mat4::from_scale(Vec3::splat(0.1)),
178                camera: Mat4::from_inverse_transform(pos, Vec3::ONE, rot),
179                light:   vec3(0.1, 0.25, -1.0).normalise(),
180                albedo:  vec3(0.5, 0.1,   0.4),
181                ambient: vec3(0.0, 0.05,  0.1),
182                shine: 50.0f32,
183            },
184            &draw_parameters,
185        ).unwrap();
186
187        let mut frame = display.draw();
188        frame.draw(
189            screen_mesh, screen_indices, if fxaa_on { fxaa } else { normal },
190            &shaders::fxaa_uniforms(colour), &DrawParameters::default()
191        ).unwrap();
192        frame.finish().unwrap();
193    }).build(event_loop).unwrap();
194}
Source

pub fn from_pos_and_rot(pos: Vec3, rot: Quat) -> Mat4

Source

pub const fn from_pos_and_scale(pos: Vec3, scale: Vec3) -> Mat4

Source

pub fn from_scale_and_rot(scale: Vec3, rot: Quat) -> Mat4

Source

pub const fn from_pos(pos: Vec3) -> Mat4

Source

pub fn from_rot(rot: Quat) -> Mat4

Source

pub const fn transpose(self) -> Mat4

rotates the matrixs components

Source

pub fn perspective_3d( window_dimesnsions: (u32, u32), fov: f32, zfar: f32, znear: f32, ) -> Mat4

creates a 3d perspective matrix. known as perspective in the supplied vertex shader.

Examples found in repository?
examples/simple-fxaa.rs (line 156)
13fn main() {
14    use Action::*;
15    let event_loop = EventLoop::new().unwrap();
16    event_loop.set_control_flow(ControlFlow::Poll);
17
18    let mut colour = ResizableTexture2d::default();
19    let mut depth = ResizableDepthTexture2d::default();
20
21    let input = { use base_input_codes::*; input_map!(
22        (Left,    ArrowLeft,  KeyA, LeftStickLeft ),
23        (Right,   ArrowRight, KeyD, LeftStickRight),
24        (Forward, ArrowUp,    KeyW, LeftStickUp   ),
25        (Back,    ArrowDown,  KeyS, LeftStickDown ),
26        (LookRight, MouseMoveRight, RightStickRight),
27        (LookLeft,  MouseMoveLeft,  RightStickLeft ),
28        (LookUp,    MouseMoveUp,    RightStickUp   ),
29        (LookDown,  MouseMoveDown,  RightStickDown ),
30        (FXAA,      KeyF,       GamepadInput::North)
31    ) };
32    struct Graphics {
33        screen_indices: IndexBuffer<u32>,
34        screen_vertices: VertexBuffer<Vertex>,
35        screen_uvs: VertexBuffer<TextureCoords>,
36
37        teapot_indices: IndexBuffer<u16>,
38        teapot_vertices: VertexBuffer<Vertex>,
39        teapot_uvs: VertexBuffer<TextureCoords>,
40        teapot_normals: VertexBuffer<Normal>,
41
42        fxaa: Program, normal: Program, program: Program
43    }
44    let graphics: Rc<RefCell<Option<Graphics>>> = Rc::default();
45    let graphics_setup = graphics.clone();
46
47    let draw_parameters = DrawParameters {
48        backface_culling: draw_parameters::BackfaceCullingMode::CullClockwise,
49        ..params::alias_3d()
50    };
51    let mut fxaa_on = true;
52    
53    let mut pos = vec3(0.0, 0.0, -30.0);
54    let mut rot = vec2(0.0, 0.0);
55    
56    let mut frame_start = Instant::now();
57
58    thin_engine::builder(input).with_setup(|display, window, _| {
59        window.set_title("FXAA Test");
60        let _ = window.set_cursor_grab(CursorGrabMode::Confined);
61        let _ = window.set_cursor_grab(CursorGrabMode::Locked);
62        window.set_cursor_visible(false);
63
64        let (screen_indices, screen_vertices, screen_uvs) = mesh!(
65            display, &screen::INDICES, &screen::VERTICES, &screen::UVS
66        ).unwrap();
67        let (teapot_indices, teapot_vertices, teapot_uvs, teapot_normals) = mesh!(
68            display, &teapot::INDICES, &teapot::VERTICES, &[] as &[TextureCoords; 0], &teapot::NORMALS
69        ).unwrap();
70
71        let program = Program::from_source(
72            display,
73            "#version 140
74            in vec3 position;
75            in vec3 normal;
76            
77            out vec3 v_normal;
78
79            uniform mat4 model;
80            uniform mat4 perspective;
81            uniform mat4 camera;
82
83            void main() {
84                mat3 norm_mat = transpose(inverse(mat3(camera * model)));
85                v_normal = normalize(norm_mat * normal);
86                gl_Position = perspective * camera * model * vec4(position, 1);
87            }",
88            "#version 140
89            out vec4 colour;
90            in vec3 v_normal;
91            uniform vec3 light;
92            uniform mat4 camera;
93            uniform vec3 ambient;
94            uniform vec3 albedo;
95            uniform float shine;
96            void main() {
97                vec3 camera_dir = inverse(mat3(camera)) * vec3(0, 0, -1);
98                vec3 half_dir = normalize(camera_dir + light);
99                float specular = pow(max(dot(half_dir, v_normal), 0.0), shine);
100                float light_level = max(dot(light, v_normal), 0.0);
101                colour = vec4(albedo * light_level + ambient + vec3(specular), 1.0);
102            }", None
103        ).unwrap();
104        let fxaa = shaders::fxaa_shader(display).unwrap();
105        let normal = Program::from_source(
106            display,
107            "#version 140
108            in vec2 texture_coords;
109            out vec2 uv;
110            in vec3 position;
111            void main() {
112                uv = texture_coords;
113                gl_Position = vec4(position, 1);
114            }", 
115            "#version 140
116            in vec2 uv;
117            uniform sampler2D tex;
118            out vec4 colour;
119            void main() {
120                colour = texture(tex, uv);
121            }", None
122        ).unwrap();
123        graphics_setup.replace(Some(Graphics {
124            screen_indices, screen_vertices, screen_uvs,
125            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
126            program, normal, fxaa
127        }));
128    }).with_update(|input, display, _, _, _| {
129        let graphics = graphics.borrow();
130        let Graphics {
131            screen_indices, screen_vertices, screen_uvs,
132            teapot_indices, teapot_vertices, teapot_uvs, teapot_normals,
133            program, normal, fxaa
134        } = graphics.as_ref().unwrap();
135        let teapot_mesh = (teapot_vertices, teapot_normals, teapot_uvs);
136        let screen_mesh = (screen_vertices, screen_uvs);
137
138        let delta_time = frame_start.elapsed().as_secs_f32();
139        frame_start = Instant::now();
140
141        // using a small resolution to better show the effect of fxaa.
142        let size = (380, 216);
143        display.resize(size);
144        depth.resize_to_display(&display);
145        colour.resize_to_display(&display);
146
147        // press f or gamepad north to toggle FXAA
148        if input.pressed(FXAA) { fxaa_on = !fxaa_on }
149
150        let colour = colour.texture();
151        let depth = depth.texture();
152        let mut frame = SimpleFrameBuffer::with_depth_buffer(
153            display, colour, depth
154        ).unwrap();
155
156        let perspective = Mat4::perspective_3d(size, 1.0, 1024.0, 0.1);
157
158        // set camera rotation
159        let look_move = input.dir(LookRight, LookLeft, LookUp, LookDown);
160        rot += look_move.scale(delta_time * 15.0);
161        rot.y = rot.y.clamp(-PI / 2.0, PI / 2.0);
162        let rx = Quat::from_y_rot(rot.x);
163        let ry = Quat::from_x_rot(-rot.y);
164        let rot = rx * ry;
165
166        // move player based on camera
167        let dir = input.dir_max_len_1(Right, Left, Forward, Back);
168        let move_dir = vec3(dir.x, 0.0, dir.y).scale(5.0*delta_time);
169        pos += Mat3::from_rot(rx) * move_dir;
170
171        frame.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0);
172        // draw teapot
173        frame.draw(
174            teapot_mesh, teapot_indices,
175            program, &uniform! {
176                perspective: perspective,
177                model: Mat4::from_scale(Vec3::splat(0.1)),
178                camera: Mat4::from_inverse_transform(pos, Vec3::ONE, rot),
179                light:   vec3(0.1, 0.25, -1.0).normalise(),
180                albedo:  vec3(0.5, 0.1,   0.4),
181                ambient: vec3(0.0, 0.05,  0.1),
182                shine: 50.0f32,
183            },
184            &draw_parameters,
185        ).unwrap();
186
187        let mut frame = display.draw();
188        frame.draw(
189            screen_mesh, screen_indices, if fxaa_on { fxaa } else { normal },
190            &shaders::fxaa_uniforms(colour), &DrawParameters::default()
191        ).unwrap();
192        frame.finish().unwrap();
193    }).build(event_loop).unwrap();
194}
Source

pub fn perspective_2d(window_dimesnsions: (u32, u32)) -> Mat4

creates a 2d perspective matrix. known as perspective in the supplied vertex shader.

Source

pub const fn from_values( a: f32, b: f32, c: f32, d: f32, e: f32, f: f32, g: f32, h: f32, i: f32, j: f32, k: f32, l: f32, m: f32, n: f32, o: f32, p: f32, ) -> Mat4

creates a matrix with the following values.

use glium_types::matrices::Mat4;
let new_matrix = Mat4::from_values(
    1.0, 0.0, 0.0, 0.0,
    0.0, 1.0, 0.0, 0.0,
    0.0, 0.0, 1.0, 0.0,
    0.0, 0.0, 0.0, 1.0
);
assert!(new_matrix == Mat4::IDENTITY);
Source

pub const fn column(&self, pos: usize) -> [f32; 4]

Source

pub const fn row(&self, pos: usize) -> [f32; 4]

Source

pub fn position(&self) -> Vec3

Source

pub fn determinant(self) -> f32

Source

pub fn inverse(self) -> Mat4

get inverse of matrix. useful for camera.

Source

pub fn scale(self, scalar: f32) -> Mat4

Trait Implementations§

Source§

impl Add for Mat4

Source§

type Output = Mat4

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Mat4) -> <Mat4 as Add>::Output

Performs the + operation. Read more
Source§

impl AddAssign for Mat4

Source§

fn add_assign(&mut self, rhs: Mat4)

Performs the += operation. Read more
Source§

impl AsUniformValue for Mat4

Source§

fn as_uniform_value(&self) -> UniformValue<'_>

Builds a UniformValue.
Source§

impl Clone for Mat4

Source§

fn clone(&self) -> Mat4

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mat4

Source§

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

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

impl Default for Mat4

Source§

fn default() -> Mat4

Returns the “default value” for a type. Read more
Source§

impl Div<f32> for Mat4

Source§

type Output = Mat4

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> <Mat4 as Div<f32>>::Output

Performs the / operation. Read more
Source§

impl Div for Mat4

Source§

type Output = Mat4

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Mat4) -> <Mat4 as Div>::Output

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Mat4

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign for Mat4

Source§

fn div_assign(&mut self, rhs: Mat4)

Performs the /= operation. Read more
Source§

impl From<Mat2> for Mat4

Source§

fn from(value: Mat2) -> Mat4

Converts to this type from the input type.
Source§

impl From<Mat3> for Mat4

Source§

fn from(value: Mat3) -> Mat4

Converts to this type from the input type.
Source§

impl From<Mat4> for Mat2

Source§

fn from(value: Mat4) -> Mat2

Converts to this type from the input type.
Source§

impl From<Mat4> for Mat3

Source§

fn from(value: Mat4) -> Mat3

Converts to this type from the input type.
Source§

impl From<Quat> for Mat4

Source§

fn from(value: Quat) -> Mat4

Converts to this type from the input type.
Source§

impl Index<usize> for Mat4

Source§

type Output = [f32; 4]

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &<Mat4 as Index<usize>>::Output

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

impl IndexMut<usize> for Mat4

Source§

fn index_mut(&mut self, index: usize) -> &mut <Mat4 as Index<usize>>::Output

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

impl Mul<Vec4> for Mat4

Source§

type Output = Vec4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec4) -> <Mat4 as Mul<Vec4>>::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for Mat4

Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> <Mat4 as Mul<f32>>::Output

Performs the * operation. Read more
Source§

impl Mul for Mat4

Source§

type Output = Mat4

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Mat4) -> <Mat4 as Mul>::Output

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Mat4

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Mat4

Source§

fn mul_assign(&mut self, rhs: Mat4)

Performs the *= operation. Read more
Source§

impl PartialEq for Mat4

Source§

fn eq(&self, other: &Mat4) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Rem<f32> for Mat4

Source§

type Output = Mat4

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: f32) -> <Mat4 as Rem<f32>>::Output

Performs the % operation. Read more
Source§

impl RemAssign<f32> for Mat4

Source§

fn rem_assign(&mut self, rhs: f32)

Performs the %= operation. Read more
Source§

impl Sub for Mat4

Source§

type Output = Mat4

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Mat4) -> <Mat4 as Sub>::Output

Performs the - operation. Read more
Source§

impl SubAssign for Mat4

Source§

fn sub_assign(&mut self, rhs: Mat4)

Performs the -= operation. Read more
Source§

impl Copy for Mat4

Source§

impl StructuralPartialEq for Mat4

Auto Trait Implementations§

§

impl Freeze for Mat4

§

impl RefUnwindSafe for Mat4

§

impl Send for Mat4

§

impl Sync for Mat4

§

impl Unpin for Mat4

§

impl UnwindSafe for Mat4

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Content for T
where T: Copy,

Source§

type Owned = T

A type that holds a sized version of the content.
Source§

unsafe fn read<F, E>(size: usize, f: F) -> Result<T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

Prepares an output buffer, then turns this buffer into an Owned. User-provided closure F must only write to and not read from &mut Self.
Source§

fn get_elements_size() -> usize

Returns the size of each element.
Source§

fn to_void_ptr(&self) -> *const ()

Produces a pointer to the data.
Source§

fn ref_from_ptr<'a>(ptr: *mut (), size: usize) -> Option<*mut T>

Builds a pointer to this type from a raw pointer.
Source§

fn is_size_suitable(size: usize) -> bool

Returns true if the size is suitable to store a type like this.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

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

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> 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