aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/matrix4x4.rs31
-rw-r--r--src/core/transform.rs17
2 files changed, 48 insertions, 0 deletions
diff --git a/src/core/matrix4x4.rs b/src/core/matrix4x4.rs
index 521d7ab..f8c685d 100644
--- a/src/core/matrix4x4.rs
+++ b/src/core/matrix4x4.rs
@@ -1,4 +1,5 @@
use crate::{Number, Float};
+use std::ops;
pub struct Matrix4x4<T: Number> {
pub m: [[T; 4]; 4],
@@ -20,6 +21,36 @@ impl<T: Number> Matrix4x4<T> {
],
}
}
+
+ pub fn initial(initial: T) -> Self {
+ Self {
+ m : [ [initial; 4]; 4]
+ }
+ }
+
+ pub fn inverse(&self) -> Self {
+
+ }
+}
+
+impl<T: Number> ops::Mul for &Matrix4x4<T> {
+ type Output = Matrix4x4<T>;
+
+ fn mul(self, op: Self) -> Self::Output {
+ let mut res = Self::Output::initial(Default::default());
+
+ // Not very fast
+ for i in 0..4 {
+ for j in 0..4 {
+ res.m[i][j] = self.m[i][0] * op.m[0][j] +
+ self.m[i][1] * op.m[1][j] +
+ self.m[i][2] * op.m[2][j] +
+ self.m[i][3] * op.m[3][j];
+ }
+ }
+
+ res
+ }
}
impl Matrix4x4f {
diff --git a/src/core/transform.rs b/src/core/transform.rs
index f64710c..337d9b1 100644
--- a/src/core/transform.rs
+++ b/src/core/transform.rs
@@ -17,6 +17,7 @@
use super::matrix4x4::Matrix4x4f;
use crate::Float;
use crate::core::Vector3f;
+use std::ops;
pub struct Transform {
m: Matrix4x4f,
@@ -56,6 +57,22 @@ impl Transform {
Vector3f::new_xyz(x, y, z)
}
+
+ pub fn inverse(&self) -> Self {
+ Transform {
+ m: self.m.inverse(),
+ }
+ }
+}
+
+impl ops::Mul for Transform {
+ type Output = Transform;
+
+ fn mul(self, op: Self) -> Self::Output {
+ Transform {
+ m: &self.m * &op.m
+ }
+ }
}
// Creation of different transformations