added nlerp for quats
@@ -100,10 +100,38 @@ impl Quat {
}
}
// Fallback
+ *other
+ }
+
+ pub fn normalized(&self) -> Self {
+ let len = self.len();
+ if len >= std::f32::EPSILON {
+ let inv_len = 1.0 / len;
+ Self {
+ x: self.x * inv_len,
+ y: self.y * inv_len,
+ z: self.z * inv_len,
+ w: self.w * inv_len,
+ }
+ } else {
*self
}
}
+ pub fn nlerp(&self, other: &Self, t: f32) -> Self {
+ (self.scale(1.0 - t) + other.scale(t)).normalized()
+ }
+
+ pub fn scale(&self, factor: f32) -> Self {
+ Self {
+ x: self.x * factor,
+ y: self.y * factor,
+ z: self.z * factor,
+ w: self.w * factor,
+ }
+ }
+}
+
impl ops::Mul<Self> for Quat {
type Output = Self;
fn mul(self, b: Self) -> Self {
@@ -115,3 +143,17 @@ impl ops::Mul<Self> for Quat {
}
}
}
+
+
+impl ops::Add<Self> for Quat {
+ type Output = Self;
+ #[inline]
+ fn add(self, b: Self) -> Self {
+ Self {
+ x: self.x + b.x,
+ y: self.y + b.y,
+ z: self.z + b.z,
+ w: self.w + b.w,
+ }
+ }
+}
