@@ -87,6 +87,9 @@ impl Transform {
87
87
}
88
88
89
89
/// Returns this transform, with its origin moved by a certain `translation`
90
+ #[ deprecated = "`translated` is not relative to the transform's coordinate system \
91
+ and thus inconsistent with GDScript. Please use translated_global() instead. \
92
+ This method will be renamed to translated_local in gdnative 0.11."]
90
93
#[ inline]
91
94
pub fn translated ( & self , translation : Vector3 ) -> Self {
92
95
Self {
@@ -150,7 +153,7 @@ impl Transform {
150
153
/// Returns the rotated transform around the given axis by the given angle (in radians),
151
154
/// using matrix multiplication. The axis must be a normalized vector.
152
155
#[ inline]
153
- pub fn rotate ( & mut self , axis : Vector3 , phi : f32 ) {
156
+ fn rotate ( & mut self , axis : Vector3 , phi : f32 ) {
154
157
* self = self . rotated ( axis, phi) ;
155
158
}
156
159
@@ -196,8 +199,10 @@ impl Transform {
196
199
197
200
/// Translates the transform by the given offset, relative to
198
201
/// the transform's basis vectors.
202
+ ///
203
+ /// This method will be renamed to `translated` in gdnative 0.11
199
204
#[ inline]
200
- pub fn translated_withbasis ( & self , translation : Vector3 ) -> Self {
205
+ pub fn translated_global ( & self , translation : Vector3 ) -> Self {
201
206
let mut copy = * self ;
202
207
copy. translate_withbasis ( translation) ;
203
208
copy
@@ -224,15 +229,15 @@ impl Transform {
224
229
}
225
230
226
231
#[ inline]
227
- pub fn is_equal_approx ( & self , other : Transform ) -> bool {
232
+ pub fn is_equal_approx ( & self , other : & Transform ) -> bool {
228
233
self . basis . is_equal_approx ( & other. basis ) && self . origin . is_equal_approx ( other. origin )
229
234
}
230
235
231
236
/// Interpolates the transform to other Transform by
232
237
/// weight amount (on the range of 0.0 to 1.0).
233
238
/// Assuming the two transforms are located on a sphere surface.
234
239
#[ inline]
235
- pub fn sphere_interpolate_with ( & self , other : Transform , weight : f32 ) -> Self {
240
+ pub fn sphere_interpolate_with ( & self , other : & Transform , weight : f32 ) -> Self {
236
241
let src_scale = self . basis . scale ( ) ;
237
242
let src_rot = self . basis . to_quat ( ) ;
238
243
let src_loc = self . origin ;
@@ -252,9 +257,9 @@ impl Transform {
252
257
/// Interpolates the transform to other Transform by
253
258
/// weight amount (on the range of 0.0 to 1.0).
254
259
#[ inline]
255
- pub fn interpolate_with ( & self , other : Transform , weight : f32 ) -> Self {
260
+ pub fn interpolate_with ( & self , other : & Transform , weight : f32 ) -> Self {
256
261
Transform {
257
- basis : self . basis . lerp ( other. basis , weight) ,
262
+ basis : self . basis . lerp ( & other. basis , weight) ,
258
263
origin : self . origin . linear_interpolate ( other. origin , weight) ,
259
264
}
260
265
}
@@ -297,7 +302,7 @@ mod tests {
297
302
basis. c ( ) ,
298
303
Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
299
304
) ;
300
- t = t. translated_withbasis ( Vector3 :: new ( 0.5 , -1.0 , 0.25 ) ) ;
305
+ t = t. translated_global ( Vector3 :: new ( 0.5 , -1.0 , 0.25 ) ) ;
301
306
t = t. scaled ( Vector3 :: new ( 0.25 , 0.5 , 2.0 ) ) ;
302
307
303
308
let basis = Basis :: from_euler ( Vector3 :: new ( 12.23 , 50.46 , 93.94 ) ) ;
@@ -307,7 +312,7 @@ mod tests {
307
312
basis. c ( ) ,
308
313
Vector3 :: new ( 0.0 , 0.0 , 0.0 ) ,
309
314
) ;
310
- t2 = t2. translated_withbasis ( Vector3 :: new ( 1.5 , -2.0 , 1.25 ) ) ;
315
+ t2 = t2. translated_global ( Vector3 :: new ( 1.5 , -2.0 , 1.25 ) ) ;
311
316
t2 = t2. scaled ( Vector3 :: new ( 0.5 , 0.58 , 1.0 ) ) ;
312
317
// Godot reports:
313
318
// t = 0.019358, -0.041264, 0.24581, -0.144074, 0.470205, 0.090279, -1.908901, -0.594598, 0.050514 - 0.112395, -0.519672, -0.347224
@@ -348,7 +353,7 @@ mod tests {
348
353
Vector3 :: new ( -0.47722515 , -0.14864945 , 0.012628445 ) ,
349
354
Vector3 :: new ( -0.5 , 1.0 , -0.25 ) ,
350
355
) ;
351
- assert ! ( expected. is_equal_approx( t) )
356
+ assert ! ( expected. is_equal_approx( & t) )
352
357
}
353
358
354
359
#[ test]
@@ -363,7 +368,7 @@ mod tests {
363
368
Vector3 :: new ( 0.99580616 , 0.0914323 , 0.0031974507 ) ,
364
369
Vector3 :: new ( 0.11239518 , -0.519672 , -0.34722406 ) ,
365
370
) ;
366
- assert ! ( expected. is_equal_approx( t) )
371
+ assert ! ( expected. is_equal_approx( & t) )
367
372
}
368
373
369
374
#[ test]
@@ -374,14 +379,14 @@ mod tests {
374
379
// TODO: Get new godot result. https://github.com/godotengine/godot/commit/61759da5b35e44003ab3ffe3d4024dd611d17eff changed how Transform3D.linear_interpolate works
375
380
// For now assuming this is sane - examined the new implementation manually.
376
381
let ( t, t2) = test_inputs ( ) ;
377
- let result = t. interpolate_with ( t2, 0.5 ) ;
382
+ let result = t. interpolate_with ( & t2, 0.5 ) ;
378
383
let expected = Transform :: from_basis_origin (
379
384
Vector3 :: new ( 0.24826992 , -0.15496635 , -0.997503 ) ,
380
385
Vector3 :: new ( 0.038474888 , 0.49598676 , -0.4808879 ) ,
381
386
Vector3 :: new ( 0.16852 , 0.14085774 , 0.48833522 ) ,
382
387
Vector3 :: new ( 0.352889 , -0.786351 , 0.707835 ) ,
383
388
) ;
384
- assert ! ( expected. is_equal_approx( result) )
389
+ assert ! ( expected. is_equal_approx( & result) )
385
390
}
386
391
387
392
#[ test]
@@ -391,13 +396,13 @@ mod tests {
391
396
// t2 = 0.477182, 0.118214, 0.09123, -0.165859, 0.521769, 0.191437, -0.086105, -0.367178, 0.926157 - 0.593383, -1.05303, 1.762894
392
397
// result = 0.727909, -0.029075, 0.486138, -0.338385, 0.6514, 0.156468, -0.910002, -0.265481, 0.330678 - 0.352889, -0.786351, 0.707835
393
398
let ( t, t2) = test_inputs ( ) ;
394
- let result = t. sphere_interpolate_with ( t2, 0.5 ) ;
399
+ let result = t. sphere_interpolate_with ( & t2, 0.5 ) ;
395
400
let expected = Transform :: from_basis_origin (
396
401
Vector3 :: new ( 0.7279087 , -0.19632529 , -0.45626357 ) ,
397
402
Vector3 :: new ( -0.05011323 , 0.65140045 , -0.22942543 ) ,
398
403
Vector3 :: new ( 0.9695858 , 0.18105738 , 0.33067825 ) ,
399
404
Vector3 :: new ( 0.3528893 , -0.78635097 , 0.7078349 ) ,
400
405
) ;
401
- assert ! ( expected. is_equal_approx( result) )
406
+ assert ! ( expected. is_equal_approx( & result) )
402
407
}
403
408
}
0 commit comments