Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
30 replies to this topic

#1 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 13 May 2012 - 05:40 AM

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

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 13 May 2012 - 07:08 AM

Can you explain what you are trying to do?

#3 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 13 May 2012 - 09:14 AM

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?

#4 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 13 May 2012 - 02:56 PM

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

#5 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 14 May 2012 - 01:34 AM

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.
alSource3f(Sources[2], AL_POSITION, heading/10, lY/10, lZ/10);
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, 14 May 2012 - 01:35 AM.


#6 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 14 May 2012 - 01:51 AM

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?

#7 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 14 May 2012 - 02:56 AM

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.

#8 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 14 May 2012 - 03:41 AM

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.

#9 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 14 May 2012 - 07:38 AM

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, 18 May 2012 - 12:49 PM.


#10 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 14 May 2012 - 11:24 AM

I did that a long time ago. As far as I remember, only setting x,y,z is not taking in account the airplane movement, hence I did that ugly handicraft. I'll try tomorrow and
get back.

#11 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 15 May 2012 - 02:04 AM

Yes seems so. Could you tell me how to use cos or sin with the heading value?
Many thanks

#12 Álvaro   Crossbones+   -  Reputation: 13912

Like
0Likes
Like

Posted 15 May 2012 - 06:45 AM

No, I can't. I have no idea what you are trying to do.

#13 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 16 May 2012 - 12:57 AM

Hmm, if I would know it much better I'd not need to ask. Narrowed down the problem to, as I said, Sound is not hearable when heading jumps from 360 to 0 degrees.
So I need a way to avoid this gap and get 360-359-358 etc. The solution is probably something very simple...

#14 WarAmp   Members   -  Reputation: 750

Like
1Likes
Like

Posted 16 May 2012 - 12:40 PM

If you are just trying to transform [0, 360] to [180, -180] then just:

newAngle = 180 - angle;

But what would really help us help you is some context. We can sort of see that you are having a problem with OpenAL, but other than just saying 'Not hearable at certain angles' we have no idea what you are doing vs. what the result is you are trying to achieve. Maybe even draw us some pictures to illustrate the problem?

Spend some time explaining the situation and we can spend more time trying to help. The more information you give us, the more we have to work with.
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.

#15 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 18 May 2012 - 03:18 AM

Thanks but it seems that I need 0-360-0 in other words: ... 359 - 360 - 359 - 358 ...
Currently I get ... 359 - 360 - 0 - 1 ...which I cannot use.
So if 0 +=359, if 1 +=357, if 2 +=355, if 3 += 353 etc. while < 180
Any forumula for that?
Many thanks

#16 Brother Bob   Moderators   -  Reputation: 8606

Like
0Likes
Like

Posted 18 May 2012 - 03:46 AM

In the first post, your question was to map the range 0 to 360 to the range 180 to 0 to -180. In your second post, you now mention the mapping from the range 0 to 360 to the range 0 to 180 to 0 to -180 instead. And now you've mentioned the mapping to the range 0 to 360 to 0 as well.

It sounds very much like you don't know what you want, becuase your question has changed for every answer and follow-up question. Take alvaro's advice and don't ask how to map numbers from one range to another. Instead, describe the problem so that we know what it is you want in the first place.

Edited by Brother Bob, 18 May 2012 - 03:47 AM.


#17 abcdef44   Banned   -  Reputation: 2

Like
-1Likes
Like

Posted 18 May 2012 - 06:10 AM

So what...apparently 0-180- doesn't work, hence I need a solution as posted above.

I tried to change both listener and source to:
newAngle = 180 - angle;
and I don't know why it's not working for now. I still get sound interruptions. Back to:
So if 0 +=359, if 1 +=357, if 2 +=355, if 3 += 353 etc. while < 180
Any forumula for that?

#18 Waterlimon   Crossbones+   -  Reputation: 2639

Like
-1Likes
Like

Posted 18 May 2012 - 06:28 AM

Do you mean you have the angle of the sound (0-360) relative to the camera, but you want to convert it to how many degrees it is from the "directly in front" direction? so if its 90 degrees, it could be 90 degrees to the left or right?

Or what?

o3o


#19 rip-off   Moderators   -  Reputation: 8728

Like
0Likes
Like

Posted 18 May 2012 - 07:36 AM

You are in too deep with your current implementation, and it makes luttle sense to someone who isn't in your headspace right now.

Forget about angles for a minute. Talk about the high level goal first, then start talking about how you are currently implementing it.

Talk about concrete domain objects first. So you might have a player, who is a beekeeper, and you have some bees buzzing around, and you want the sound to reflect where the bees are. Then start telling this how you're making angles or whatnot, and we can (probably) tell you a way to do this without angles.

Edited by rip-off, 18 May 2012 - 07:37 AM.


#20 abcdef44   Banned   -  Reputation: 2

Like
0Likes
Like

Posted 18 May 2012 - 09:44 AM

waterlimon. I've given from the gameengine the listener and source positions (x,y,z) and headings in degrees as I said before. Now I only give those positions to listener and sound source and only change the source heading. One in front and one behind. All fine and working only when source heading flips from 360 - 0 sound no longer nicely in-/decreases depending on the listener but is suddenly gone.
Listener and airplane are moving in all directions, hence it's probably the cheapest solution to close the gap 360 - 0 as above. But maybe it can be done much nicer? This
is an old hack which even myself am hard to understand it's logic. I'll go through the code tomorrow again. The listener heading is always towards the airplane, only the airplane rotates.




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