1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#[cfg(feature = "arbitrary")]
use quickcheck::{Arbitrary, Gen};
#[cfg(feature = "arbitrary")]
use core::storage::Owned;
use num::One;
use rand::{Rng, Rand};
use alga::general::Real;
use alga::linear::Rotation as AlgaRotation;
use core::{DefaultAllocator, Vector2, Vector3};
use core::dimension::{DimName, U2, U3};
use core::allocator::Allocator;
use geometry::{Point, Translation, Rotation, Isometry, UnitQuaternion, UnitComplex,
Point3, Rotation2, Rotation3};
impl<N: Real, D: DimName, R: AlgaRotation<Point<N, D>>> Isometry<N, D, R>
where DefaultAllocator: Allocator<N, D> {
#[inline]
pub fn identity() -> Self {
Self::from_parts(Translation::identity(), R::identity())
}
#[inline]
pub fn rotation_wrt_point(r: R, p: Point<N, D>) -> Self {
let shift = r.transform_vector(&-&p.coords);
Self::from_parts(Translation::from_vector(shift + p.coords), r)
}
}
impl<N: Real, D: DimName, R: AlgaRotation<Point<N, D>>> One for Isometry<N, D, R>
where DefaultAllocator: Allocator<N, D> {
#[inline]
fn one() -> Self {
Self::identity()
}
}
impl<N: Real + Rand, D: DimName, R> Rand for Isometry<N, D, R>
where R: AlgaRotation<Point<N, D>> + Rand,
DefaultAllocator: Allocator<N, D> {
#[inline]
fn rand<G: Rng>(rng: &mut G) -> Self {
Self::from_parts(rng.gen(), rng.gen())
}
}
#[cfg(feature = "arbitrary")]
impl<N, D: DimName, R> Arbitrary for Isometry<N, D, R>
where N: Real + Arbitrary + Send,
R: AlgaRotation<Point<N, D>> + Arbitrary + Send,
Owned<N, D>: Send,
DefaultAllocator: Allocator<N, D> {
#[inline]
fn arbitrary<G: Gen>(rng: &mut G) -> Self {
Self::from_parts(Arbitrary::arbitrary(rng), Arbitrary::arbitrary(rng))
}
}
impl<N: Real> Isometry<N, U2, Rotation2<N>> {
#[inline]
pub fn new(translation: Vector2<N>, angle: N) -> Self {
Self::from_parts(Translation::from_vector(translation), Rotation::<N, U2>::new(angle))
}
}
impl<N: Real> Isometry<N, U2, UnitComplex<N>> {
#[inline]
pub fn new(translation: Vector2<N>, angle: N) -> Self {
Self::from_parts(Translation::from_vector(translation), UnitComplex::from_angle(angle))
}
}
macro_rules! isometry_construction_impl(
($RotId: ident < $($RotParams: ident),*>, $RRDim: ty, $RCDim: ty) => {
impl<N: Real> Isometry<N, U3, $RotId<$($RotParams),*>> {
#[inline]
pub fn new(translation: Vector3<N>, axisangle: Vector3<N>) -> Self {
Self::from_parts(
Translation::from_vector(translation),
$RotId::<$($RotParams),*>::from_scaled_axis(axisangle))
}
#[inline]
pub fn new_observer_frame(eye: &Point3<N>,
target: &Point3<N>,
up: &Vector3<N>)
-> Self {
Self::from_parts(
Translation::from_vector(eye.coords.clone()),
$RotId::new_observer_frame(&(target - eye), up))
}
#[inline]
pub fn look_at_rh(eye: &Point3<N>,
target: &Point3<N>,
up: &Vector3<N>)
-> Self {
let rotation = $RotId::look_at_rh(&(target - eye), up);
let trans = &rotation * (-eye);
Self::from_parts(Translation::from_vector(trans.coords), rotation)
}
#[inline]
pub fn look_at_lh(eye: &Point3<N>,
target: &Point3<N>,
up: &Vector3<N>)
-> Self {
let rotation = $RotId::look_at_lh(&(target - eye), up);
let trans = &rotation * (-eye);
Self::from_parts(Translation::from_vector(trans.coords), rotation)
}
}
}
);
isometry_construction_impl!(Rotation3<N>, U3, U3);
isometry_construction_impl!(UnitQuaternion<N>, U4, U1);