I’m struggling to understand how the VrAppState syncs the Listener (for audio positioning) with the HMD position.
A normal JME application uses AudioListenerState for this which syncs sound with camera position. This functionality seems to be missing for VR so we’ve been syncing the listener manually with VrAppState.getFinalObserverPosition()
.
This method crashes when no observer is set because it then tries to cast Camera into Spatial.
What is the purpose of the observer?
The javadoc says it will be linked to the HMD. But in which way? It seems to simply act as an offset to the VR camera position.
There is code that expects VREnvironment.getObserver()
to return NULL but that’s never gonna happen, leading to potential crashes.
I’d suggest to abstract away the distinction between Camera and Spatial behind an Observer class so a caller doesn’t have to care about the observer type, simplifying code like this which exists at various places:
Object obs = environment.getObserver();
if( obs instanceof Camera ) {
tempq.set(((Camera)obs).getRotation());
} else {
tempq.set(((Spatial)obs).getWorldRotation());
}
I’d like to refactor this a bit and add a VR equivalent to AudioListenerState. Can I?