fromsoftware_shared/
matrix.rs

1/// Defines some helper methods around dealing with math
2use std::ops::{Add, Sub};
3
4pub trait MatrixLayout {}
5
6pub enum RowMajor {}
7impl MatrixLayout for RowMajor {}
8
9pub enum ColMajor {}
10impl MatrixLayout for ColMajor {}
11
12#[repr(C)]
13#[derive(Debug)]
14pub struct F32Matrix4x4<L: MatrixLayout = RowMajor>(
15    pub F32Vector4,
16    pub F32Vector4,
17    pub F32Vector4,
18    pub F32Vector4,
19    std::marker::PhantomData<L>,
20);
21
22#[repr(C, align(16))]
23#[derive(Debug, Clone, Copy)]
24pub struct F32Vector4(pub f32, pub f32, pub f32, pub f32);
25
26impl Sub<F32Vector4> for F32Vector4 {
27    type Output = F32Vector4;
28
29    fn sub(self, rhs: F32Vector4) -> Self::Output {
30        F32Vector4(
31            self.0 - rhs.0,
32            self.1 - rhs.1,
33            self.2 - rhs.2,
34            self.3 - rhs.3,
35        )
36    }
37}
38
39impl Add<F32Vector4> for F32Vector4 {
40    type Output = F32Vector4;
41
42    fn add(self, rhs: F32Vector4) -> Self::Output {
43        F32Vector4(
44            self.0 - rhs.0,
45            self.1 - rhs.1,
46            self.2 - rhs.2,
47            self.3 - rhs.3,
48        )
49    }
50}
51
52#[repr(C)]
53#[derive(Debug, Clone, Copy)]
54pub struct F32Vector3(pub f32, pub f32, pub f32);