Added moveToward for vectors.
This commit is contained in:
parent
f25c3c7a5d
commit
388bea9205
2 changed files with 24 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ import math, godotbase, hashes
|
|||
import internal/godotinternaltypes, internal/godotstrings
|
||||
import godotcoretypes, gdnativeapi
|
||||
|
||||
const EPSILON = 0.00001'f32
|
||||
|
||||
{.push stackTrace: off.}
|
||||
|
||||
proc vec2*(): Vector2 {.inline, noinit.} =
|
||||
|
|
@ -199,4 +201,14 @@ proc clamped*(self: Vector2; length: float32): Vector2 {.noinit.} =
|
|||
result /= len
|
||||
result *= length
|
||||
|
||||
proc moveToward*(vFrom, to: Vector2, delta: float32): Vector2 =
|
||||
let
|
||||
vd = to - vFrom
|
||||
vLen = vd.length
|
||||
|
||||
if vLen <= delta or vLen < EPSILON:
|
||||
result = to
|
||||
else:
|
||||
result = vFrom + (vd / vLen) * delta
|
||||
|
||||
{.pop.} # stackTrace: off
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
import math, hashes
|
||||
import godotbase, godotcoretypes
|
||||
|
||||
const EPSILON = 0.00001'f32
|
||||
|
||||
{.push stackTrace: off.}
|
||||
|
||||
proc vec3*(): Vector3 {.inline.} =
|
||||
|
|
@ -239,4 +241,14 @@ proc cubicInterpolate*(self, b, preA, postB: Vector3;
|
|||
(2.0 * p0 - 5.0 * p1 + 4 * p2 - p3) * t2 +
|
||||
(-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t3)
|
||||
|
||||
proc moveToward*(vFrom, to: Vector3, delta: float32): Vector3 =
|
||||
let
|
||||
vd = to - vFrom
|
||||
vLen = vd.length
|
||||
|
||||
if vLen <= delta or vLen < EPSILON:
|
||||
result = to
|
||||
else:
|
||||
result = vFrom + (vd / vLen) * delta
|
||||
|
||||
{.pop.} # stackTrace: off
|
||||
Loading…
Add table
Add a link
Reference in a new issue