Projecting a Sound (like a flashlight)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Gabumon
Posts: 10
Joined: Wed Feb 21, 2007 6:26 pm

Projecting a Sound (like a flashlight)

Post by Gabumon »

Hey All,

I am hoping someone can help me out with this.

I am trying to do this weird thing where, I am "projecting" a sound like a flashlight.

If I were holding a flashlight, whereever the "light" would hit a wall, there would be point where a sound emanates instead.

Now I am sure if I needed to project the sound from the center of the screen like a typical FPS, I wouldn't have a problem, but I need the sound to be projected from a point off center. Say screen coordinates 50, 50.

When I do that, the sound I hear seems to emanate from the correct spot against walls, as long as I am pointing AWAY from the origin [0,0,0].

But as I move away from the origin [using Irrlicht's FPS Camera] and turn to face it, the sound starts emanating from the opposite speaker it should be coming out of the screen.

I think this may be a vector/matrix4 translation/orienation problem, but I am a little weak on 3D math.

Does anyone have any suggestion on how I would correct this problem?


Below is the pertinent code.

Code: Select all

//This set irrKlang's ear's to match the camera.
engine->setListenerPosition( camera->getPosition(), camera->getTarget(), vector3df(0,0,0), camera->getUpVector() );

//The following is straight from the Collision tutorial, expect I am using getRayFromScreenCoordinates(), since the sound's projection from me is off center.
 _line = smgr->getSceneCollisionManager()->getRayFromScreenCoordinates( position2d<s32>( 50, 50 ), 0);

if (smgr->getSceneCollisionManager()->getCollisionPoint( line, selector, intersection, tri))
{
	bill->setPosition(intersection);
				
}


//Now it seems that reasonably the intersection of the billboard, would be that of the sound.   But like I said the sound only emanates from the correct location if I am pointing away from the Origin. 
_IRRsound->setPosition( intersection );

Any guesses?

Thanks in advance..

Staque
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You might want to have a look at the code I posted here a while back. It is a sound listener and a sound emitter scene node and some test code.

It looks like your code for placing the listener is wrong. The problem that you have is that you are passing a position vector instead of a direction vector as the second parameter to setListenerPosition(). You should also passing the relative position of the camera as the first parameter, which not always the world position. I think this would work better...

Code: Select all

core::vector3df forward(camera->getTarget() - camera->getAbsolutePosition());
forward.normalize();

core::vector3df upwards(camera->getUpVector());
// upwards.normalize();

core::vector3df velocity(0, 0, 0);

engine->setListenerPosition(camera->getAbsolutePosition(), forwards, velocity, upwards);
Travis
Gabumon
Posts: 10
Joined: Wed Feb 21, 2007 6:26 pm

BIG THANKS!!!

Post by Gabumon »

vitek

You are the best!!!

Thanks for the help!

Peace

Staque
Post Reply