diff options
| author | Jasper St. Pierre <jstpierre@mecheye.net> | 2023-09-30 16:59:17 -0700 |
|---|---|---|
| committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2023-09-30 16:59:17 -0700 |
| commit | c983ef2106cbbedea128471841ec2ed90a2a69ad (patch) | |
| tree | e9a68fa8ca048ef774d29453abfac74fe36b06af /include/JSystem/JGeometry.h | |
| parent | d06e54362d821eba80a7defb2d1eb7c17d11b1b5 (diff) | |
JPAMath start
Diffstat (limited to 'include/JSystem/JGeometry.h')
| -rw-r--r-- | include/JSystem/JGeometry.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index ac4857ec..a8afb2d5 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -151,10 +151,10 @@ struct TVec3<f32> { return C_VECSquareMag((Vec*)&x); } - void normalize() { + f32 normalize() { f32 sq = squared(); if (sq <= FLT_EPSILON * 32.0f) { - return; + return 0.0f; } f32 norm; if (sq <= 0.0f) { @@ -162,14 +162,15 @@ struct TVec3<f32> { } else { norm = fsqrt_step(sq); } - scale(norm); + scale(1.0f / norm); + return norm; } - void normalize(const TVec3<f32>& other) { + f32 normalize(const TVec3<f32>& other) { f32 sq = other.squared(); if (sq <= FLT_EPSILON * 32.0f) { zero(); - return; + return 0.0f; } f32 norm; if (sq <= 0.0f) { @@ -177,7 +178,8 @@ struct TVec3<f32> { } else { norm = fsqrt_step(sq); } - scale(norm, other); + scale(1.0f / norm, other); + return norm; } f32 length() const { @@ -249,7 +251,7 @@ struct TVec3<f32> { void cross(const TVec3<f32>& a, const TVec3<f32>& b) { VECCrossProduct(a, b, *this); } - + void setLength(f32 len) { f32 sq = squared(); if (sq <= FLT_EPSILON * 32.0f) { |
