summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/src/data_types.rs3
-rw-r--r--engine/src/data_types/matrix.rs15
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.