• 9
• 10
• 9
• 10
• 10

heading to position transform angle in C++

This topic is 2159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi
how to transform a normal heading angle in degrees:

0
|
360

to what I want:

180
| |
0
| |
-180

Something alike:
if angle > 180
...
but I cannot figure it. I need to avoid the gap between 0 to 360 for a smooth 3D sound.
Many thanks
Michael

Share on other sites
Can you explain what you are trying to do?

Share on other sites
i get values from 0 - 360 but want to have a second value following that: 0 - 180 - 0 - -180

But maybe I should try fmod and omit 0 returns, for my sound listener positions?

Share on other sites
double convert_0_360_angle_to_m180_180(double angle) { return angle < 180 ? angle : angle - 360; }

But now you have a gap at 180. If you were to really explain what your problem is, I am sure we could find a solution (which probably doesn't even involve using angles).

Share on other sites
That's exactly what I try to avoid. This is the sound source position, hence having a gap, for ex. 0 - 360 disrupts sound. No more nice fading in or out depending on listener position.
I've to use/manipulate a degrees 0-360 for the sound source. I've two sounds, one in front and one behind. the one behind is close to 360 hence not usable resulting in sound disruption.
heading is the value which changes 0-360 as the sound object rotates.
Many thanks
PS: a gap at 180 might be ok, I'll try that now and report back. Edited by mike4

Share on other sites
No luck, I've already tried something similar.

I have values camera: y,z,y and heading
and for sound source the same. Both change depending on viewer or source location/heading. Probably
I'm doing something completely wrong?

Share on other sites
What exactly do you do with those headings? Ultimately, the only things that should matter are the sine and cosine of those angles, and those don't have any discontinuities.

Share on other sites
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.

Could you tell me how to use sine/cosine with those values?
Many thanks indeed.

Share on other sites
Wait, you are dividing the heading by 10? Of course that will have trouble with discontinuities!

But, why are you setting the coordinates of AL_POSITION to some angle? That makes no sense at all. Edited by alvaro