diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-20 19:34:20 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-20 19:34:20 +0200 |
commit | cdc51e0c4369d1ef38ff8d6cc9440b91b2c90535 (patch) | |
tree | a2256eda409144d05114477ac1f0cf56e4730036 /engine | |
parent | 0ca4deaa00d403ae5743434c7b63bc13b821c5ad (diff) |
feat(engine): make the matrix struct public
Diffstat (limited to 'engine')
-rw-r--r-- | engine/src/data_types.rs | 3 | ||||
-rw-r--r-- | engine/src/data_types/matrix.rs | 15 |
2 files changed, 15 insertions, 3 deletions
diff --git a/engine/src/data_types.rs b/engine/src/data_types.rs index 5cf15e4..b35839a 100644 --- a/engine/src/data_types.rs +++ b/engine/src/data_types.rs @@ -1,5 +1,4 @@ pub mod color; pub mod dimens; +pub mod matrix; pub mod vector; - -pub(crate) mod matrix; diff --git a/engine/src/data_types/matrix.rs b/engine/src/data_types/matrix.rs index 85a3721..c5cc63a 100644 --- a/engine/src/data_types/matrix.rs +++ b/engine/src/data_types/matrix.rs @@ -1,7 +1,6 @@ use crate::vector::Vec3; #[derive(Debug, Clone)] -#[repr(C)] pub struct Matrix<Value, const ROWS: usize, const COLUMNS: usize> { /// Items must be layed out this way for it to work with OpenGL shaders. @@ -10,6 +9,8 @@ pub struct Matrix<Value, const ROWS: usize, const COLUMNS: usize> impl<Value, const ROWS: usize, const COLUMNS: usize> Matrix<Value, ROWS, COLUMNS> { + /// Creates a new `ROWS` * `COLUMNS` matrix. + #[must_use] pub fn new() -> Self where Value: Default + Copy, @@ -25,6 +26,7 @@ impl<Value, const ROWS: usize, const COLUMNS: usize> Matrix<Value, ROWS, COLUMNS self.items[column][row] = value; } + /// Returns the internal 2D array as a pointer. #[must_use] pub fn as_ptr(&self) -> *const Value { @@ -32,6 +34,17 @@ impl<Value, const ROWS: usize, const COLUMNS: usize> Matrix<Value, ROWS, COLUMNS } } +impl<Value, const ROWS: usize, const COLUMNS: usize> Default + for Matrix<Value, ROWS, COLUMNS> +where + Value: Copy + Default, +{ + fn default() -> Self + { + Self::new() + } +} + impl<const ROWS_COLS: usize> Matrix<f32, ROWS_COLS, ROWS_COLS> { /// Creates a new identity matrix. |