heading to position transform angle in C++

Started by
29 comments, last by rip-off 11 years, 11 months ago
Errr ...

Yes, for now I only do alike also for the listener:
alListener3f(AL_POSITION, cH/10,cY/10,(lZ/10)+disX);
cH is the heading degree and disX the distance.


You are setting an angle as the value of a position component! That means that your listener wanders around and suddenly jumps in space in dependence on an orientation. That is definitely a mistake.

Set the AL_POSITION like the camera's position (or like the object's position in case of the source), and set the AL_ORIENTATION using sine and cosine on the heading to compute a direction vector from the angle(s).

(If you want an attenuation effect that is not given by the normal operation of AL then try some volume computation but don't try to misuse the position for that because it will not work properly.)
Advertisement
Four days ago, in post #9 of this thread, I already told him that using angles as values for AL_POSITION makes no sense, but I think he ignored me.
Thanks. How would that look using sin/cos of the heading degrees?

// Orientation of the listener. (first 3 elements are "at", 3 are "up")
ALfloat ListenerOri[] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 };
Reread rip-off's comment #19 in this thread until it makes sense. Then please don't ask again until you can give us the kind of description of the situation that is required.
No again, I cannot change given things. I can only use x,y,z and heading for source and listener.
deleted
Ok Mike4, one more time:

What are you trying to do? There seems to be a language barrier issue here, perhaps describe your problem in your native language, and another poster can help you that way?


I can only use x,y,z and heading for source and listener.


What do you mean by this? Are you saying that you have the location and heading angle of both the Source AND the Listener? If that's the case, you would use alListener3f with AL_POSITION to set the x,y,z and then use a separate call to alListener3f with AL_ORIENTATION to set the orientation. A quick google search will tell you how to use the given heading with alListener to create the 'at' and 'up' vectors you need.

If you only have partial information about the listener/source then please tell us explicitly the information you have.
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
Thanks, where? I only found examples using static alike:
ALfloat listenerOri[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f };

That's what I'm doing as well. If that's correct my x,y,z positions must be wrong. I don't remember why I used heading as above nor why this even works mostly.
Hmm I need to get the source heading 0-360 into openal. Any links, thanks.
Yes confirmed. If I only put source and listener x,y,z positions sound doesn't change when source rotates. So listener is ok but source heading needs to get in. I have two sounds, one in front and one in the back of the rotating object.

Hmm I'll try to use glrotate...maybe this should do the job without diving into maths?
No luck with glrotate even this doesn' work:

float VerX = (cos(pPsi) * lX+5) + (sin(pPsi) * lZ);
float VerY = lY;
float VerZ = -(sin(pPsi) * lX+5) + (cos(pPsi) * lZ);

alSource3f(Sources[1], AL_POSITION, VerX, VerY, VerZ);

lX etc. are the local points. pPsi is the heading. lX+5 is the front sound? I simply want to put that before the back sound.
Thanks to get this finally working.

PS: Probably, as stated before, cheapest would be a formula for:
if 0 +=359, if 1 +=357, if 2 +=355, if 3 += 353 etc. while < 180

This topic is closed to new replies.

Advertisement