|
如题:
我想在场景中加入各种各样的鸟叫声以及瀑布等水的声音!每一种鸟叫声的声源位置是设置好了的!想法就是将某个声源绑定在一个特定的位置,当相机隔那个声源位置很远的时候是听不到声音的,当场景中的人物走到离声源位置很近的地方,也就是说相机隔声源靠近的时候,可以感觉这个声源的声音慢慢增大! 我在SoundState这个类中发现了setPosition这个函数,但是奇怪的是,不论我怎么设置这个坐标,声源依旧是处于某一个特定的地方,不知道那个位置是自动默认的还是??
我的程序中关于声音的设置代码如下:
// Create a new filestream that streams samples from a ogg-file.
osgAudio::FileStream *musicStream = new osgAudio::FileStream(file);
SoundState *musicSoundState = new SoundState("music");
// Associate the stream with the sound state
musicSoundState->setStream( musicStream );
// Create a named sound state.
//osg::ref_ptr<osgAudio::SoundState> sound_state = new osgAudio::SoundState("glider");
//// Let the soundstate use the sample we just created
//sound_state->setSample(sample);
// Set its gain (volume) to 0.9
musicSoundState->setGain(0.9f);
// Set its pitch to 1 (normal speed)
musicSoundState->setPitch(1);
// Make it play
musicSoundState->setPlay(true);
// The sound should loop over and over again
musicSoundState->setLooping(true);
musicSoundState->setAmbient(true);//设置声音是否衰减
musicSoundState->setRelative(false);//设置声音是否始终相对于listener
musicSoundState->setPosition(SOUND_POSITION);//SOUND_POSITION
//==osg::Vec3(-129.759f,-270.086f,17.6714f));
// Allocate a hardware soundsource to this soundstate (priority 10)
musicSoundState->allocateSource(10, false);
// At 70 the gain will be half of full!
musicSoundState->setReferenceDistance(70);
musicSoundState->setRolloffFactor(4);
musicSoundState->apply();
// Add the soundstate to the sound manager, so we can find it later on if we want to
osgAudio::SoundManager::instance()->addSoundState(musicSoundState);
目前主要的目的是想知道声源的位置是否可以设定,只有当相机靠近这个声源的时候才能听得到!如果可以设置的话,应该怎么设置??它的位置是世界坐标还是???还望各位指点一二!谢谢! |
|