| 1 |
use super::glam::{DMat3, DMat4, DQuat, DVec2, DVec3, Mat3, Mat4, Quat, Vec2, Vec3}; |
| 2 |
use crate::{Isometry2, Isometry3, Matrix3, Matrix4, Translation3, UnitQuaternion}; |
| 3 |
use std::convert::TryFrom; |
| 4 |
|
| 5 |
impl From<Isometry2<f32>> for Mat3 { |
| 6 |
fn from(iso: Isometry2<f32>) -> Mat3 { |
| 7 |
iso.to_homogeneous().into() |
| 8 |
} |
| 9 |
} |
| 10 |
impl From<Isometry3<f32>> for Mat4 { |
| 11 |
fn from(iso: Isometry3<f32>) -> Mat4 { |
| 12 |
iso.to_homogeneous().into() |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
impl From<Isometry2<f64>> for DMat3 { |
| 17 |
fn from(iso: Isometry2<f64>) -> DMat3 { |
| 18 |
iso.to_homogeneous().into() |
| 19 |
} |
| 20 |
} |
| 21 |
impl From<Isometry3<f64>> for DMat4 { |
| 22 |
fn from(iso: Isometry3<f64>) -> DMat4 { |
| 23 |
iso.to_homogeneous().into() |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
impl From<Isometry3<f32>> for (Vec3, Quat) { |
| 28 |
fn from(iso: Isometry3<f32>) -> (Vec3, Quat) { |
| 29 |
(iso.translation.into(), iso.rotation.into()) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
impl From<Isometry3<f64>> for (DVec3, DQuat) { |
| 34 |
fn from(iso: Isometry3<f64>) -> (DVec3, DQuat) { |
| 35 |
(iso.translation.into(), iso.rotation.into()) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
impl From<Isometry2<f32>> for (Vec2, f32) { |
| 40 |
fn from(iso: Isometry2<f32>) -> (Vec2, f32) { |
| 41 |
let tra = Vec2::new(iso.translation.x, iso.translation.y); |
| 42 |
let rot = iso.rotation.angle(); |
| 43 |
(tra, rot) |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
impl From<Isometry2<f64>> for (DVec2, f64) { |
| 48 |
fn from(iso: Isometry2<f64>) -> (DVec2, f64) { |
| 49 |
let tra = DVec2::new(iso.translation.x, iso.translation.y); |
| 50 |
let rot = iso.rotation.angle(); |
| 51 |
(tra, rot) |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
impl From<(Vec3, Quat)> for Isometry3<f32> { |
| 56 |
fn from((tra, rot): (Vec3, Quat)) -> Self { |
| 57 |
Isometry3::from_parts(tra.into(), rot.into()) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
impl From<(DVec3, DQuat)> for Isometry3<f64> { |
| 62 |
fn from((tra, rot): (DVec3, DQuat)) -> Self { |
| 63 |
Isometry3::from_parts(tra.into(), rot.into()) |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
impl From<(Vec2, f32)> for Isometry2<f32> { |
| 68 |
fn from((tra, rot): (Vec2, f32)) -> Self { |
| 69 |
Isometry2::new(tra.into(), rot) |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
impl From<(DVec2, f64)> for Isometry2<f64> { |
| 74 |
fn from((tra, rot): (DVec2, f64)) -> Self { |
| 75 |
Isometry2::new(tra.into(), rot) |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
impl From<Quat> for Isometry3<f32> { |
| 80 |
fn from(rot: Quat) -> Self { |
| 81 |
Isometry3::from_parts(Translation3::identity(), rot.into()) |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
impl From<DQuat> for Isometry3<f64> { |
| 86 |
fn from(rot: DQuat) -> Self { |
| 87 |
Isometry3::from_parts(Translation3::identity(), rot.into()) |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
impl From<Vec3> for Isometry3<f32> { |
| 92 |
fn from(tra: Vec3) -> Self { |
| 93 |
Isometry3::from_parts(tra.into(), UnitQuaternion::identity()) |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
impl From<DVec3> for Isometry3<f64> { |
| 98 |
fn from(tra: DVec3) -> Self { |
| 99 |
Isometry3::from_parts(tra.into(), UnitQuaternion::identity()) |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
impl From<Vec2> for Isometry2<f32> { |
| 104 |
fn from(tra: Vec2) -> Self { |
| 105 |
Isometry2::new(tra.into(), 0.0) |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
impl From<DVec2> for Isometry2<f64> { |
| 110 |
fn from(tra: DVec2) -> Self { |
| 111 |
Isometry2::new(tra.into(), 0.0) |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
impl TryFrom<Mat3> for Isometry2<f32> { |
| 116 |
type Error = (); |
| 117 |
|
| 118 |
fn try_from(mat3: Mat3) -> Result<Isometry2<f32>, Self::Error> { |
| 119 |
crate::try_convert(Matrix3::from(mat3)).ok_or(()) |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
impl TryFrom<Mat4> for Isometry3<f32> { |
| 124 |
type Error = (); |
| 125 |
|
| 126 |
fn try_from(mat4: Mat4) -> Result<Isometry3<f32>, Self::Error> { |
| 127 |
crate::try_convert(Matrix4::from(mat4)).ok_or(()) |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
impl TryFrom<DMat3> for Isometry2<f64> { |
| 132 |
type Error = (); |
| 133 |
|
| 134 |
fn try_from(mat3: DMat3) -> Result<Isometry2<f64>, Self::Error> { |
| 135 |
crate::try_convert(Matrix3::from(mat3)).ok_or(()) |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
impl TryFrom<DMat4> for Isometry3<f64> { |
| 140 |
type Error = (); |
| 141 |
|
| 142 |
fn try_from(mat4: DMat4) -> Result<Isometry3<f64>, Self::Error> { |
| 143 |
crate::try_convert(Matrix4::from(mat4)).ok_or(()) |
| 144 |
} |
| 145 |
} |