mirror of
https://github.com/lisk77/comet.git
synced 2025-10-24 13:58:49 +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,7 @@
|
|||
use crate::point::{Point2, Point3};
|
||||
use crate::quaternion::Quat;
|
||||
use crate::utilities::acos;
|
||||
use std::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};
|
||||
use comet_log::*;
|
||||
use std::ops::*;
|
||||
|
||||
pub trait InnerSpace {
|
||||
fn dot(&self, other: &Self) -> f32;
|
||||
|
|
@ -140,6 +139,28 @@ impl Mul<f32> for Vec2 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Mul<Vec2> for f32 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn mul(self, other: Vec2) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self * other.x,
|
||||
y: self * other.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<f32> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn div(self, other: f32) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self.x / other,
|
||||
y: self.y / other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[f32;2]> for Vec2 {
|
||||
fn into(self) -> [f32;2] {
|
||||
[self.x, self.y]
|
||||
|
|
@ -674,6 +695,30 @@ impl Mul<f32> for Vec3 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Mul<Vec3> for f32 {
|
||||
type Output = Vec3;
|
||||
|
||||
fn mul(self, other: Vec3) -> Vec3 {
|
||||
Vec3 {
|
||||
x: self * other.x,
|
||||
y: self * other.y,
|
||||
z: self * other.z,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<f32> for Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
fn div(self, other: f32) -> Vec3 {
|
||||
Vec3 {
|
||||
x: self.x / other,
|
||||
y: self.y / other,
|
||||
z: self.z / other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Quat> for Vec3 {
|
||||
fn into(self) -> Quat {
|
||||
Quat::new(0.0, self)
|
||||
|
|
@ -3050,6 +3095,28 @@ impl Mul<f32> for Vec4 {
|
|||
}
|
||||
}
|
||||
|
||||
impl Mul<Vec4> for f32 {
|
||||
type Output = Vec4;
|
||||
|
||||
fn mul(self, other: Vec4) -> Vec4 {
|
||||
Vec4 {
|
||||
x: self * other.x,
|
||||
y: self * other.y,
|
||||
z: self * other.z,
|
||||
w: self * other.w,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MulAssign<f32> for Vec4 {
|
||||
fn mul_assign(&mut self, other: f32) {
|
||||
self.x *= other;
|
||||
self.y *= other;
|
||||
self.z *= other;
|
||||
self.w *= other;
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<[f32;4]> for Vec4 {
|
||||
fn into(self) -> [f32;4] {
|
||||
[self.x, self.y, self.z, self.w]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue