Implement more gtx functions.
This commit is contained in:
parent
a827e2d95f
commit
98cf1a8d17
|
@ -1,43 +1,49 @@
|
|||
use na::{Real, U2, U3, U4};
|
||||
use na::{Real, U2, U3, U4, Rotation3, Vector3, Unit, UnitComplex};
|
||||
|
||||
pub fn orientation<N: Real>(Normal: &Vec<N, U3>, Up: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
||||
unimplemented!()
|
||||
use aliases::{Vec, Mat};
|
||||
|
||||
pub fn orientation<N: Real>(normal: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
||||
if let Some(r) = Rotation3::rotation_between(normal, up) {
|
||||
r.to_homogeneous()
|
||||
} else {
|
||||
Mat::<N, U4, U4>::identity()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rotate2<N: Real>(v: &Vec<N, U2>, angle: N) -> Vec<N, U2> {
|
||||
unimplemented!()
|
||||
UnitComplex::new(angle) * v
|
||||
}
|
||||
|
||||
pub fn rotate<N: Real>(v: &Vec<N, U3>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U3> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v
|
||||
}
|
||||
|
||||
pub fn rotate4<N: Real>(v: &Vec<N, U4>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U4> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v
|
||||
}
|
||||
|
||||
pub fn rotateX<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::x_axis(), angle) * v
|
||||
}
|
||||
|
||||
pub fn rotateX4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::x_axis(), angle).to_homogeneous() * v
|
||||
}
|
||||
|
||||
pub fn rotateY<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::y_axis(), angle) * v
|
||||
}
|
||||
|
||||
pub fn rotateY4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::y_axis(), angle).to_homogeneous() * v
|
||||
}
|
||||
|
||||
pub fn rotateZ<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::z_axis(), angle) * v
|
||||
}
|
||||
|
||||
pub fn rotateZ4<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
|
||||
unimplemented!()
|
||||
Rotation3::from_axis_angle(&Vector3::z_axis(), angle).to_homogeneous() * v
|
||||
}
|
||||
|
||||
pub fn slerp<N: Real>(x: &Vec<N, U3>, y: &Vec<N, U3>, a: N) -> Vec<N, U3> {
|
||||
|
|
|
@ -1,9 +1,127 @@
|
|||
pub fn mat< 3, 3, T, Q > proj2D (mat< 3, 3, T, Q > const &m, vec< 3, T, Q > const &normal)
|
||||
pub fn mat< 4, 4, T, Q > proj3D (mat< 4, 4, T, Q > const &m, vec< 3, T, Q > const &normal)
|
||||
pub fn mat< 4, 4, T, Q > scaleBias (T scale, T bias)
|
||||
pub fn mat< 4, 4, T, Q > scaleBias (mat< 4, 4, T, Q > const &m, T scale, T bias)
|
||||
pub fn mat< 3, 3, T, Q > shearX2D (mat< 3, 3, T, Q > const &m, T y)
|
||||
pub fn mat< 4, 4, T, Q > shearX3D (mat< 4, 4, T, Q > const &m, T y, T z)
|
||||
pub fn mat< 3, 3, T, Q > shearY2D (mat< 3, 3, T, Q > const &m, T x)
|
||||
pub fn mat< 4, 4, T, Q > shearY3D (mat< 4, 4, T, Q > const &m, T x, T z)
|
||||
pub fn mat< 4, 4, T, Q > shearZ3D (mat< 4, 4, T, Q > const &m, T x, T y)
|
||||
use na::{self, U2, U3, U4, Matrix3, Matrix4};
|
||||
|
||||
use traits::Number;
|
||||
use aliases::{Mat, Vec};
|
||||
|
||||
pub fn proj2D<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
|
||||
let mut res = Matrix3::identity();
|
||||
|
||||
{
|
||||
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
|
||||
part -= normal * normal.transpose();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn proj3D<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
||||
let mut res = Matrix4::identity();
|
||||
|
||||
{
|
||||
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
|
||||
part -= normal * normal.transpose();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn reflect2D<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
|
||||
let mut res = Matrix3::identity();
|
||||
|
||||
{
|
||||
let mut part = res.fixed_slice_mut::<U2, U2>(0, 0);
|
||||
part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn reflect3D<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
|
||||
let mut res = Matrix4::identity();
|
||||
|
||||
{
|
||||
let mut part = res.fixed_slice_mut::<U3, U3>(0, 0);
|
||||
part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn scaleBias<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
|
||||
Matrix4::new(
|
||||
scale, _0, _0, bias,
|
||||
_0, scale, _0, bias,
|
||||
_0, _0, scale, bias,
|
||||
_0, _0, _0, _1,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn scaleBias2<N: Number>(m: &Mat<N, U4, U4>, scale: N, bias: N) -> Mat<N, U4, U4> {
|
||||
m * scaleBias(scale, bias)
|
||||
}
|
||||
|
||||
pub fn shearX2D<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
|
||||
let shear = Matrix3::new(
|
||||
_1, y, _0,
|
||||
_0, _1, _0,
|
||||
_0, _0, _1
|
||||
);
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn shearX3D<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
let shear = Matrix4::new(
|
||||
_1, _0, _0, _0,
|
||||
y, _1, _0, _0,
|
||||
z, _0, _1, _0,
|
||||
_0, _0, _0, _1,
|
||||
);
|
||||
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn shearY2D<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
|
||||
let shear = Matrix3::new(
|
||||
_1, _0, _0,
|
||||
x, _1, _0,
|
||||
_0, _0, _1
|
||||
);
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn shearY3D<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
let shear = Matrix4::new(
|
||||
_1, x, _0, _0,
|
||||
_0, _1, _0, _0,
|
||||
_0, z, _1, _0,
|
||||
_0, _0, _0, _1,
|
||||
);
|
||||
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn shearZ3D<N: Number>(m: &Mat<N, U4, U4>, x: N, y: N) -> Mat<N, U4, U4> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
let shear = Matrix4::new(
|
||||
_1, _0, x, _0,
|
||||
_0, _1, y, _0,
|
||||
_0, _0, _1, _0,
|
||||
_0, _0, _0, _1,
|
||||
);
|
||||
|
||||
m * shear
|
||||
}
|
||||
|
|
|
@ -1,5 +1,40 @@
|
|||
pub fn mat< 3, 3, T, Q > rotate (mat< 3, 3, T, Q > const &m, T angle)
|
||||
pub fn mat< 3, 3, T, Q > scale (mat< 3, 3, T, Q > const &m, vec< 2, T, Q > const &v)
|
||||
pub fn mat< 3, 3, T, Q > shearX (mat< 3, 3, T, Q > const &m, T y)
|
||||
pub fn mat< 3, 3, T, Q > shearY (mat< 3, 3, T, Q > const &m, T x)
|
||||
pub fn mat< 3, 3, T, Q > translate (mat< 3, 3, T, Q > const &m, vec< 2, T, Q > const &v)
|
||||
use na::{Real, U2, U3, UnitComplex, Matrix3};
|
||||
|
||||
use traits::Number;
|
||||
use aliases::{Mat, Vec};
|
||||
|
||||
pub fn rotate<N: Real>(m: &Mat<N, U3, U3>, angle: N) -> Mat<N, U3, U3> {
|
||||
m * UnitComplex::new(angle).to_homogeneous()
|
||||
}
|
||||
|
||||
pub fn scale<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
|
||||
m.prepend_nonuniform_scaling(v)
|
||||
}
|
||||
|
||||
pub fn shearX<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
|
||||
let shear = Matrix3::new(
|
||||
_1, y, _0,
|
||||
_0, _1, _0,
|
||||
_0, _0, _1
|
||||
);
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn shearY<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
|
||||
let _0 = N::zero();
|
||||
let _1 = N::one();
|
||||
|
||||
let shear = Matrix3::new(
|
||||
_1, _0, _0,
|
||||
x, _1, _0,
|
||||
_0, _0, _1
|
||||
);
|
||||
m * shear
|
||||
}
|
||||
|
||||
pub fn translate<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
|
||||
m.prepend_translation(v)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
pub fn T angle (vec< L, T, Q > const &x, vec< L, T, Q > const &y)
|
||||
pub fn T orientedAngle (vec< 2, T, Q > const &x, vec< 2, T, Q > const &y)
|
||||
pub fn T orientedAngle (vec< 3, T, Q > const &x, vec< 3, T, Q > const &y, vec< 3, T, Q > const &ref)
|
||||
use na::{self, DefaultAllocator, Real, U2, U3};
|
||||
|
||||
use traits::{Dimension, Alloc};
|
||||
use aliases::Vec;
|
||||
|
||||
|
||||
pub fn angle<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.angle(y)
|
||||
}
|
||||
|
||||
pub fn oriented_angle<N: Real>(x: &Vec<N, U2>, y: &Vec<N, U2>) -> N {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn oriented_angle_ref<N: Real>(x: &Vec<N, U3>, y: &Vec<N, U3>, refv: &Vec<N, U3>) -> N {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue