In my game the position data is in the range -2147483647 to 2147483647.
The X axis is left-right, increasing as I move right.
The Y axis is forward-back, inreasing as i move forward.
The Z axis is up-down, increasing as I move up.
I’m having difficulties translating this coordinate system to proper FMOD_VECTOR values for setting event 3D attributes.
As I have come to understand, FMOD has a left handed coordinate system, which leads me to conclude that I have to set my FMOD coordinates this way:
fmodVector.pos.x = (float)player.pos->x;
fmodVector.pos.y = (float)player.pos->z;
fmodVector.pos.z = (float)player.pos->y;
Interchanging the Z and Y axis. Now the fmod coordinates should be:
x axis: +right
y axis: +up
z axis: +forward
Am I right so far?
Now, I want to convert these coordinates to a forward vector to use as forward argument when setting 3D attributes for listener.
How can i achieve this?
- gummipekk asked 8 years ago
Oopps, forget that i have the rotation also in the same range as the translation axes, -2147483647 to 2147483647. I convert this to angle in degrees and is facing 90 degrees when making the obeservations regarding the coordinate system.
I convert this angle to a forward vector:
fmodVector.forward.x = cos(((float)player.angle / 4294967294.0f) * 3.14159265f);
fmodVector.forward.z = sin(((float)player.angle / 4294967294.0f) * 3.14159265f);
fmodVector.forward.y = 0.0f;
But this doesn’t sound right.
What am I doing wrong here?
- gummipekk answered 8 years ago
What is the range in degree of your angle? Is it -180 to 180 or -360 to -360 or…? I assume the former?
If you want to convert degrees to radians you need to divide by 180 and multiply by PI. If you are -180 to 180 then you are essentially dividing by 360.
Also, do you think of your angle as being degrees from Y (i.e. degrees from forward)? Like is something "facing forward" an angle of 0? If so then you’ll be fine. If it’s degrees from X then you’ll need to add or subtract 90 degrees before you do the sin/cos.
Couple more more small things. First, on consoles (not so much PC), integer to float conversions can be pretty expensive. If you see this sort of thing happening a lot, it’s something to keep in mind. Second, aside from fiddly precision issues, (X/Y)Z == (XZ)/Y. You can save a divide by rewriting that:
[code:rxbj2xhn]cos(((float)player.angle * (3.14159265f/4294967294.0f)); // Compiler will auto collapse the right term into a single costant. [/code:rxbj2xhn]
- audiodev answered 8 years ago
You can use FMOD_INIT_3D_RIGHTHANDED to make FMOD run as right handed.
Seperating the angle into a seperate variable will probably make it easier to debug (and offer a small performance gain).
float angleRadians = player.angle * (3.14159265f/4294967294.0f);
assert(0.f <= angleRadians && angleRadians <= 3.14159265f);
- Guest answered 8 years ago
Please login first to submit.