| 332 | } |
| 333 | |
| 334 | void PannerNode::getAzimuthElevation(ContextRenderLock & r, double * outAzimuth, double * outElevation) |
| 335 | { |
| 336 | // FIXME: we should cache azimuth and elevation (if possible), so we only re-calculate if a change has been made. |
| 337 | |
| 338 | double azimuth = 0.0; |
| 339 | |
| 340 | auto listener = r.context()->listener(); |
| 341 | |
| 342 | // Calculate the source-listener vector |
| 343 | /// @fixme these values should be per sample, not per quantum |
| 344 | FloatPoint3D listenerPosition = { |
| 345 | listener->positionX()->value(), |
| 346 | listener->positionY()->value(), |
| 347 | listener->positionZ()->value()}; |
| 348 | |
| 349 | /// @fixme these values should be per sample, not per quantum |
| 350 | FloatPoint3D sourceListener = { |
| 351 | positionX()->value(), |
| 352 | positionY()->value(), |
| 353 | positionZ()->value()}; |
| 354 | |
| 355 | sourceListener = normalize(sourceListener - listenerPosition); |
| 356 | |
| 357 | if (is_zero(sourceListener)) |
| 358 | { |
| 359 | // degenerate case if source and listener are at the same point |
| 360 | *outAzimuth = 0.0; |
| 361 | *outElevation = 0.0; |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | // Align axes |
| 366 | /// @fixme these values should be per sample, not per quantum |
| 367 | FloatPoint3D listenerFront = normalize(FloatPoint3D{ |
| 368 | listener->forwardX()->value(), |
| 369 | listener->forwardY()->value(), |
| 370 | listener->forwardZ()->value()}); |
| 371 | |
| 372 | /// @fixme these values should be per sample, not per quantum |
| 373 | FloatPoint3D listenerUp = { |
| 374 | listener->upX()->value(), |
| 375 | listener->upY()->value(), |
| 376 | listener->upZ()->value()}; |
| 377 | |
| 378 | FloatPoint3D listenerRight = normalize(cross(listenerFront, listenerUp)); |
| 379 | FloatPoint3D up = cross(listenerRight, listenerFront); |
| 380 | |
| 381 | float upProjection = dot(sourceListener, up); |
| 382 | |
| 383 | FloatPoint3D projectedSource = normalize(sourceListener - upProjection * up); |
| 384 | |
| 385 | azimuth = 180.0 * acos(dot(projectedSource, listenerRight)) / static_cast<double>(LAB_PI); |
| 386 | fixNANs(azimuth); // avoid illegal values |
| 387 | |
| 388 | // Source in front or behind the listener |
| 389 | double frontBack = dot(projectedSource, listenerFront); |
| 390 | if (frontBack < 0.0) |
| 391 | azimuth = 360.0 - azimuth; |
nothing calls this directly
no test coverage detected