#[repr(C)]pub struct Mat4 {
pub x_axis: Vec4,
pub y_axis: Vec4,
pub z_axis: Vec4,
pub w_axis: Vec4,
}Expand description
A 4x4 column major matrix.
If you are primarily dealing with 3D affine transformations
considering using Affine3A which is faster than a 4x4 matrix
for some affine operations.
Affine transformations including 3D translation, rotation and scale can be created
using methods such as Self::from_translation(), Self::from_quat(),
Self::from_scale() and Self::from_scale_rotation_translation().
The Self::transform_point3() and Self::transform_vector3() convenience methods
are provided for performing affine transformations on 3D vectors and points. These
multiply 3D inputs as 4D vectors with an implicit w value of 1 for points and 0
for vectors respectively. These methods assume that Self contains a valid affine
transform.
SIMD vector types are used for storage on supported platforms.
This type is 16 byte aligned.
Fields§
§x_axis: Vec4§y_axis: Vec4§z_axis: Vec4§w_axis: Vec4Implementations§
Source§impl Mat4
impl Mat4
Sourcepub const IDENTITY: Mat4
pub const IDENTITY: Mat4
A 4x4 identity matrix, where all diagonal elements are 1, and all off-diagonal elements are 0.
Sourcepub const fn from_cols(
x_axis: Vec4,
y_axis: Vec4,
z_axis: Vec4,
w_axis: Vec4,
) -> Mat4
pub const fn from_cols( x_axis: Vec4, y_axis: Vec4, z_axis: Vec4, w_axis: Vec4, ) -> Mat4
Creates a 4x4 matrix from four column vectors.
See also Self::from_rows when the data is in row major order.
Sourcepub const fn from_rows(row0: Vec4, row1: Vec4, row2: Vec4, row3: Vec4) -> Mat4
pub const fn from_rows(row0: Vec4, row1: Vec4, row2: Vec4, row3: Vec4) -> Mat4
Creates a 4x4 matrix from four row vectors.
Matrices are stored in column major order, so the given rows are permuted into
the matrix layout. Use Self::from_cols instead when the data is already in
column major order.
Sourcepub const fn from_cols_array(m: &[f32; 16]) -> Mat4
pub const fn from_cols_array(m: &[f32; 16]) -> Mat4
Creates a 4x4 matrix from a [f32; 16] array stored in column major order.
If the data is in row major order use Self::from_rows_array instead.
Sourcepub const fn to_cols_array(&self) -> [f32; 16]
pub const fn to_cols_array(&self) -> [f32; 16]
Creates a [f32; 16] array storing data in column major order.
If you require the data in row major order use Self::to_rows_array instead.
Sourcepub const fn from_cols_array_2d(m: &[[f32; 4]; 4]) -> Mat4
pub const fn from_cols_array_2d(m: &[[f32; 4]; 4]) -> Mat4
Creates a 4x4 matrix from a [[f32; 4]; 4] 4D array stored in column major order.
If the data is in row major order transpose the returned matrix.
Sourcepub const fn to_cols_array_2d(&self) -> [[f32; 4]; 4]
pub const fn to_cols_array_2d(&self) -> [[f32; 4]; 4]
Creates a [[f32; 4]; 4] 4D array storing data in column major order.
If you require row major order transpose the matrix first.
Sourcepub const fn from_rows_array(m: &[f32; 16]) -> Mat4
pub const fn from_rows_array(m: &[f32; 16]) -> Mat4
Creates a 4x4 matrix from a [f32; 16] array stored in row major order.
Matrices are stored in column major order, so the array is permuted into the
matrix layout. Use Self::from_cols_array instead when the data is already in
column major order.
Sourcepub const fn to_rows_array(&self) -> [f32; 16]
pub const fn to_rows_array(&self) -> [f32; 16]
Creates a [f32; 16] array storing data in row major order.
Matrices are stored in column major order, so the array is permuted out of the
column major storage. Use Self::to_cols_array instead when you want data in
column major order.
Sourcepub const fn from_diagonal(diagonal: Vec4) -> Mat4
pub const fn from_diagonal(diagonal: Vec4) -> Mat4
Creates a 4x4 matrix with its diagonal set to diagonal and all other entries set to 0.
Sourcepub fn from_scale_rotation_translation(
scale: Vec3,
rotation: Quat,
translation: Vec3,
) -> Mat4
pub fn from_scale_rotation_translation( scale: Vec3, rotation: Quat, translation: Vec3, ) -> Mat4
Creates an affine transformation matrix from the given 3D scale, rotation and
translation.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
§Panics
Will panic if rotation is not normalized when glam_assert is enabled.
Sourcepub fn from_rotation_translation(rotation: Quat, translation: Vec3) -> Mat4
pub fn from_rotation_translation(rotation: Quat, translation: Vec3) -> Mat4
Creates an affine transformation matrix from the given 3D translation.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
§Panics
Will panic if rotation is not normalized when glam_assert is enabled.
Sourcepub fn to_scale_rotation_translation(&self) -> (Vec3, Quat, Vec3)
pub fn to_scale_rotation_translation(&self) -> (Vec3, Quat, Vec3)
Extracts scale, rotation and translation from self. The input matrix is
expected to be a 3D affine transformation matrix otherwise the output will be invalid.
§Panics
Will panic if self is not a valid affine transformation matrix, if the determinant of the
3x3 linear part (the rotation and scale part of the transform) is zero, when glam_assert
is enabled.
Sourcepub fn from_quat(rotation: Quat) -> Mat4
pub fn from_quat(rotation: Quat) -> Mat4
Creates an affine transformation matrix from the given rotation quaternion.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
§Panics
Will panic if rotation is not normalized when glam_assert is enabled.
Sourcepub fn from_mat3(m: Mat3) -> Mat4
pub fn from_mat3(m: Mat3) -> Mat4
Creates an affine transformation matrix from the given 3x3 linear transformation matrix.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Sourcepub fn from_mat3_translation(mat3: Mat3, translation: Vec3) -> Mat4
pub fn from_mat3_translation(mat3: Mat3, translation: Vec3) -> Mat4
Creates an affine transformation matrics from a 3x3 matrix (expressing scale, shear and rotation) and a translation vector.
Equivalent to Mat4::from_translation(translation) * Mat4::from_mat3(mat3)
Sourcepub fn from_mat3a(m: Mat3A) -> Mat4
pub fn from_mat3a(m: Mat3A) -> Mat4
Creates an affine transformation matrix from the given 3x3 linear transformation matrix.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Examples found in repository?
341fn calculate_mirror_camera_transform_and_projection(
342 main_camera_transform: &Transform,
343 main_camera_projection: &PerspectiveProjection,
344 mirror_transform: &Transform,
345) -> (Transform, PerspectiveProjection) {
346 // Calculate the reflection matrix (a.k.a. Householder matrix) that will
347 // reflect the scene across the mirror plane.
348 //
349 // Note that you must calculate this in *matrix* form and only *afterward*
350 // convert to a `Transform` instead of composing `Transform`s. This is
351 // because the reflection matrix has non-uniform scale, and composing
352 // transforms can't always handle composition of matrices with non-uniform
353 // scales.
354 let mirror_camera_transform = Transform::from_matrix(
355 Mat4::from_mat3a(reflection_matrix(Vec3::NEG_Z)) * main_camera_transform.to_matrix(),
356 );
357
358 // Compute the distance from the camera to the mirror plane. This will be
359 // used to calculate the distance to the near clip plane for the mirror
360 // world.
361 let distance_from_camera_to_mirror = InfinitePlane3d::new(mirror_transform.rotation * Vec3::Y)
362 .signed_distance(
363 Isometry3d::IDENTITY,
364 mirror_transform.translation - main_camera_transform.translation,
365 );
366
367 // Compute the normal of the mirror plane in view space.
368 let view_from_world = main_camera_transform.compute_affine().matrix3.inverse();
369 let mirror_projection_plane_normal =
370 (view_from_world * (mirror_transform.rotation * Vec3::NEG_Y)).normalize();
371
372 // Compute the final projection. It should match the main camera projection,
373 // except that `near` and `near_normal` should be set to the updated near
374 // plane and near normal plane as above.
375 let mirror_camera_projection = PerspectiveProjection {
376 near_clip_plane: mirror_projection_plane_normal.extend(distance_from_camera_to_mirror),
377 ..*main_camera_projection
378 };
379
380 (mirror_camera_transform, mirror_camera_projection)
381}Sourcepub fn from_translation(translation: Vec3) -> Mat4
pub fn from_translation(translation: Vec3) -> Mat4
Creates an affine transformation matrix from the given 3D translation.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Examples found in repository?
92fn setup_meshes(
93 mut commands: Commands,
94 mut mesh_assets: ResMut<Assets<Mesh>>,
95 mut material_assets: ResMut<Assets<StandardMaterial>>,
96 mut inverse_bindposes_assets: ResMut<Assets<SkinnedMeshInverseBindposes>>,
97) {
98 // Create a mesh with two rectangles.
99 let unskinned_mesh = Mesh::new(
100 PrimitiveTopology::TriangleList,
101 RenderAssetUsages::default(),
102 )
103 .with_inserted_attribute(
104 Mesh::ATTRIBUTE_POSITION,
105 vec![
106 [-0.3, -0.3, 0.0],
107 [0.3, -0.3, 0.0],
108 [-0.3, 0.3, 0.0],
109 [0.3, 0.3, 0.0],
110 [-0.4, 0.8, 0.0],
111 [0.4, 0.8, 0.0],
112 [-0.4, 1.8, 0.0],
113 [0.4, 1.8, 0.0],
114 ],
115 )
116 .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vec![[0.0, 0.0, 1.0]; 8])
117 .with_inserted_indices(Indices::U16(vec![0, 1, 3, 0, 3, 2, 4, 5, 7, 4, 7, 6]));
118
119 // Copy the mesh and add skinning attributes that bind each rectangle to a joint.
120 let skinned_mesh = unskinned_mesh
121 .clone()
122 .with_inserted_attribute(
123 Mesh::ATTRIBUTE_JOINT_INDEX,
124 VertexAttributeValues::Uint16x4(vec![
125 [0, 0, 0, 0],
126 [0, 0, 0, 0],
127 [0, 0, 0, 0],
128 [0, 0, 0, 0],
129 [1, 0, 0, 0],
130 [1, 0, 0, 0],
131 [1, 0, 0, 0],
132 [1, 0, 0, 0],
133 ]),
134 )
135 .with_inserted_attribute(
136 Mesh::ATTRIBUTE_JOINT_WEIGHT,
137 vec![[1.00, 0.00, 0.0, 0.0]; 8],
138 );
139
140 let unskinned_mesh_handle = mesh_assets.add(unskinned_mesh);
141 let skinned_mesh_handle = mesh_assets.add(skinned_mesh);
142
143 let inverse_bindposes_handle = inverse_bindposes_assets.add(vec![
144 Mat4::IDENTITY,
145 Mat4::from_translation(Vec3::new(0.0, -1.3, 0.0)),
146 ]);
147
148 let mesh_material_handle = material_assets.add(StandardMaterial::default());
149
150 let background_material_handle = material_assets.add(StandardMaterial {
151 base_color: Color::srgb(0.05, 0.15, 0.05),
152 reflectance: 0.2,
153 ..default()
154 });
155
156 #[derive(PartialEq)]
157 enum Variation {
158 Normal,
159 MissingMeshAttributes,
160 MissingJointEntity,
161 MissingSkinnedMeshComponent,
162 }
163
164 for (index, variation) in [
165 Variation::Normal,
166 Variation::MissingMeshAttributes,
167 Variation::MissingJointEntity,
168 Variation::MissingSkinnedMeshComponent,
169 ]
170 .into_iter()
171 .enumerate()
172 {
173 // Skip variations that are currently broken. See https://github.com/bevyengine/bevy/issues/16929,
174 // https://github.com/bevyengine/bevy/pull/18074.
175 if (variation == Variation::MissingSkinnedMeshComponent)
176 || (variation == Variation::MissingMeshAttributes)
177 {
178 continue;
179 }
180
181 let transform = Transform::from_xyz(((index as f32) - 1.5) * 4.5, 0.0, 0.0);
182
183 let joint_0 = commands.spawn(transform).id();
184
185 let joint_1 = commands
186 .spawn((ChildOf(joint_0), AnimatedJoint, Transform::IDENTITY))
187 .id();
188
189 if variation == Variation::MissingJointEntity {
190 commands.entity(joint_1).despawn();
191 }
192
193 let mesh_handle = match variation {
194 Variation::MissingMeshAttributes => &unskinned_mesh_handle,
195 _ => &skinned_mesh_handle,
196 };
197
198 let mut entity_commands = commands.spawn((
199 Mesh3d(mesh_handle.clone()),
200 MeshMaterial3d(mesh_material_handle.clone()),
201 transform,
202 ));
203
204 if variation != Variation::MissingSkinnedMeshComponent {
205 entity_commands.insert(SkinnedMesh {
206 inverse_bindposes: inverse_bindposes_handle.clone(),
207 joints: vec![joint_0, joint_1],
208 });
209 }
210
211 // Add a square behind the mesh to distinguish it from the other meshes.
212 commands.spawn((
213 Transform::from_xyz(transform.translation.x, transform.translation.y, -0.8),
214 Mesh3d(mesh_assets.add(Plane3d::default().mesh().size(4.3, 4.3).normal(Dir3::Z))),
215 MeshMaterial3d(background_material_handle.clone()),
216 ));
217 }
218}More examples
124fn spawn_custom_meshes(
125 mut commands: Commands,
126 mut mesh_assets: ResMut<Assets<Mesh>>,
127 mut material_assets: ResMut<Assets<StandardMaterial>>,
128 mut inverse_bindposes_assets: ResMut<Assets<SkinnedMeshInverseBindposes>>,
129) {
130 let mesh_handle = mesh_assets.add(
131 Mesh::new(
132 PrimitiveTopology::TriangleStrip,
133 // Test that skinned mesh bounds work even if the mesh is render
134 // world only.
135 RenderAssetUsages::RENDER_WORLD,
136 )
137 .with_inserted_attribute(
138 Mesh::ATTRIBUTE_POSITION,
139 vec![
140 [-0.5, 0.0, 0.0],
141 [0.5, 0.0, 0.0],
142 [-0.5, 0.5, 0.0],
143 [0.5, 0.5, 0.0],
144 [-0.5, 1.0, 0.0],
145 [0.5, 1.0, 0.0],
146 [-0.5, 1.5, 0.0],
147 [0.5, 1.5, 0.0],
148 [-0.5, 2.0, 0.0],
149 [0.5, 2.0, 0.0],
150 ],
151 )
152 .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vec![[0.0, 0.0, 1.0]; 10])
153 .with_inserted_attribute(
154 Mesh::ATTRIBUTE_JOINT_INDEX,
155 VertexAttributeValues::Uint16x4(vec![
156 [1, 0, 0, 0],
157 [1, 0, 0, 0],
158 [1, 2, 0, 0],
159 [1, 2, 0, 0],
160 [1, 2, 0, 0],
161 [1, 2, 0, 0],
162 [2, 1, 0, 0],
163 [2, 1, 0, 0],
164 [2, 0, 0, 0],
165 [2, 0, 0, 0],
166 ]),
167 )
168 .with_inserted_attribute(
169 Mesh::ATTRIBUTE_JOINT_WEIGHT,
170 vec![
171 [1.00, 0.00, 0.0, 0.0],
172 [1.00, 0.00, 0.0, 0.0],
173 [0.75, 0.25, 0.0, 0.0],
174 [0.75, 0.25, 0.0, 0.0],
175 [0.50, 0.50, 0.0, 0.0],
176 [0.50, 0.50, 0.0, 0.0],
177 [0.75, 0.25, 0.0, 0.0],
178 [0.75, 0.25, 0.0, 0.0],
179 [1.00, 0.00, 0.0, 0.0],
180 [1.00, 0.00, 0.0, 0.0],
181 ],
182 )
183 .with_generated_skinned_mesh_bounds()
184 .unwrap(),
185 );
186
187 let inverse_bindposes_handle = inverse_bindposes_assets.add(vec![
188 Mat4::from_translation(Vec3::new(0.0, 0.0, 0.0)),
189 Mat4::from_translation(Vec3::new(0.0, 0.0, 0.0)),
190 Mat4::from_translation(Vec3::new(0.0, -1.0, 0.0)),
191 ]);
192
193 struct MeshInstance {
194 animations: [CustomAnimationId; 2],
195 }
196
197 let mesh_instances = [
198 // Simple cases. First joint is still, second joint is all rotation/translation/scale variations.
199 MeshInstance { animations: [0, 1] },
200 MeshInstance { animations: [0, 2] },
201 MeshInstance { animations: [0, 3] },
202 MeshInstance { animations: [0, 4] },
203 MeshInstance { animations: [0, 5] },
204 MeshInstance { animations: [0, 6] },
205 MeshInstance { animations: [0, 7] },
206 MeshInstance { animations: [0, 8] },
207 // Skewed cases. First joint is non-uniform scaling, second joint is rotation/translation variations.
208 MeshInstance { animations: [9, 1] },
209 MeshInstance { animations: [9, 2] },
210 MeshInstance { animations: [9, 3] },
211 MeshInstance { animations: [9, 4] },
212 MeshInstance { animations: [9, 5] },
213 ];
214
215 for (i, mesh_instance) in mesh_instances.iter().enumerate() {
216 let x = ((i as f32) * 2.0) - ((mesh_instances.len() - 1) as f32);
217
218 let base_entity = commands
219 .spawn((Transform::from_xyz(x, 0.0, 0.0), Visibility::default()))
220 .id();
221
222 let joints = vec![
223 commands.spawn((Transform::IDENTITY,)).id(),
224 commands
225 .spawn((
226 CustomAnimation(mesh_instance.animations[0]),
227 Transform::IDENTITY,
228 ))
229 .id(),
230 commands
231 .spawn((
232 CustomAnimation(mesh_instance.animations[1]),
233 Transform::IDENTITY,
234 ))
235 .id(),
236 ];
237
238 commands.entity(joints[0]).insert(ChildOf(base_entity));
239
240 commands.entity(joints[1]).insert(ChildOf(joints[0]));
241 commands.entity(joints[2]).insert(ChildOf(joints[1]));
242
243 let mesh_entity = commands
244 .spawn((
245 Transform::IDENTITY,
246 Mesh3d(mesh_handle.clone()),
247 MeshMaterial3d(material_assets.add(StandardMaterial {
248 base_color: Color::WHITE,
249 cull_mode: None,
250 ..default()
251 })),
252 SkinnedMesh {
253 inverse_bindposes: inverse_bindposes_handle.clone(),
254 joints: joints.clone(),
255 },
256 DynamicSkinnedMeshBounds,
257 ))
258 .id();
259
260 commands.entity(mesh_entity).insert(ChildOf(base_entity));
261 }
262}38fn setup(
39 mut commands: Commands,
40 asset_server: Res<AssetServer>,
41 mut meshes: ResMut<Assets<Mesh>>,
42 mut materials: ResMut<Assets<StandardMaterial>>,
43 mut skinned_mesh_inverse_bindposes_assets: ResMut<Assets<SkinnedMeshInverseBindposes>>,
44) {
45 // Create a camera
46 commands.spawn((
47 Camera3d::default(),
48 Transform::from_xyz(2.5, 2.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
49 ));
50
51 // Create inverse bindpose matrices for a skeleton consists of 2 joints
52 let inverse_bindposes = skinned_mesh_inverse_bindposes_assets.add(vec![
53 Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)),
54 Mat4::from_translation(Vec3::new(-0.5, -1.0, 0.0)),
55 ]);
56
57 // Create a mesh
58 let mesh = Mesh::new(
59 PrimitiveTopology::TriangleList,
60 RenderAssetUsages::RENDER_WORLD,
61 )
62 // Set mesh vertex positions
63 .with_inserted_attribute(
64 Mesh::ATTRIBUTE_POSITION,
65 vec![
66 [0.0, 0.0, 0.0],
67 [1.0, 0.0, 0.0],
68 [0.0, 0.5, 0.0],
69 [1.0, 0.5, 0.0],
70 [0.0, 1.0, 0.0],
71 [1.0, 1.0, 0.0],
72 [0.0, 1.5, 0.0],
73 [1.0, 1.5, 0.0],
74 [0.0, 2.0, 0.0],
75 [1.0, 2.0, 0.0],
76 ],
77 )
78 // Add UV coordinates that map the left half of the texture since its a 1 x
79 // 2 rectangle.
80 .with_inserted_attribute(
81 Mesh::ATTRIBUTE_UV_0,
82 vec![
83 [0.0, 0.00],
84 [0.5, 0.00],
85 [0.0, 0.25],
86 [0.5, 0.25],
87 [0.0, 0.50],
88 [0.5, 0.50],
89 [0.0, 0.75],
90 [0.5, 0.75],
91 [0.0, 1.00],
92 [0.5, 1.00],
93 ],
94 )
95 // Set mesh vertex normals
96 .with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, vec![[0.0, 0.0, 1.0]; 10])
97 // Set mesh vertex joint indices for mesh skinning.
98 // Each vertex gets 4 indices used to address the `JointTransforms` array in the vertex shader
99 // as well as `SkinnedMeshJoint` array in the `SkinnedMesh` component.
100 // This means that a maximum of 4 joints can affect a single vertex.
101 .with_inserted_attribute(
102 Mesh::ATTRIBUTE_JOINT_INDEX,
103 // Need to be explicit here as [u16; 4] could be either Uint16x4 or Unorm16x4.
104 VertexAttributeValues::Uint16x4(vec![
105 [0, 0, 0, 0],
106 [0, 0, 0, 0],
107 [0, 1, 0, 0],
108 [0, 1, 0, 0],
109 [0, 1, 0, 0],
110 [0, 1, 0, 0],
111 [0, 1, 0, 0],
112 [0, 1, 0, 0],
113 [0, 1, 0, 0],
114 [0, 1, 0, 0],
115 ]),
116 )
117 // Set mesh vertex joint weights for mesh skinning.
118 // Each vertex gets 4 joint weights corresponding to the 4 joint indices assigned to it.
119 // The sum of these weights should equal to 1.
120 .with_inserted_attribute(
121 Mesh::ATTRIBUTE_JOINT_WEIGHT,
122 vec![
123 [1.00, 0.00, 0.0, 0.0],
124 [1.00, 0.00, 0.0, 0.0],
125 [0.75, 0.25, 0.0, 0.0],
126 [0.75, 0.25, 0.0, 0.0],
127 [0.50, 0.50, 0.0, 0.0],
128 [0.50, 0.50, 0.0, 0.0],
129 [0.25, 0.75, 0.0, 0.0],
130 [0.25, 0.75, 0.0, 0.0],
131 [0.00, 1.00, 0.0, 0.0],
132 [0.00, 1.00, 0.0, 0.0],
133 ],
134 )
135 // Tell bevy to construct triangles from a list of vertex indices,
136 // where each 3 vertex indices form a triangle.
137 .with_inserted_indices(Indices::U16(vec![
138 0, 1, 3, 0, 3, 2, 2, 3, 5, 2, 5, 4, 4, 5, 7, 4, 7, 6, 6, 7, 9, 6, 9, 8,
139 ]))
140 // Create skinned mesh bounds. Together with the `DynamicSkinnedMeshBounds`
141 // component, this will ensure the mesh is correctly frustum culled.
142 .with_generated_skinned_mesh_bounds()
143 .unwrap();
144
145 let mesh = meshes.add(mesh);
146
147 // We're seeding the PRNG here to make this example deterministic for testing purposes.
148 // This isn't strictly required in practical use unless you need your app to be deterministic.
149 let mut rng = ChaCha8Rng::seed_from_u64(42);
150
151 for i in -5..5 {
152 // Create joint entities
153 let joint_0 = commands
154 .spawn(Transform::from_xyz(
155 i as f32 * 1.5,
156 0.0,
157 // Move quads back a small amount to avoid Z-fighting and not
158 // obscure the transform gizmos.
159 -(i as f32 * 0.01).abs(),
160 ))
161 .id();
162 let joint_1 = commands.spawn((AnimatedJoint(i), Transform::IDENTITY)).id();
163
164 // Set joint_1 as a child of joint_0.
165 commands.entity(joint_0).add_children(&[joint_1]);
166
167 // Each joint in this vector corresponds to each inverse bindpose matrix in `SkinnedMeshInverseBindposes`.
168 let joint_entities = vec![joint_0, joint_1];
169
170 // Create skinned mesh renderer. Note that its transform doesn't affect the position of the mesh.
171 commands.spawn((
172 Mesh3d(mesh.clone()),
173 MeshMaterial3d(materials.add(StandardMaterial {
174 base_color: Color::srgb(
175 rng.random_range(0.0..1.0),
176 rng.random_range(0.0..1.0),
177 rng.random_range(0.0..1.0),
178 ),
179 base_color_texture: Some(asset_server.load("textures/uv_checker_bw.png")),
180 ..default()
181 })),
182 SkinnedMesh {
183 inverse_bindposes: inverse_bindposes.clone(),
184 joints: joint_entities,
185 },
186 DynamicSkinnedMeshBounds,
187 ));
188 }
189}Sourcepub fn from_axis_angle(axis: Vec3, angle: f32) -> Mat4
pub fn from_axis_angle(axis: Vec3, angle: f32) -> Mat4
Creates an affine transformation matrix containing a 3D rotation around a normalized
rotation axis of angle (in radians).
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
§Panics
Will panic if axis is not normalized when glam_assert is enabled.
Sourcepub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Mat4
pub fn from_euler(order: EulerRot, a: f32, b: f32, c: f32) -> Mat4
Creates a affine transformation matrix containing a rotation from the given euler rotation sequence and angles (in radians).
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Sourcepub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32)
pub fn to_euler(&self, order: EulerRot) -> (f32, f32, f32)
Extract Euler angles with the given Euler rotation order.
Note if the upper 3x3 matrix contain scales, shears, or other non-rotation transformations then the resulting Euler angles will be ill-defined.
§Panics
Will panic if any column of the upper 3x3 rotation matrix is not normalized when
glam_assert is enabled.
Sourcepub fn from_rotation_x(angle: f32) -> Mat4
pub fn from_rotation_x(angle: f32) -> Mat4
Creates an affine transformation matrix containing a 3D rotation around the x axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Sourcepub fn from_rotation_y(angle: f32) -> Mat4
pub fn from_rotation_y(angle: f32) -> Mat4
Creates an affine transformation matrix containing a 3D rotation around the y axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Sourcepub fn from_rotation_z(angle: f32) -> Mat4
pub fn from_rotation_z(angle: f32) -> Mat4
Creates an affine transformation matrix containing a 3D rotation around the z axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
Sourcepub fn from_scale(scale: Vec3) -> Mat4
pub fn from_scale(scale: Vec3) -> Mat4
Creates an affine transformation matrix containing the given 3D non-uniform scale.
The resulting matrix can be used to transform 3D points and vectors. See
Self::transform_point3() and Self::transform_vector3().
§Panics
Will panic if all elements of scale are zero when glam_assert is enabled.
Sourcepub const fn from_cols_slice(slice: &[f32]) -> Mat4
pub const fn from_cols_slice(slice: &[f32]) -> Mat4
Creates a 4x4 matrix from the first 16 values in slice.
See also Self::from_rows_slice when the slice is in row major order.
§Panics
Panics if slice is less than 16 elements long.
Sourcepub fn write_cols_to_slice(&self, slice: &mut [f32])
pub fn write_cols_to_slice(&self, slice: &mut [f32])
Writes the columns of self to the first 16 elements in slice.
§Panics
Panics if slice is less than 16 elements long.
Sourcepub const fn from_rows_slice(slice: &[f32]) -> Mat4
pub const fn from_rows_slice(slice: &[f32]) -> Mat4
Creates a 4x4 matrix from the first 16 values in slice, stored in row
major order.
Matrices are stored in column major order, so the slice is permuted into the
matrix layout. Use Self::from_cols_slice instead when the slice is already in
column major order.
§Panics
Panics if slice is less than 16 elements long.
Sourcepub fn col_mut(&mut self, index: usize) -> &mut Vec4
pub fn col_mut(&mut self, index: usize) -> &mut Vec4
Returns a mutable reference to the matrix column for the given index.
§Panics
Panics if index is greater than 3.
Examples found in repository?
23 fn get_clip_from_view(&self) -> Mat4 {
24 let mut mat = self.perspective.get_clip_from_view();
25 mat.col_mut(2)[0] = self.horizontal_obliqueness;
26 mat.col_mut(2)[1] = self.vertical_obliqueness;
27 mat
28 }
29
30 fn get_clip_from_view_for_sub(&self, sub_view: &bevy::camera::SubCameraView) -> Mat4 {
31 let mut mat = self.perspective.get_clip_from_view_for_sub(sub_view);
32 mat.col_mut(2)[0] = self.horizontal_obliqueness;
33 mat.col_mut(2)[1] = self.vertical_obliqueness;
34 mat
35 }Sourcepub fn row(&self, index: usize) -> Vec4
pub fn row(&self, index: usize) -> Vec4
Returns the matrix row for the given index.
See also Self::set_row when you need to change the row.
§Panics
Panics if index is greater than 3.
Sourcepub fn set_row(&mut self, index: usize, row: Vec4)
pub fn set_row(&mut self, index: usize, row: Vec4)
Sets the matrix row for the given index.
Matrices are stored in column major order, so the row is spread across all
4 columns and writing it touches every column. Use Self::col_mut
instead when you can work with columns. See also Self::row.
§Panics
Panics if index is greater than 3.
Sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Returns true if, and only if, all elements are finite.
If any element is either NaN, positive or negative infinity, this will return false.
Sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Returns the determinant of self.
Sourcepub fn inverse(&self) -> Mat4
pub fn inverse(&self) -> Mat4
Returns the inverse of self.
If the matrix is not invertible the returned matrix will be invalid. The
returned matrix will also be invalid if the inverse is not finite, which can
happen when self contains very large or very small values. Use
Self::try_inverse or Self::inverse_or_zero to detect these cases.
§Panics
Will panic if the resulting inverted matrix is not finite when glam_assert
is enabled.
Examples found in repository?
528fn create_cubes(
529 image_assets: Res<Assets<Image>>,
530 mut commands: Commands,
531 irradiance_volumes: Query<(&IrradianceVolume, &GlobalTransform)>,
532 voxel_cube_parents: Query<Entity, With<VoxelCubeParent>>,
533 voxel_cubes: Query<Entity, With<VoxelCube>>,
534 example_assets: Res<ExampleAssets>,
535 mut voxel_visualization_material_assets: ResMut<Assets<VoxelVisualizationMaterial>>,
536) {
537 // If voxel cubes have already been spawned, don't do anything.
538 if !voxel_cubes.is_empty() {
539 return;
540 }
541
542 let Some(voxel_cube_parent) = voxel_cube_parents.iter().next() else {
543 return;
544 };
545
546 for (irradiance_volume, global_transform) in irradiance_volumes.iter() {
547 let Some(image) = image_assets.get(&irradiance_volume.voxels) else {
548 continue;
549 };
550
551 let resolution = image.texture_descriptor.size;
552
553 let voxel_cube_material = voxel_visualization_material_assets.add(ExtendedMaterial {
554 base: StandardMaterial::from(Color::from(RED)),
555 extension: VoxelVisualizationExtension {
556 irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo {
557 world_from_voxel: VOXEL_FROM_WORLD.inverse(),
558 voxel_from_world: VOXEL_FROM_WORLD,
559 resolution: uvec3(
560 resolution.width,
561 resolution.height,
562 resolution.depth_or_array_layers,
563 ),
564 intensity: IRRADIANCE_VOLUME_INTENSITY,
565 },
566 },
567 });
568
569 let scale = vec3(
570 1.0 / resolution.width as f32,
571 1.0 / resolution.height as f32,
572 1.0 / resolution.depth_or_array_layers as f32,
573 );
574
575 // Spawn a cube for each voxel.
576 for z in 0..resolution.depth_or_array_layers {
577 for y in 0..resolution.height {
578 for x in 0..resolution.width {
579 let uvw = (uvec3(x, y, z).as_vec3() + 0.5) * scale - 0.5;
580 let pos = global_transform.transform_point(uvw);
581 let voxel_cube = commands
582 .spawn((
583 Mesh3d(example_assets.voxel_cube.clone()),
584 MeshMaterial3d(voxel_cube_material.clone()),
585 Transform::from_scale(Vec3::splat(VOXEL_CUBE_SCALE))
586 .with_translation(pos),
587 ))
588 .insert(VoxelCube)
589 .insert(NotShadowCaster)
590 .id();
591
592 commands.entity(voxel_cube_parent).add_child(voxel_cube);
593 }
594 }
595 }
596 }
597}Sourcepub fn try_inverse(&self) -> Option<Mat4>
pub fn try_inverse(&self) -> Option<Mat4>
Returns the inverse of self or None if the matrix is not invertible, or if
the inverse is not finite.
Sourcepub fn inverse_or_zero(&self) -> Mat4
pub fn inverse_or_zero(&self) -> Mat4
Returns the inverse of self or Mat4::ZERO if the matrix is not
invertible, or if the inverse is not finite.
Sourcepub fn look_to_lh(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::view::look_to_mat4 function instead
pub fn look_to_lh(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4
use the glam::camera::lh::view::look_to_mat4 function instead
Creates a left-handed view matrix using a camera position, a facing direction and an up direction
For a view coordinate system with +X=right, +Y=up and +Z=forward.
§Panics
Will panic if dir or up are not normalized, or if dir and up are parallel,
when glam_assert is enabled.
Sourcepub fn look_to_rh(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::view::look_to_mat4 function instead
pub fn look_to_rh(eye: Vec3, dir: Vec3, up: Vec3) -> Mat4
use the glam::camera::rh::view::look_to_mat4 function instead
Creates a right-handed view matrix using a camera position, a facing direction, and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=back.
§Panics
Will panic if dir or up are not normalized, or if dir and up are parallel,
when glam_assert is enabled.
Sourcepub fn look_at_lh(eye: Vec3, center: Vec3, up: Vec3) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::view::look_at_mat4 function instead
pub fn look_at_lh(eye: Vec3, center: Vec3, up: Vec3) -> Mat4
use the glam::camera::lh::view::look_at_mat4 function instead
Creates a left-handed view matrix using a camera position, a focal points and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=forward.
§Panics
Will panic if up is not normalized, if center is equal to eye, or if the view
direction is parallel to up, when glam_assert is enabled.
Sourcepub fn look_at_rh(eye: Vec3, center: Vec3, up: Vec3) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::view::look_at_mat4 function instead
pub fn look_at_rh(eye: Vec3, center: Vec3, up: Vec3) -> Mat4
use the glam::camera::rh::view::look_at_mat4 function instead
Creates a right-handed view matrix using a camera position, a focal point, and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=back.
§Panics
Will panic if up is not normalized, if center is equal to eye, or if the view
direction is parallel to up, when glam_assert is enabled.
Sourcepub fn frustum_rh_gl(
left: f32,
right: f32,
bottom: f32,
top: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::opengl::frustum function instead
pub fn frustum_rh_gl( left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::rh::proj::opengl::frustum function instead
Creates a right-handed perspective projection matrix with [-1,1] depth range.
This is the same as the OpenGL glFrustum function.
See https://registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml
Sourcepub fn frustum_lh(
left: f32,
right: f32,
bottom: f32,
top: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::proj::directx::frustum function instead
pub fn frustum_lh( left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::lh::proj::directx::frustum function instead
Creates a left-handed perspective projection matrix with [0,1] depth range.
§Panics
Will panic if left equals right, bottom equals top, z_near equals z_far,
or z_near or z_far are not positive when glam_assert is enabled.
Sourcepub fn frustum_rh(
left: f32,
right: f32,
bottom: f32,
top: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::directx::frustum function instead
pub fn frustum_rh( left: f32, right: f32, bottom: f32, top: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::rh::proj::directx::frustum function instead
Creates a right-handed perspective projection matrix with [0,1] depth range.
§Panics
Will panic if left equals right, bottom equals top, z_near equals z_far,
or z_near or z_far are not positive when glam_assert is enabled.
Sourcepub fn perspective_rh_gl(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::opengl::perspective function instead
pub fn perspective_rh_gl( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::rh::proj::opengl::perspective function instead
Creates a right-handed perspective projection matrix with [-1,1] depth range.
Useful to map the standard right-handed coordinate system into what OpenGL expects.
This is the same as the OpenGL gluPerspective function.
See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml
Sourcepub fn perspective_lh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::proj::directx::perspective function instead
pub fn perspective_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::lh::proj::directx::perspective function instead
Creates a left-handed perspective projection matrix with [0,1] depth range.
Useful to map the standard left-handed coordinate system into what WebGPU/Metal/Direct3D expect.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near or z_far are less than or equal to zero, or if z_near is
equal to z_far, when glam_assert is enabled.
Sourcepub fn perspective_rh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::directx::perspective function instead
pub fn perspective_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32, ) -> Mat4
use the glam::camera::rh::proj::directx::perspective function instead
Creates a right-handed perspective projection matrix with [0,1] depth range.
Useful to map the standard right-handed coordinate system into what WebGPU/Metal/Direct3D expect.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near or z_far are less than or equal to zero, or if z_near is
equal to z_far, when glam_assert is enabled.
Sourcepub fn perspective_infinite_lh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::proj::directx::perspective_infinite function instead
pub fn perspective_infinite_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, ) -> Mat4
use the glam::camera::lh::proj::directx::perspective_infinite function instead
Creates an infinite left-handed perspective projection matrix with [0,1] depth range.
Like perspective_lh, but with an infinite value for z_far.
The result is that points near z_near are mapped to depth 0, and as they move towards infinity the depth approaches 1.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near is less than or equal to zero when glam_assert is enabled.
Sourcepub fn perspective_infinite_reverse_lh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::proj::directx::perspective_infinite_reverse function instead
pub fn perspective_infinite_reverse_lh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, ) -> Mat4
use the glam::camera::lh::proj::directx::perspective_infinite_reverse function instead
Creates an infinite reverse left-handed perspective projection matrix with [0,1] depth range.
Similar to perspective_infinite_lh, but maps Z = z_near to a depth of 1 and Z = infinity to a depth of 0.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near is less than or equal to zero when glam_assert is enabled.
Sourcepub fn perspective_infinite_rh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::directx::perspective_infinite function instead
pub fn perspective_infinite_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, ) -> Mat4
use the glam::camera::rh::proj::directx::perspective_infinite function instead
Creates an infinite right-handed perspective projection matrix with [0,1] depth range.
Like perspective_rh, but with an infinite value for z_far.
The result is that points near z_near are mapped to depth 0, and as they move towards infinity the depth approaches 1.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near is less than or equal to zero when glam_assert is enabled.
Sourcepub fn perspective_infinite_reverse_rh(
fov_y_radians: f32,
aspect_ratio: f32,
z_near: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::directx::perspective_infinite_reverse function instead
pub fn perspective_infinite_reverse_rh( fov_y_radians: f32, aspect_ratio: f32, z_near: f32, ) -> Mat4
use the glam::camera::rh::proj::directx::perspective_infinite_reverse function instead
Creates an infinite reverse right-handed perspective projection matrix with [0,1] depth range.
Similar to perspective_infinite_rh, but maps Z = z_near to a depth of 1 and Z = infinity to a depth of 0.
§Panics
Will panic if fov_y_radians is not in the range (0, π), if aspect_ratio is
zero, or if z_near is less than or equal to zero when glam_assert is enabled.
Sourcepub fn orthographic_rh_gl(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::opengl::orthographic function instead
pub fn orthographic_rh_gl( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32, ) -> Mat4
use the glam::camera::rh::proj::opengl::orthographic function instead
Creates a right-handed orthographic projection matrix with [-1,1] depth
range. This is the same as the OpenGL glOrtho function in OpenGL.
See
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glOrtho.xml
Useful to map a right-handed coordinate system to the normalized device coordinates that OpenGL expects.
Sourcepub fn orthographic_lh(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::lh::proj::directx::orthographic function instead
pub fn orthographic_lh( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32, ) -> Mat4
use the glam::camera::lh::proj::directx::orthographic function instead
Creates a left-handed orthographic projection matrix with [0,1] depth range.
Useful to map a left-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
Sourcepub fn orthographic_rh(
left: f32,
right: f32,
bottom: f32,
top: f32,
near: f32,
far: f32,
) -> Mat4
👎Deprecated since 0.33.1: use the glam::camera::rh::proj::directx::orthographic function instead
pub fn orthographic_rh( left: f32, right: f32, bottom: f32, top: f32, near: f32, far: f32, ) -> Mat4
use the glam::camera::rh::proj::directx::orthographic function instead
Creates a right-handed orthographic projection matrix with [0,1] depth range.
Useful to map a right-handed coordinate system to the normalized device coordinates that WebGPU/Direct3D/Metal expect.
Sourcepub fn project_point3(&self, rhs: Vec3) -> Vec3
pub fn project_point3(&self, rhs: Vec3) -> Vec3
Transforms the given 3D vector as a point, applying perspective correction.
This is the equivalent of multiplying the 3D vector as a 4D vector where w is 1.0.
The perspective divide is performed meaning the resulting 3D vector is divided by w.
This method assumes that self contains a projective transform.
Sourcepub fn transform_point3(&self, rhs: Vec3) -> Vec3
pub fn transform_point3(&self, rhs: Vec3) -> Vec3
Transforms the given 3D vector as a point.
This is the equivalent of multiplying the 3D vector as a 4D vector where w is
1.0.
This method assumes that self contains a valid affine transform. It does not perform
a perspective divide, if self contains a perspective transform, or if you are unsure,
the Self::project_point3() method should be used instead.
§Panics
Will panic if the 3rd row of self is not (0, 0, 0, 1) when glam_assert is enabled.
Sourcepub fn transform_vector3(&self, rhs: Vec3) -> Vec3
pub fn transform_vector3(&self, rhs: Vec3) -> Vec3
Transforms the given 3D vector as a direction.
This is the equivalent of multiplying the 3D vector as a 4D vector where w is
0.0.
This method assumes that self contains a valid affine transform.
§Panics
Will panic if the 3rd row of self is not (0, 0, 0, 1) when glam_assert is enabled.
Sourcepub fn project_point3a(&self, rhs: Vec3A) -> Vec3A
pub fn project_point3a(&self, rhs: Vec3A) -> Vec3A
Transforms the given Vec3A as a 3D point, applying perspective correction.
This is the equivalent of multiplying the Vec3A as a 4D vector where w is 1.0.
The perspective divide is performed meaning the resulting 3D vector is divided by w.
This method assumes that self contains a projective transform.
Sourcepub fn transform_point3a(&self, rhs: Vec3A) -> Vec3A
pub fn transform_point3a(&self, rhs: Vec3A) -> Vec3A
Transforms the given Vec3A as 3D point.
This is the equivalent of multiplying the Vec3A as a 4D vector where w is 1.0.
This method assumes that self contains a valid affine transform. If self contains a
perspective transform, or if you are unsure, the Self::project_point3a() method should
be used instead.
§Panics
Will panic if the 3rd row of self is not (0, 0, 0, 1) when glam_assert is enabled.
Sourcepub fn transform_vector3a(&self, rhs: Vec3A) -> Vec3A
pub fn transform_vector3a(&self, rhs: Vec3A) -> Vec3A
Sourcepub fn mul_transpose_vec4(&self, rhs: Vec4) -> Vec4
pub fn mul_transpose_vec4(&self, rhs: Vec4) -> Vec4
Transforms a 4D vector by the transpose of self.
Sourcepub fn mul_scalar(&self, rhs: f32) -> Mat4
pub fn mul_scalar(&self, rhs: f32) -> Mat4
Multiplies a 4x4 matrix by a scalar.
Sourcepub fn mul_diagonal_scale(&self, scale: Vec4) -> Mat4
pub fn mul_diagonal_scale(&self, scale: Vec4) -> Mat4
Multiply self by a scaling vector scale.
This is faster than creating a whole diagonal scaling matrix and then multiplying that.
This operation is commutative.
Sourcepub fn div_scalar(&self, rhs: f32) -> Mat4
pub fn div_scalar(&self, rhs: f32) -> Mat4
Divides a 4x4 matrix by a scalar.
Sourcepub fn recip(&self) -> Mat4
pub fn recip(&self) -> Mat4
Returns a matrix containing the reciprocal 1.0/n of each element of self.
Sourcepub fn abs_diff_eq(&self, rhs: Mat4, max_abs_diff: f32) -> bool
pub fn abs_diff_eq(&self, rhs: Mat4, max_abs_diff: f32) -> bool
Returns true if the absolute difference of all elements between self and rhs
is less than or equal to max_abs_diff.
This can be used to compare if two matrices contain similar elements. It works best
when comparing with a known value. The max_abs_diff that should be used used
depends on the values being compared against.
For more see comparing floating point numbers.
Sourcepub fn as_dmat4(&self) -> DMat4
Available on crate feature f64 only.
pub fn as_dmat4(&self) -> DMat4
f64 only.Examples found in repository?
185 pub fn receive_messages(
186 mut events: MessageReader<Self>,
187 mut controllers: Query<(&mut PanOrbitCamera, &GlobalTransform)>,
188 mut camera_map: ResMut<CameraPointerMap>,
189 pointer_map: Res<PointerMap>,
190 pointer_interactions: Query<&PointerInteraction>,
191 pointer_locations: Query<&PointerLocation>,
192 cameras: Query<(&Camera, &Projection)>,
193 windows: Query<&Window>,
194 ) {
195 for event in events.read() {
196 let Ok((mut controller, cam_transform)) = controllers.get_mut(event.camera()) else {
197 continue;
198 };
199
200 match event {
201 PanOrbitCameraInputMessage::Start { kind, pointer, .. } => {
202 if controller.is_actively_controlled() {
203 continue;
204 }
205 let anchor = pointer_map
206 .get_entity(*pointer)
207 .and_then(|entity| pointer_interactions.get(entity).ok())
208 .and_then(|interaction| interaction.get_nearest_hit())
209 // Since `bevy` 0.17.3:
210 //
211 // If the current hit is on a window, we cannot use the `hit.position` as an anchor
212 // as the `hit.position` is in viewport coordinates.
213 .filter(|(entity, _hit)| !windows.contains(*entity))
214 .and_then(|(_, hit)| hit.position)
215 .map(|world_space_hit| {
216 // Convert the world space hit to view (camera) space
217 cam_transform
218 .to_matrix()
219 .as_dmat4()
220 .inverse()
221 .transform_point3(world_space_hit.into())
222 })
223 .filter(|p| {
224 #[cfg(debug_assertions)]
225 if !p.is_finite() {
226 bevy::log::warn!(
227 "Non-finite input fed to camera controller: {p:?}"
228 );
229 }
230 p.is_finite()
231 })
232 .or_else(|| {
233 let camera = cameras.get(event.camera()).ok();
234 let pointer_location = pointer_map
235 .get_entity(*pointer)
236 .and_then(|entity| pointer_locations.get(entity).ok())
237 .and_then(|l| l.location());
238 if let Some(((camera, proj), pointer_location)) =
239 camera.zip(pointer_location)
240 {
241 screen_to_view_space(
242 camera,
243 proj,
244 &controller,
245 pointer_location.position,
246 )
247 } else {
248 None
249 }
250 })
251 .filter(|p| p.is_finite());
252
253 match kind {
254 MotionKind::OrbitZoom => controller.start_orbit(anchor),
255 MotionKind::PanZoom => controller.start_pan(anchor),
256 MotionKind::Zoom => controller.start_zoom(anchor),
257 }
258 camera_map.insert(*pointer, event.camera());
259 }
260 PanOrbitCameraInputMessage::End { .. } => {
261 controller.end_move();
262 if let Some(pointer) = camera_map
263 .iter()
264 .find(|(.., camera)| **camera == event.camera())
265 .map(|(&pointer, ..)| pointer)
266 {
267 camera_map.remove(&pointer);
268 }
269 }
270 }
271 }
272 }
273
274 /// While a camera motion is active, this system will take care of sending new pointer motion to
275 /// the camera controller. The camera controller assumes that pan and orbit movements are tied
276 /// to screen space pointer motion.
277 ///
278 /// This is because some of the pixel-perfect features of the controller require that data be
279 /// passed in as screen space deltas, to compute perfect first-order control. This is also
280 /// because the plugin uses pointer information to know which camera is being controlled.
281 ///
282 /// If you want to control the camera with different inputs, you will need to replace this
283 /// system with one that tracks other input methods, and sends the required zoom and screenspace
284 /// movement information.
285 pub fn send_pointer_inputs(
286 camera_map: Res<CameraPointerMap>,
287 mut camera_controllers: Query<&mut PanOrbitCamera>,
288 mut mouse_wheel: MessageReader<MouseWheel>,
289 mut moves: MessageReader<PointerInput>,
290 ) {
291 let moves_list: Vec<_> = moves.read().collect();
292 for (pointer, camera) in camera_map.iter() {
293 let Ok(mut camera_controller) = camera_controllers.get_mut(*camera) else {
294 continue;
295 };
296
297 let screenspace_input = moves_list
298 .iter()
299 .filter(|m| m.pointer_id.eq(pointer))
300 .filter_map(|m| match m.action {
301 PointerAction::Move { delta } => Some(delta),
302 _ => None,
303 })
304 .sum();
305
306 let zoom_amount = match pointer {
307 // TODO: add pinch zoom support
308 PointerId::Mouse => mouse_wheel
309 .read()
310 .map(|mw| {
311 let scroll_multiplier = match mw.unit {
312 MouseScrollUnit::Line => 150.0,
313 MouseScrollUnit::Pixel => 1.0,
314 };
315 mw.y * scroll_multiplier
316 })
317 .sum::<f32>(),
318 _ => 0.0,
319 };
320
321 camera_controller.send_screenspace_input(screenspace_input);
322 camera_controller.send_zoom_input(zoom_amount);
323 }
324 // This must be cleared manually because reading these inputs is conditional - we are not
325 // guaranteed to be flushing the events every frame.
326 mouse_wheel.clear();
327 }
328}
329
330fn screen_to_view_space(
331 camera: &Camera,
332 proj: &Projection,
333 controller: &PanOrbitCamera,
334 target_position: Vec2,
335) -> Option<DVec3> {
336 let mut viewport_position = if let Some(rect) = camera.logical_viewport_rect() {
337 target_position.as_dvec2() - rect.min.as_dvec2()
338 } else {
339 target_position.as_dvec2()
340 };
341 let target_size = camera.logical_viewport_size()?.as_dvec2();
342 // Flip the Y co-ordinate origin from the top to the bottom.
343 viewport_position.y = target_size.y - viewport_position.y;
344 let ndc = viewport_position * 2. / target_size - DVec2::ONE;
345 let ndc_to_view = proj.get_clip_from_view().as_dmat4().inverse();
346 let view_near_plane = ndc_to_view.project_point3(ndc.extend(1.));
347 match &proj {
348 Projection::Perspective(_) | Projection::Custom(_) => {
349 // Using EPSILON because an NDC with Z = 0 returns NaNs.
350 let view_far_plane = ndc_to_view.project_point3(ndc.extend(f64::EPSILON));
351 let direction = (view_far_plane - view_near_plane).normalize();
352 Some((direction / direction.z) * controller.last_anchor_depth())
353 }
354 Projection::Orthographic(_) => Some(DVec3::new(
355 view_near_plane.x,
356 view_near_plane.y,
357 controller.last_anchor_depth(),
358 )),
359 }
360}Trait Implementations§
Source§impl AbsDiffEq for Mat4
impl AbsDiffEq for Mat4
Source§fn default_epsilon() -> <Mat4 as AbsDiffEq>::Epsilon
fn default_epsilon() -> <Mat4 as AbsDiffEq>::Epsilon
Source§fn abs_diff_eq(
&self,
other: &Mat4,
epsilon: <Mat4 as AbsDiffEq>::Epsilon,
) -> bool
fn abs_diff_eq( &self, other: &Mat4, epsilon: <Mat4 as AbsDiffEq>::Epsilon, ) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl AddAssign for Mat4
impl AddAssign for Mat4
Source§fn add_assign(&mut self, rhs: Mat4)
fn add_assign(&mut self, rhs: Mat4)
+= operation. Read moreSource§impl AddAssign<&Mat4> for Mat4
impl AddAssign<&Mat4> for Mat4
Source§fn add_assign(&mut self, rhs: &Mat4)
fn add_assign(&mut self, rhs: &Mat4)
+= operation. Read moreSource§impl AsMutMatrixParts<f32, 4, 4> for Mat4
impl AsMutMatrixParts<f32, 4, 4> for Mat4
Source§impl AsRefMatrixParts<f32, 4, 4> for Mat4
impl AsRefMatrixParts<f32, 4, 4> for Mat4
impl Copy for Mat4
Source§impl CreateFrom for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + FromMatrixParts<f32, 4, 4>,
f32: MatrixScalar + CreateFrom,
impl CreateFrom for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + FromMatrixParts<f32, 4, 4>,
f32: MatrixScalar + CreateFrom,
Source§impl<'de> Deserialize<'de> for Mat4
Deserialize expects a sequence of 16 values.
impl<'de> Deserialize<'de> for Mat4
Deserialize expects a sequence of 16 values.
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Mat4, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Mat4, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl DivAssign<&f32> for Mat4
impl DivAssign<&f32> for Mat4
Source§fn div_assign(&mut self, rhs: &f32)
fn div_assign(&mut self, rhs: &f32)
/= operation. Read moreSource§impl DivAssign<f32> for Mat4
impl DivAssign<f32> for Mat4
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl From<Mat4> for GlobalTransform
impl From<Mat4> for GlobalTransform
Source§fn from(world_from_local: Mat4) -> GlobalTransform
fn from(world_from_local: Mat4) -> GlobalTransform
Source§impl FromReflect for Mat4
impl FromReflect for Mat4
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Mat4>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Mat4>
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetTypeRegistration for Mat4
impl GetTypeRegistration for Mat4
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl IntoReturn for Mat4
impl IntoReturn for Mat4
Source§impl MulAssign for Mat4
impl MulAssign for Mat4
Source§fn mul_assign(&mut self, rhs: Mat4)
fn mul_assign(&mut self, rhs: Mat4)
*= operation. Read moreSource§impl MulAssign<&Affine3> for Mat4
impl MulAssign<&Affine3> for Mat4
Source§fn mul_assign(&mut self, rhs: &Affine3)
fn mul_assign(&mut self, rhs: &Affine3)
*= operation. Read moreSource§impl MulAssign<&Affine3A> for Mat4
impl MulAssign<&Affine3A> for Mat4
Source§fn mul_assign(&mut self, rhs: &Affine3A)
fn mul_assign(&mut self, rhs: &Affine3A)
*= operation. Read moreSource§impl MulAssign<&Mat4> for Mat4
impl MulAssign<&Mat4> for Mat4
Source§fn mul_assign(&mut self, rhs: &Mat4)
fn mul_assign(&mut self, rhs: &Mat4)
*= operation. Read moreSource§impl MulAssign<&f32> for Mat4
impl MulAssign<&f32> for Mat4
Source§fn mul_assign(&mut self, rhs: &f32)
fn mul_assign(&mut self, rhs: &f32)
*= operation. Read moreSource§impl MulAssign<Affine3> for Mat4
impl MulAssign<Affine3> for Mat4
Source§fn mul_assign(&mut self, rhs: Affine3)
fn mul_assign(&mut self, rhs: Affine3)
*= operation. Read moreSource§impl MulAssign<Affine3A> for Mat4
impl MulAssign<Affine3A> for Mat4
Source§fn mul_assign(&mut self, rhs: Affine3A)
fn mul_assign(&mut self, rhs: Affine3A)
*= operation. Read moreSource§impl MulAssign<f32> for Mat4
impl MulAssign<f32> for Mat4
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl PartialReflect for Mat4
impl PartialReflect for Mat4
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Mat4>) -> ReflectOwned
fn reflect_owned(self: Box<Mat4>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Mat4>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Mat4>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Source§fn into_partial_reflect(self: Box<Mat4>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Mat4>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn reflect_partial_cmp(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
fn to_dynamic(&self) -> Result<Box<dyn PartialReflect>, ReflectCloneError>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
impl Pod for Mat4
Source§impl ReadFrom for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + AsMutMatrixParts<f32, 4, 4>,
f32: MatrixScalar + ReadFrom,
impl ReadFrom for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + AsMutMatrixParts<f32, 4, 4>,
f32: MatrixScalar + ReadFrom,
Source§impl Reflect for Mat4
impl Reflect for Mat4
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<Mat4>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Mat4>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Source§impl RelativeEq for Mat4
impl RelativeEq for Mat4
Source§fn default_max_relative() -> <Mat4 as AbsDiffEq>::Epsilon
fn default_max_relative() -> <Mat4 as AbsDiffEq>::Epsilon
Source§fn relative_eq(
&self,
other: &Mat4,
epsilon: <Mat4 as AbsDiffEq>::Epsilon,
max_relative: <Mat4 as AbsDiffEq>::Epsilon,
) -> bool
fn relative_eq( &self, other: &Mat4, epsilon: <Mat4 as AbsDiffEq>::Epsilon, max_relative: <Mat4 as AbsDiffEq>::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.Source§impl Serialize for Mat4
Serialize as a sequence of 16 values.
impl Serialize for Mat4
Serialize as a sequence of 16 values.
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl ShaderSize for Mat4where
f32: ShaderSize,
impl ShaderSize for Mat4where
f32: ShaderSize,
Source§const SHADER_SIZE: NonZero<u64> = _
const SHADER_SIZE: NonZero<u64> = _
ShaderType::min_size)Source§impl ShaderType for Mat4where
f32: ShaderSize,
impl ShaderType for Mat4where
f32: ShaderSize,
Source§fn assert_uniform_compat()
fn assert_uniform_compat()
Self meets the requirements of the
uniform address space restrictions on stored values and the
uniform address space layout constraints Read moreSource§impl Struct for Mat4
impl Struct for Mat4
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
name as a &dyn PartialReflect.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
index as a
&dyn PartialReflect.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Source§fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
fn to_dynamic_struct(&self) -> Result<DynamicStruct, ReflectCloneError>
DynamicStruct from this struct. Read moreSource§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None if TypeInfo is not available.Source§impl SubAssign for Mat4
impl SubAssign for Mat4
Source§fn sub_assign(&mut self, rhs: Mat4)
fn sub_assign(&mut self, rhs: Mat4)
-= operation. Read moreSource§impl SubAssign<&Mat4> for Mat4
impl SubAssign<&Mat4> for Mat4
Source§fn sub_assign(&mut self, rhs: &Mat4)
fn sub_assign(&mut self, rhs: &Mat4)
-= operation. Read moreSource§impl TransformPoint for Mat4
impl TransformPoint for Mat4
Source§impl TypePath for Mat4
impl TypePath for Mat4
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Source§impl UlpsEq for Mat4
impl UlpsEq for Mat4
Source§fn default_max_ulps() -> u32
fn default_max_ulps() -> u32
Source§impl WriteInto for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + AsRefMatrixParts<f32, 4, 4>,
f32: MatrixScalar + WriteInto,
impl WriteInto for Mat4where
Mat4: ShaderType<ExtraMetadata = MatrixMetadata> + AsRefMatrixParts<f32, 4, 4>,
f32: MatrixScalar + WriteInto,
fn write_into<B>(&self, writer: &mut Writer<B>)where
B: BufferMut,
Auto Trait Implementations§
impl Freeze for Mat4
impl RefUnwindSafe for Mat4
impl Send for Mat4
impl Sync for Mat4
impl Unpin for Mat4
impl UnsafeUnpin for Mat4
impl UnwindSafe for Mat4
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Brush for T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path. Read moreimpl<T> GpuArrayBufferable for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T> HitDataExtra for T
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Interleave for Twhere
T: Pod,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> NoUninit for Twhere
T: Pod,
Source§impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
Source§fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
func, and turns it into a TemplatePatch.Source§impl<T> PatchTemplate for Twhere
T: Template,
impl<T> PatchTemplate for Twhere
T: Template,
Source§fn patch_template<F>(func: F) -> TemplatePatch<F, T>
fn patch_template<F>(func: F) -> TemplatePatch<F, T>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().impl<T> Reflectable for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
impl<T> Settings for T
Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.Source§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
self.