Fmod listener position
Is it possible to have several sounds on different places in a 3D sound world in Fmod? I would like to plot up all the sounds in this 3D world and move around the player.
I am developing f开发者_运维百科or iPhone.
To place a channel or event in a 3D location use either Channel::set3DAttributes or Event::set3DAttributes, these functions take a 3D world position and a direction vector.
If you want to "walk" around the 3D world, you need to adjust the listener position with either System::set3DListenerAttributes or EventSystem::set3DListenerAttributes (depending on if you are using FMOD low level API or FMOD Event System API. These functions take a position vector, velocity vector, forward vector and up vector.
I recommend referring to the 3D example that ships with FMOD and checking fmodex.chm for more details about the above functions.
The following code allowed me to place several sounds that were made into events in Fmod Designer into a 3D world of Fmod:
FMOD_RESULT result = FMOD_OK;
FMOD_VECTOR listenerpos = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR eventpos = { 0.0f, 0.0f, 1.0f };
FMOD_VECTOR eventpos2 = { 0.0f, 0.0f, 1.0f };
float DISTANCEFACTOR = 2.0f;
Event 1 is one of the sounds I want to place in my 3D world:
result = group->getEvent("Event 1", FMOD_EVENT_DEFAULT, &event1);
ERRCHECK(result);
Event 2 is the other event I want to place in the same sounds landscape:
result = group->getEvent("Event 2", FMOD_EVENT_DEFAULT, &event2);
ERRCHECK(result);
I place the listener position in the middle of this world:
listenerpos.x = 0;
listenerpos.y = 0;
listenerpos.z = 0;
result = eventSystem->set3DListenerAttributes(0, &listenerpos,NULL,NULL,NULL);
ERRCHECK(result);
I set the position of one of the events to an object I move around on the iPhone screen:
eventpos.x = xPos;
eventpos.z = yPos;
result = event1->set3DAttributes(&eventpos,&vel);
ERRCHECK(result);
I set the other event to another position:
eventpos2.x = xPos2;
eventpos2.y = yPos2;
result = event2->set3DAttributes(&eventpos2,&vel);
ERRCHECK(result);
The entire event system and 3D world is updated with these positions:
result = eventSystem->update();
ERRCHECK(result);
I trigger the 2 events and hear how they move around the listener:
result = event1->start();
ERRCHECK(result);
result = event2->start();
ERRCHECK(result);
精彩评论