From 1acd6f1a9778c1fc7153bf81a51f0006e1871f72 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 20 Jan 2024 10:44:36 -0800 Subject: [PATCH] c_m3d work --- include/SSystem/SComponent/c_m3d.h | 1 - src/SSystem/SComponent/c_m3d.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/SSystem/SComponent/c_m3d.h b/include/SSystem/SComponent/c_m3d.h index 959768a57..584354b9b 100644 --- a/include/SSystem/SComponent/c_m3d.h +++ b/include/SSystem/SComponent/c_m3d.h @@ -23,7 +23,6 @@ extern f32 G_CM3D_F_ABS_MIN; void cM3d_InDivPos1(const Vec*, const Vec*, f32, Vec*); void cM3d_InDivPos2(const Vec*, const Vec*, f32, Vec*); -f32 cM3d_Len2dSq(f32, f32, f32, f32); bool cM3d_Len2dSqPntAndSegLine(f32, f32, f32, f32, f32, f32, f32*, f32*, f32*); bool cM3d_Len3dSqPntAndSegLine(const cM3dGLin*, const Vec*, Vec*, f32*); f32 cM3d_SignedLenPlaAndPos(const cM3dGPla*, const Vec*); diff --git a/src/SSystem/SComponent/c_m3d.cpp b/src/SSystem/SComponent/c_m3d.cpp index 908aeacc8..468646766 100644 --- a/src/SSystem/SComponent/c_m3d.cpp +++ b/src/SSystem/SComponent/c_m3d.cpp @@ -58,9 +58,33 @@ void cM3d_InDivPos2(const Vec* v0, const Vec* v1, f32 scale, Vec* pDst) { cM3d_InDivPos1(v0, &tmp, scale, pDst); } +inline f32 cM3d_Len2dSq(f32 x0, f32 y0, f32 x1, f32 y1) { + f32 x = x0 - x1; + f32 y = y0 - y1; + return x*x + y*y; +} + /* 8024A4B4-8024A56C .text cM3d_Len2dSqPntAndSegLine__FffffffPfPfPf */ -bool cM3d_Len2dSqPntAndSegLine(f32, f32, f32, f32, f32, f32, f32*, f32*, f32*) { +bool cM3d_Len2dSqPntAndSegLine(f32 xp, f32 yp, f32 x0, f32 y0, f32 x1, f32 y1, f32* outx, f32* outy, f32* seg) { /* Nonmatching */ + bool ret = false; + f32 xd = x1 - x0; + f32 yd = y1 - y0; + f32 dot = (xd*xd + yd*yd); + if (cM3d_IsZero(dot)) { + *seg = 0.0f; + return ret; + } + + f32 t = (x1 * (xp - x0) + y1 * (yp - y0)) / dot; + if (t >= 0.0f && t <= 1.0f) { + ret = true; + } + + *outx = x0 + xd * t; + *outy = y0 + yd * t; + *seg = cM3d_Len2dSq(*outx, *outy, xp, yp); + return ret; } /* 8024A56C-8024A670 .text cM3d_Len3dSqPntAndSegLine__FPC8cM3dGLinPC3VecP3VecPf */