@@ -2,6 +2,17 @@ use std::ops::Mul;
2
2
3
3
use crate :: core_types:: { Basis , Vector3 } ;
4
4
5
+ // Note regarding naming of interpolation: there are 3 namings in Godot.
6
+ // * `lerp` + `slerp` for simple types
7
+ // * `linear_interpolate` for vectors and colors
8
+ // (now renamed to [`lerp`](https://docs.godotengine.org/en/latest/classes/class_vector3.html?highlight=vector3#class-vector3-method-lerp) + `slerp`)
9
+ // * `Vector3` also has `cubic_interpolate` and `bezier_interpolate`, which might explain the origins
10
+ // * `interpolate_with` for transforms; in Godot 4 also
11
+ // [`sphere_interpolate_with`](https://docs.godotengine.org/en/latest/classes/class_transform3d.html#class-transform3d-method-sphere-interpolate-with)
12
+ //
13
+ // We currently also have `Transform2D::interpolate_with()`.
14
+ // In an ideal world, all those would be called `lerp` and `slerp`.
15
+
5
16
/// Affine 3D transform (3x4 matrix).
6
17
///
7
18
/// Used for 3D linear transformations. Uses a basis + origin representation.
@@ -89,7 +100,7 @@ impl Transform {
89
100
/// Returns this transform, with its origin moved by a certain `translation`
90
101
#[ deprecated = "`translated` is not relative to the transform's coordinate system \
91
102
and thus inconsistent with GDScript. Please use translated_global() instead. \
92
- This method will be renamed to translated_local in gdnative 0.11 ."]
103
+ This method will be renamed to translated_local in gdnative 0.12 ."]
93
104
#[ inline]
94
105
pub fn translated ( & self , translation : Vector3 ) -> Self {
95
106
Self {
@@ -119,17 +130,18 @@ impl Transform {
119
130
/// affine_inverse for transforms with scaling).
120
131
#[ inline]
121
132
pub fn inverse ( & self ) -> Self {
133
+ let basis = self . basis . transposed ( ) ;
122
134
Transform {
123
- basis : self . basis . transposed ( ) ,
124
- origin : self . basis . xform ( -self . origin ) ,
135
+ basis,
136
+ origin : basis. xform ( -self . origin ) ,
125
137
}
126
138
}
127
139
128
140
/// Returns the inverse of the transform, under the assumption that the
129
141
/// transformation is composed of rotation, scaling and translation.
130
142
#[ inline]
131
143
pub fn affine_inverse ( & self ) -> Self {
132
- let basis_inv = self . basis . inverted ( ) ;
144
+ let basis_inv = self . basis . inverse ( ) ;
133
145
let origin_inv = basis_inv. xform ( -self . origin ) ;
134
146
135
147
Self {
@@ -150,12 +162,14 @@ impl Transform {
150
162
} * ( * self )
151
163
}
152
164
165
+ /*
153
166
/// Returns the rotated transform around the given axis by the given angle (in radians),
154
167
/// using matrix multiplication. The axis must be a normalized vector.
155
168
#[inline]
156
169
fn rotate(&mut self, axis: Vector3, phi: f32) {
157
170
*self = self.rotated(axis, phi);
158
171
}
172
+ */
159
173
160
174
/// Returns a copy of the transform rotated such that its -Z axis points
161
175
/// towards the target position.
@@ -189,7 +203,7 @@ impl Transform {
189
203
/// In-place translates the transform by the given offset, relative to
190
204
/// the transform's basis vectors.
191
205
#[ inline]
192
- fn translate_withbasis ( & mut self , translation : Vector3 ) {
206
+ fn translate_global ( & mut self , translation : Vector3 ) {
193
207
// Note: Godot source uses origin + basis dot translation,
194
208
// but self.translate() uses only origin + translation
195
209
self . origin . x += self . basis . elements [ 0 ] . dot ( translation) ;
@@ -204,7 +218,7 @@ impl Transform {
204
218
#[ inline]
205
219
pub fn translated_global ( & self , translation : Vector3 ) -> Self {
206
220
let mut copy = * self ;
207
- copy. translate_withbasis ( translation) ;
221
+ copy. translate_global ( translation) ;
208
222
copy
209
223
}
210
224
@@ -356,6 +370,23 @@ mod tests {
356
370
assert ! ( expected. is_equal_approx( & t) )
357
371
}
358
372
373
+ /*
374
+ #[test]
375
+ fn inverse_is_sane() {
376
+ let t = test_inputs().0.inverse();
377
+ let expected = Transform::from_basis_origin(
378
+ // Fix values
379
+ Vector3::new(0.309725, -0.66022015, 3.9329607),
380
+ Vector3::new(-0.57629496, 1.8808193, 0.3611141),
381
+ Vector3::new(-0.47722515, -0.14864945, 0.012628445),
382
+ Vector3::new(-0.7398631, 0.0425314, 0.03682696),
383
+ );
384
+
385
+ println!("TF: {t:?}");
386
+ assert!(expected.is_equal_approx(&t))
387
+ }
388
+ */
389
+
359
390
#[ test]
360
391
fn orthonormalization_is_sane ( ) {
361
392
// Godot reports:
0 commit comments