mirror of
https://github.com/lisk77/comet.git
synced 2025-12-12 17:18:50 +00:00
feat: added some operations to vectors and quaternions
This commit is contained in:
parent
c90d09fd49
commit
1558a9896c
3 changed files with 184 additions and 27 deletions
|
|
@ -1,8 +1,9 @@
|
|||
use std::ops::*;
|
||||
use std::ops::Mul;
|
||||
|
||||
use crate::vector::Vec3;
|
||||
|
||||
/// Representation of a quaternion in scalar/vector form
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Quat {
|
||||
pub s: f32,
|
||||
pub v: Vec3,
|
||||
|
|
@ -44,6 +45,72 @@ impl Quat {
|
|||
}
|
||||
}
|
||||
|
||||
impl Add<Quat> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn add(self, other: Quat) -> Quat {
|
||||
Quat {
|
||||
s: self.s + other.s,
|
||||
v: self.v + other.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub<Quat> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn sub(self, other: Quat) -> Quat {
|
||||
Quat {
|
||||
s: self.s - other.s,
|
||||
v: self.v - other.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn neg(self) -> Quat {
|
||||
Quat {
|
||||
s: -self.s,
|
||||
v: -self.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<f32> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn add(self, scalar: f32) -> Quat {
|
||||
Quat {
|
||||
s: self.s + scalar,
|
||||
v: self.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub<f32> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn sub(self, scalar: f32) -> Quat {
|
||||
Quat {
|
||||
s: self.s - scalar,
|
||||
v: self.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Quat> for f32 {
|
||||
type Output = Quat;
|
||||
|
||||
fn mul(self, quat: Quat) -> Quat {
|
||||
Quat {
|
||||
s: self*quat.s,
|
||||
v: self*quat.v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Quat> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
|
|
@ -58,3 +125,25 @@ impl Mul<Quat> for Quat {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f32> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn mul(self, scalar: f32) -> Quat {
|
||||
Quat {
|
||||
s: self.s*scalar,
|
||||
v: self.v*scalar,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<f32> for Quat {
|
||||
type Output = Quat;
|
||||
|
||||
fn div(self, scalar: f32) -> Quat {
|
||||
Quat {
|
||||
s: self.s/scalar,
|
||||
v: self.v/scalar,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue