mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:08:55 +02:00
correct spatialization and off-axis attenuation for a spherical source
This commit is contained in:
parent
e07c55ec43
commit
c5d3365f3e
1 changed files with 15 additions and 13 deletions
|
@ -150,8 +150,8 @@ int main(int argc, const char* argv[]) {
|
|||
if (otherAgent != agent) {
|
||||
glm::vec3 listenerPosition = agentRingBuffer->getPosition();
|
||||
glm::vec3 relativePosition = otherAgentBuffer->getPosition() - agentRingBuffer->getPosition();
|
||||
glm::vec3 rotatedSourcePosition = glm::inverse(agentRingBuffer->getOrientation())
|
||||
* relativePosition;
|
||||
glm::quat inverseOrientation = glm::inverse(agentRingBuffer->getOrientation());
|
||||
glm::vec3 rotatedSourcePosition = inverseOrientation * relativePosition;
|
||||
|
||||
float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
|
||||
|
||||
|
@ -171,14 +171,25 @@ int main(int argc, const char* argv[]) {
|
|||
// and the position of the source by the radius to get the
|
||||
// closest point on the boundary of the sphere to the source
|
||||
|
||||
glm::vec3 closestPoint = glm::normalize(relativePosition) * otherAgentBuffer->getRadius();
|
||||
glm::vec3 closestPoint = glm::normalize(-relativePosition) * otherAgentBuffer->getRadius();
|
||||
|
||||
// for the other calculations the agent position is the closest point on the sphere
|
||||
rotatedSourcePosition = closestPoint;
|
||||
rotatedSourcePosition = inverseOrientation * -closestPoint;
|
||||
|
||||
// ovveride the distance to the agent with the distance to the point on the
|
||||
// boundary of the sphere
|
||||
distanceSquareToSource = glm::distance2(listenerPosition, closestPoint);
|
||||
|
||||
} else {
|
||||
// calculate the angle delivery
|
||||
glm::vec3 rotatedListenerPosition = glm::inverse(otherAgentBuffer->getOrientation())
|
||||
* relativePosition;
|
||||
|
||||
float angleOfDelivery = glm::angle(glm::vec3(0.0f, 0.0f, 1.0f),
|
||||
glm::normalize(rotatedListenerPosition));
|
||||
|
||||
offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION +
|
||||
(OFF_AXIS_ATTENUATION_FORMULA_STEP * (angleOfDelivery / 90.0f));
|
||||
}
|
||||
|
||||
const float DISTANCE_SCALE = 2.5f;
|
||||
|
@ -205,15 +216,6 @@ int main(int argc, const char* argv[]) {
|
|||
glm::normalize(rotatedSourcePosition),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// calculate the angle delivery
|
||||
glm::vec3 rotatedListenerPosition = glm::inverse(otherAgentBuffer->getOrientation())
|
||||
* relativePosition;
|
||||
|
||||
float angleOfDelivery = glm::angle(glm::vec3(0.0f, 0.0f, 1.0f),
|
||||
glm::normalize(rotatedListenerPosition));
|
||||
|
||||
offAxisCoefficient = MAX_OFF_AXIS_ATTENUATION
|
||||
+ (OFF_AXIS_ATTENUATION_FORMULA_STEP * (angleOfDelivery / 90.0f));
|
||||
|
||||
float sinRatio = fabsf(sinf(glm::radians(bearingRelativeAngleToSource)));
|
||||
numSamplesDelay = PHASE_DELAY_AT_90 * sinRatio;
|
||||
|
|
Loading…
Reference in a new issue