MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / FindNearestPointOnLine

Function FindNearestPointOnLine

src/SB/Core/gc/iCollide.cpp:114–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114void FindNearestPointOnLine(xVec3* _result, xVec3* _point, xVec3* _start, xVec3* _end)
115{
116 RwV3d localResult;
117 RwV3d* result = (RwV3d*)_result;
118 RwV3d* point = (RwV3d*)_point;
119 RwV3d* start = (RwV3d*)_start;
120 RwV3d* end = (RwV3d*)_end;
121
122 float mu;
123 float lineLength2;
124
125 mu = (point->x * (end->x - start->x) + point->y * (end->y - start->y) +
126 point->z * (end->z - start->z)) -
127 (start->x * (end->x - start->x) + start->y * (end->y - start->y) +
128 start->z * (end->z - start->z));
129 if (mu <= 0.0f)
130 {
131 localResult = *start;
132 }
133 else
134 {
135 lineLength2 = SQR(end->x - start->x) + SQR(end->y - start->y) + SQR(end->z - start->z);
136 if (mu < lineLength2)
137 {
138 mu /= lineLength2;
139 localResult.x = mu * (end->x - start->x);
140 localResult.x += start->x;
141 localResult.y = mu * (end->y - start->y);
142 localResult.y += start->y;
143 localResult.z = mu * (end->z - start->z);
144 localResult.z += start->z;
145 }
146 else
147 {
148 localResult = *end;
149 }
150 }
151 *result = localResult;
152}
153
154static void properSphereIsectTri(const xVec3* center, F32 radius, xVec3* tohit, F32* dist_ptr,
155 RpCollisionTriangle* tri)

Callers 1

properSphereIsectTriFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected