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

Function Pat_FaceTarget

src/SB/Game/zNPCTypeBossPatrick.cpp:2208–2259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2206}
2207
2208static S32 Pat_FaceTarget(zNPCBPatrick* pat, const xVec3* target, F32 turn_rate, F32 dt)
2209{
2210 S32 retval = -1;
2211 xVec3 newAt;
2212
2213 xVec3Sub(&newAt, target, (xVec3*)&pat->model->Mat->pos);
2214
2215 newAt.y = f832;
2216 F32 a = xVec3Normalize(&newAt, &newAt);
2217
2218 F32 currRot = xatan2(pat->model->Mat->at.x, pat->model->Mat->at.z);
2219 F32 desireRot = xatan2(newAt.x, newAt.z);
2220
2221 F32 diffRot = desireRot - currRot;
2222
2223 if (diffRot > f1140)
2224 {
2225 diffRot -= f1666;
2226 }
2227
2228 if (diffRot < f2405)
2229 {
2230 diffRot += f1666;
2231 }
2232
2233 F32 deltaRot = turn_rate * dt;
2234
2235 if ((F32)iabs(diffRot) < deltaRot)
2236 {
2237 pat->frame->mat.at = newAt;
2238 retval = 0;
2239 }
2240 else
2241 {
2242 if (diffRot < f832)
2243 {
2244 deltaRot = -deltaRot;
2245 retval = 1;
2246 }
2247
2248 desireRot = currRot + deltaRot;
2249 deltaRot = isin(currRot + deltaRot);
2250 pat->frame->mat.at.x = deltaRot;
2251 pat->frame->mat.at.y = f832;
2252 deltaRot = icos(desireRot);
2253 pat->frame->mat.at.z = deltaRot;
2254 }
2255
2256 xVec3Cross(&pat->frame->mat.right, &pat->frame->mat.up, &pat->frame->mat.at);
2257
2258 return retval;
2259}
2260
2261/*
2262 I think the multi-dimensional box array might be changed

Callers 1

ProcessMethod · 0.70

Calls 6

xVec3SubFunction · 0.85
xatan2Function · 0.85
isinFunction · 0.85
icosFunction · 0.85
xVec3CrossFunction · 0.85
xVec3NormalizeFunction · 0.50

Tested by

no test coverage detected