Tuesday, April 22, 2014

"Sonar"


Sonar

This “Sonar” functionality allows users to test distances to the nearest objects. This helps users determine their distance from important objects. This function mimics the use of reverberation to calculate the proximity of objects. In the virtual world, we can convey this information even when the object is very far away.

Use case:

User is navigating room, attempting to follow wall. The user loses track of wall on right-hand side. The user continues navigating but becomes lost. The user suspects that they are moving towards the North wall, which is where the exit is. They query around themselves but no objects are within range. The user tries to find the wall by sending a “sonar” signal forward. After a short delay, they hear a “knock” coming back from the front. From experience, they associate this “knock” with an interior wall. The user estimates their distance from the wall based on the length of the delay. Comfortable that they have made progress towards the north wall, the user continues until they reach the wall, takes a right turn, and follows the wall to the exit.

Calculating Delay

Calculating the sound delay is a simple matter of determining the distance between the user and the object and accounting for the speed of sound. Where a and b are 3D points representing user and object positions:


        double dist = Math.sqrt( Math.pow((a.x - b.x ), 2) + Math.pow((a.y - b.y), 2) +                    Math.pow((a.z - b.z), 2) );;

        double delayAsSeconds = dist/speedOfSound * 2;
        double delayAsMilliseconds = delayAsSeconds * 1000;


The play thread is then qued with the appropriate delay and sound. The sound is always the one associated with the relevant object.

No comments:

Post a Comment