Quaternion memory layout changed to [x, y, z, w]
(#500)
The `From` and `Into` impls for `[S; 4]` and `(S, S, S, S)` have been changed accordingly. This is consistent with other libraries like glm, nalgebra, and glam, as well as the glTF spec. Note that the `Quaternion::new` constructor has **not** yet been updated.
This commit is contained in:
parent
a691de8714
commit
164808eebc
2 changed files with 14 additions and 10 deletions
|
@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
default_fn! macro to reduce code duplication and complexity. Currently
|
default_fn! macro to reduce code duplication and complexity. Currently
|
||||||
only needed for non-functional SIMD feature.
|
only needed for non-functional SIMD feature.
|
||||||
- Refactored SIMD code into separate source files. See README.md for details.
|
- Refactored SIMD code into separate source files. See README.md for details.
|
||||||
|
- **Breaking**: Quaternion memory layout changed to `[x, y, z, w]`. The
|
||||||
|
`From` and `Into` impls for `[S; 4]` and `(S, S, S, S)` have been changed
|
||||||
|
accordingly.
|
||||||
|
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,10 @@ use mint;
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Quaternion<S> {
|
pub struct Quaternion<S> {
|
||||||
/// The scalar part of the quaternion.
|
|
||||||
pub s: S,
|
|
||||||
/// The vector part of the quaternion.
|
/// The vector part of the quaternion.
|
||||||
pub v: Vector3<S>,
|
pub v: Vector3<S>,
|
||||||
|
/// The scalar part of the quaternion.
|
||||||
|
pub s: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Quaternion<S> {
|
impl<S> Quaternion<S> {
|
||||||
|
@ -542,7 +542,7 @@ impl<S: BaseFloat> Into<[S; 4]> for Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into(self) -> [S; 4] {
|
fn into(self) -> [S; 4] {
|
||||||
match self.into() {
|
match self.into() {
|
||||||
(w, xi, yj, zk) => [w, xi, yj, zk],
|
(xi, yj, zk, w) => [xi, yj, zk, w],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,7 +564,7 @@ impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> {
|
||||||
impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
|
impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(v: [S; 4]) -> Quaternion<S> {
|
fn from(v: [S; 4]) -> Quaternion<S> {
|
||||||
Quaternion::new(v[0], v[1], v[2], v[3])
|
Quaternion::new(v[3], v[0], v[1], v[2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,7 +589,7 @@ impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S> {
|
||||||
Quaternion {
|
Quaternion {
|
||||||
s,
|
s,
|
||||||
v: Vector3 { x, y, z },
|
v: Vector3 { x, y, z },
|
||||||
} => (s, x, y, z),
|
} => (x, y, z, s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(v: (S, S, S, S)) -> Quaternion<S> {
|
fn from(v: (S, S, S, S)) -> Quaternion<S> {
|
||||||
match v {
|
match v {
|
||||||
(w, xi, yj, zk) => Quaternion::new(w, xi, yj, zk),
|
(xi, yj, zk, w) => Quaternion::new(w, xi, yj, zk),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,12 +698,12 @@ mod tests {
|
||||||
use vector::*;
|
use vector::*;
|
||||||
|
|
||||||
const QUATERNION: Quaternion<f32> = Quaternion {
|
const QUATERNION: Quaternion<f32> = Quaternion {
|
||||||
s: 1.0,
|
|
||||||
v: Vector3 {
|
v: Vector3 {
|
||||||
x: 2.0,
|
x: 1.0,
|
||||||
y: 3.0,
|
y: 2.0,
|
||||||
z: 4.0,
|
z: 3.0,
|
||||||
},
|
},
|
||||||
|
s: 4.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue