• Create Account

# heading to position transform angle in C++

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

30 replies to this topic

### #21haegarr  Crossbones+   -  Reputation: 6999

Like
1Likes
Like

Posted 18 May 2012 - 12:32 PM

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.)

Edited by haegarr, 18 May 2012 - 12:42 PM.

### #22Álvaro  Crossbones+   -  Reputation: 18628

Like
0Likes
Like

Posted 18 May 2012 - 12:47 PM

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.

### #23 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 20 May 2012 - 02:30 AM

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 };

### #24Álvaro  Crossbones+   -  Reputation: 18628

Like
0Likes
Like

Posted 20 May 2012 - 05:45 AM

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.

### #25 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 20 May 2012 - 06:33 AM

No again, I cannot change given things. I can only use x,y,z and heading for source and listener.

### #26 abcdef44   Banned   -  Reputation: 2

Like
-2Likes
Like

Posted 21 May 2012 - 08:09 AM

deleted

Edited by mike4, 23 May 2012 - 04:03 AM.

### #27WarAmp  Members   -  Reputation: 750

Like
0Likes
Like

Posted 22 May 2012 - 06:03 PM

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.

### #28 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 23 May 2012 - 12:02 AM

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.

### #29 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 23 May 2012 - 01:08 AM

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?

Edited by mike4, 23 May 2012 - 04:03 AM.

### #30 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 23 May 2012 - 05:44 AM

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

Edited by mike4, 23 May 2012 - 05:51 AM.

### #31rip-off  Moderators   -  Reputation: 10520

Like
0Likes
Like

Posted 23 May 2012 - 07:15 AM

Ok, now what you are saying is making a little more sense to me. You have an object that has two logical sound sources, one at the front and one at the back. You are trying to take the position of the object's origin, and do the appropriate maths to discover the world-space co-ordinates of these sound sources.

The remaining question is what is pPsi? It is the angle around the Y axis perhaps? I assume it is in radians? Do you derive this angle from a heading vector, or do you use this angle to move the object? In the former case, try adding the vector that is V * L + P, where P is the position of the object, V is the normalised heading vector and L is the distance from the origin to the sound emitter. In the latter case, your code to move the object is similar to the code needed for this.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS