On 11/01/2009 06:28 PM, Erik Hofman wrote: > > At this time I've tried about everything to get the listener orientation > aligned properly. What's needed it converting the ViewOrientation matrix > (quaternation) and/or ViewOrientationOffset matrix (quaternation) to > align with OpenGL and get the look-at and look-up vector from it. > the look-at vector should match the OpenGL view vector and the up-vector > is the perpendicular vector pointing out of the top of the listeners head. > > It looks like I'm really close (for testing I've commented out some > position offset and velocity vector code) but to me it's not yet 100% > right, as if I'm missing something. I would really appreciate it if > someone who knows his way around this could take a look at > SGSoundManager::update_pos_and_orientation() in > SimGear/simgear/sound/soundmgr_openal.cxx > View related values are set in FlightGear/src/Main/viewmgr.cxx: both > recalcLookFrom() anf recalcLookAt() Assuming you want the orientation and position of the listener, and the positions of the sources, to match those in the visual world, you should just use the absolute position and orientation in the corresponding FGViewer object i.e., what you get from FGViewer::getViewPosition() and FGViewer::getViewOrientation(). You don't need to worry about the local reference frame, view position and orientation offsets, or the rotation between OpenGL and aerospace coordinates; that is all included in those position and orientation values. Then the vectors you need for the OpenAL orientation are:
SGVec3d lookAt = viewOrientation.back_transform(-SGVec3d::ec3); SGVec3d lookUp = viewOrientation.back_transform(SGVec3d::ec2); Now, there's a problem with using Cartesian coordinates directly: a single precision float doesn't have enough precision to represent positions near the earth's surface to better than a few meters. This is likely to be an issue for sound sources near the listener, like cockpit sounds and engine noises. So, the simplest coordinate system to use has its origin at the listener's position, but is oriented with the global Cartesian system. The position you set in OpenAL for the sound sources would just be the relative position of the source with respect to the listener i.e., sourcePos - listenerPos. While setting the listener position and orientation and source positions is simple, you will need to transform the velocities of the listener and sources from the local earth frame to the global Cartesian frame. Looking at src/Model/acmodel.cxx, you have a velocity in the local frame as (speed_north, speed_east, speed_down) in feet per second. To transform that to the global frame: SGQuatd hlOr = SGQuatd::fromLonLat(_position); SGVec3d globalVelocity = hlOr.back_transform(localVelocity*SG_FEET_TO_METER); If you can point me to the code where you calculate the positions of local sources from the model, I'll take a look at that too. Hope this helps, Tim ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel