diff --git a/src/f32/mat4.rs b/src/f32/mat4.rs index 85be3db3..c6e0fef0 100644 --- a/src/f32/mat4.rs +++ b/src/f32/mat4.rs @@ -138,7 +138,7 @@ impl Mat4 { } } - /// Create a new homogenous `Mat4` containing a rotation around a normalized rotation axis of + /// Create a new `Mat4` containing a rotation around a normalized rotation axis of /// angle (in radians). #[inline] pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self { @@ -159,7 +159,7 @@ impl Mat4 { } } - /// Create a new homogenous `Mat4` containing a rotation around the given euler angles + /// Create a new `Mat4` containing a rotation around the given euler angles /// (in radians). #[inline] pub fn from_rotation_ypr(yaw: f32, pitch: f32, roll: f32) -> Self { @@ -167,7 +167,7 @@ impl Mat4 { Self::from_quat(quat) } - /// Create a new homogenous `Mat4` containing a rotation around the x axis of angle + /// Create a new `Mat4` containing a rotation around the x axis of angle /// (in radians). #[inline] pub fn from_rotation_x(angle: f32) -> Self { @@ -180,7 +180,7 @@ impl Mat4 { } } - /// Create a new homogenous `Mat4` containing a rotation around the y axis of angle + /// Create a new `Mat4` containing a rotation around the y axis of angle /// (in radians). #[inline] pub fn from_rotation_y(angle: f32) -> Self { @@ -193,7 +193,7 @@ impl Mat4 { } } - /// Create a new homogenous `Mat4` containing a rotation around the z axis of angle + /// Create a new `Mat4` containing a rotation around the z axis of angle /// (in radians). #[inline] pub fn from_rotation_z(angle: f32) -> Self { @@ -218,6 +218,43 @@ impl Mat4 { } } + #[inline] + pub fn from_array_as_cols(m: [f32; 16]) -> Self { + Mat4 { + x_axis: Vec4::new(m[0], m[1], m[2], m[3]), + y_axis: Vec4::new(m[4], m[5], m[6], m[7]), + z_axis: Vec4::new(m[8], m[9], m[10], m[11]), + w_axis: Vec4::new(m[12], m[13], m[14], m[15]), + } + } + + #[inline] + pub fn to_array_as_cols(&self) -> [f32; 16] { + *self.as_ref() + } + + /// Create a new `Mat4` from a 4x4 array of f32. + /// Array rows are treated as columns. + #[inline] + pub fn from_arrays_as_cols(m: [[f32; 4]; 4]) -> Self { + Mat4 { + x_axis: m[0].into(), + y_axis: m[1].into(), + z_axis: m[2].into(), + w_axis: m[3].into(), + } + } + + #[inline] + pub fn to_arrays_as_cols(&self) -> [[f32; 4]; 4] { + [ + self.x_axis.into(), + self.y_axis.into(), + self.z_axis.into(), + self.w_axis.into(), + ] + } + #[inline] pub fn set_x_axis(&mut self, x: Vec4) { self.x_axis = x; @@ -606,45 +643,45 @@ impl Mul for Mat4 { } } +#[deprecated( + since = "0.7.2", + note = "please use `Mat4::from_arrays_as_cols` instead" +)] impl From<[[f32; 4]; 4]> for Mat4 { - #[inline] fn from(m: [[f32; 4]; 4]) -> Self { - Mat4 { - x_axis: m[0].into(), - y_axis: m[1].into(), - z_axis: m[2].into(), - w_axis: m[3].into(), - } + Mat4::from_arrays_as_cols(m) } } +#[deprecated( + since = "0.7.2", + note = "please use `Mat4::to_arrays_as_cols` instead" +)] impl From for [[f32; 4]; 4] { #[inline] fn from(m: Mat4) -> Self { - [ - m.x_axis.into(), - m.y_axis.into(), - m.z_axis.into(), - m.w_axis.into(), - ] + m.to_arrays_as_cols() } } +#[deprecated( + since = "0.7.2", + note = "please use `Mat4::from_array_as_cols` instead" +)] impl From<[f32; 16]> for Mat4 { #[inline] fn from(m: [f32; 16]) -> Self { - Mat4 { - x_axis: Vec4::new(m[0], m[1], m[2], m[3]), - y_axis: Vec4::new(m[4], m[5], m[6], m[7]), - z_axis: Vec4::new(m[8], m[9], m[10], m[11]), - w_axis: Vec4::new(m[12], m[13], m[14], m[15]), - } + Mat4::from_array_as_cols(m) } } +#[deprecated( + since = "0.7.2", + note = "please use `Mat4::to_array_as_cols` instead" +)] impl From for [f32; 16] { #[inline] fn from(m: Mat4) -> Self { - *m.as_ref() + m.to_array_as_cols() } }