How is 3d positional data supposed to be set/assigned?

Note that I am using a right handed coordinate system.
When looking down the positive Z axis, left is +X and right is -X

I have initialized the FMOD system with the right handed coordinates.

FMOD::Studio::System::create(&m_PtrFMODStudioSystem);
FMOD_RESULT result = m_PtrFMODStudioSystem->initialize(32, //# Channels
													FMOD_STUDIO_INIT_NORMAL,
													FMOD_INIT_3D_RIGHTHANDED,
													nullptr);

This is how I was building my FMOD_3D_ATTRIBUTES struct

FMOD_3D_ATTRIBUTES attr;
auto camForward = pCamera->GetForwardVector();
auto camUp = pCamera->GetUpVector();
attr.forward = FMOD_VECTOR(camForward.x, camForward.y, camForward.z);
attr.up = FMOD_VECTOR(camUp.x, camUp.y, camUp.z);
auto camPos = pCamera->GetPosition();
auto entityPos = pEntity->GetPosition();
auto soundPos = entityPos - camPos;
attr.position = FMOD_VECTOR(soundPos.x, soundPos.y, soundPos.z);

so my position would be entityPos - cameraPos
the forward vector = camera’s forward vector
up vector = camera’s up vector
not using velocity atm

Here is a video of what I am seeing and at the top left after the sound is created there are numbers for what i’m using on all the current variables.

What am I doing wrong here?

Just to add…
I found with the following code, it seems to give me the sound like i’d expect, but I don’t understand why.

FMOD_3D_ATTRIBUTES attr;
auto camInverseMatrix = pCamera->GetWorldMatrix().Invert();
auto entityPos = pEntity->GetPosition();
Math::Float3 finalPos = DirectX::XMVector3TransformCoord(entityPos.ToSIMD(), camInverseMatrix);

attr.forward = FMOD_VECTOR(0, 0, 1);
attr.up = FMOD_VECTOR(0, 1, 0);
attr.position = FMOD_VECTOR(finalPos.x, finalPos.y, finalPos.z);
auto result = pInstanceEntry->pInstance->set3DAttributes(&attr);

Should I always just assume the listener is at 0,0,0 facing 0, 0, 1 with an up of 0, 1, 0 and use the inverse matrix of my camera to find the position to be passed in?

Hi,

As noted in the documentation for FMOD_3D_ATTRIBUTES, FMOD will interpret position as a position in world space, i.e. absolute. The forward and up vectors are used to represent the orientation of the given listener or event instance.

Correct me if I’m wrong, but I’m interpreting your first code snippet as setting the 3D attributes of your truck sound event instance - providing local/relative coordinates for any of these arguments, or the camera/listener forward and up vectors as 3D attributes for an event instance, could definitely cause the issue you observed. The second code snippet works as it provides the world-space position of your event instance, and doesn’t set the event instance’s orientation to match the listener.

If you require any further clarification, please let me know.

1 Like

Thanks,

I was missing the listener part which was causing the root issues. It’s working as expected now.

1 Like