MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FixAtan2

Function FixAtan2

fix/fix.cpp:220–247  ·  view source on GitHub ↗

given cos & sin of an angle, return that angle. parms need not be normalized, that is, the ratio of the parms cos/sin must equal the ratio of the actual cos & sin for the result angle, but the parms need not be the actual cos & sin. NOTE: this is different from the standard C atan2, since it is left-handed.

Source from the content-addressed store, hash-verified

218// need not be the actual cos & sin.
219// NOTE: this is different from the standard C atan2, since it is left-handed.
220angle FixAtan2(float cos, float sin) {
221 float q, m;
222 angle t;
223
224 // find smaller of two
225
226 q = (sin * sin) + (cos * cos);
227
228 m = std::sqrt(q);
229
230 if (m == 0)
231 return 0;
232
233 if (std::fabs(sin) < std::fabs(cos)) {
234 // sin is smaller, use arcsin
235 t = FixAsin(sin / m);
236 if (cos < 0)
237 t = 0x8000 - t;
238
239 return t;
240 } else {
241 t = FixAcos(cos / m);
242 if (sin < 0)
243 t = F1_0 - t;
244
245 return t;
246 }
247}
248
249// Does a ceiling operation on a fixed number
250fix FixCeil(fix num) {

Callers 1

Calls 2

FixAsinFunction · 0.70
FixAcosFunction · 0.70

Tested by

no test coverage detected