This commit is contained in:
blueloveTH 2024-05-13 16:20:51 +08:00
parent a09def4ec3
commit e19c2ccf96
4 changed files with 9 additions and 14 deletions

View File

@ -47,7 +47,7 @@ class vec2(_StructLike['vec2']):
""" """
@staticmethod @staticmethod
def smooth_damp(current: vec2, target: vec2, current_velocity_: vec2, smooth_time: float, max_speed: float, delta_time: float) -> vec2: def smooth_damp(current: vec2, target: vec2, current_velocity: vec2, smooth_time: float, max_speed: float, delta_time: float) -> tuple[vec2, vec2]:
... ...
class vec3(_StructLike['vec3']): class vec3(_StructLike['vec3']):

View File

@ -38,8 +38,11 @@ class vec2(_StructLike['vec2']):
""" """
@staticmethod @staticmethod
def smooth_damp(current: vec2, target: vec2, current_velocity_: vec2, smooth_time: float, max_speed: float, delta_time: float) -> vec2: def smooth_damp(current: vec2, target: vec2, current_velocity: vec2, smooth_time: float, max_speed: float, delta_time: float) -> tuple[vec2, vec2]:
... """Smoothly changes a vector towards a desired goal over time.
Returns a new value that is closer to the target and current velocity.
"""
class vec3(_StructLike['vec3']): class vec3(_StructLike['vec3']):
x: float x: float

View File

@ -130,12 +130,12 @@ static Vec2 SmoothDamp(Vec2 current, Vec2 target, Vec2& currentVelocity, float s
vm->bind(type, "smooth_damp(current: vec2, target: vec2, current_velocity_: vec2, smooth_time: float, max_speed: float, delta_time: float) -> vec2", [](VM* vm, ArgsView args){ vm->bind(type, "smooth_damp(current: vec2, target: vec2, current_velocity_: vec2, smooth_time: float, max_speed: float, delta_time: float) -> vec2", [](VM* vm, ArgsView args){
Vec2 current = CAST(Vec2, args[0]); Vec2 current = CAST(Vec2, args[0]);
Vec2 target = CAST(Vec2, args[1]); Vec2 target = CAST(Vec2, args[1]);
Vec2& current_velocity_ = CAST(Vec2&, args[2]); Vec2 current_velocity_ = CAST(Vec2, args[2]);
float smooth_time = CAST_F(args[3]); float smooth_time = CAST_F(args[3]);
float max_speed = CAST_F(args[4]); float max_speed = CAST_F(args[4]);
float delta_time = CAST_F(args[5]); float delta_time = CAST_F(args[5]);
Vec2 ret = SmoothDamp(current, target, current_velocity_, smooth_time, max_speed, delta_time); Vec2 ret = SmoothDamp(current, target, current_velocity_, smooth_time, max_speed, delta_time);
return VAR(ret); return VAR(Tuple(VAR(ret), VAR(current_velocity_)));
}, {}, BindType::STATICMETHOD); }, {}, BindType::STATICMETHOD);
// @staticmethod // @staticmethod

View File

@ -42,7 +42,7 @@ assert test_vec2.rotate(radians) == test_vec2_copy
# test smooth_damp # test smooth_damp
vel = vec2(0, 0) vel = vec2(0, 0)
ret = vec2.smooth_damp(vec2(1, 2), vec2(3, 4), vel, 0.2, 0.001, 0.05) ret, vel = vec2.smooth_damp(vec2(1, 2), vec2(3, 4), vel, 0.2, 0.001, 0.05)
assert isinstance(ret, vec2) assert isinstance(ret, vec2)
assert vel.length() > 0 assert vel.length() > 0
@ -463,14 +463,6 @@ assert mymat3x3().f()
# test assign # test assign
a = vec2(1, 2)
assert a.copy_(vec2(3, 4)) is None
assert a == vec2(3, 4)
b = vec3(1, 2, 3)
assert b.copy_(vec3(4, 5, 6)) is None
assert b == vec3(4, 5, 6)
c = vec4(1, 2, 3, 4) c = vec4(1, 2, 3, 4)
assert c.copy_(vec4(5, 6, 7, 8)) is None assert c.copy_(vec4(5, 6, 7, 8)) is None
assert c == vec4(5, 6, 7, 8) assert c == vec4(5, 6, 7, 8)