]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_openal.cxx
Merge branch 'jmt/magvar' into next
[simgear.git] / simgear / sound / sample_openal.cxx
index 4be9d8113f02c9c068afd605e3c7926d58bded95..16291d7da918bd15dd51c35853710e86cf2e04ec 100644 (file)
@@ -31,7 +31,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/structure/exception.hxx>
 #include <simgear/misc/sg_path.hxx>
-#include <simgear/math/SGQuat.hxx>
+#include <simgear/math/SGMath.hxx>
 
 #include "soundmgr_openal.hxx"
 #include "sample_openal.hxx"
@@ -49,7 +49,8 @@ SGSoundSample::SGSoundSample() :
     _velocity(SGVec3f::zeros()),
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
-    _base_pos(SGGeod::fromDeg(0,0)),
+    _base_pos(SGVec3d::zeros()),
+    _rotation(SGQuatd::zeros()),
     _refname(random_string()),
     _data(NULL),
     _format(AL_FORMAT_MONO8),
@@ -83,7 +84,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) :
     _velocity(SGVec3f::zeros()),
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
-    _base_pos(SGGeod::fromDeg(0,0)),
+    _base_pos(SGVec3d::zeros()),
+    _rotation(SGQuatd::zeros()),
     _refname(file),
     _data(NULL),
     _format(AL_FORMAT_MONO8),
@@ -123,7 +125,8 @@ SGSoundSample::SGSoundSample( const unsigned char** data,
     _velocity(SGVec3f::zeros()),
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
-    _base_pos(SGGeod::fromDeg(0,0)),
+    _base_pos(SGVec3d::zeros()),
+    _rotation(SGQuatd::zeros()),
     _refname(random_string()),
     _format(format),
     _size(len),
@@ -158,7 +161,8 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
     _velocity(SGVec3f::zeros()),
     _orientation(SGQuatd::zeros()),
     _orivec(SGVec3f::zeros()),
-    _base_pos(SGGeod::fromDeg(0,0)),
+    _base_pos(SGVec3d::zeros()),
+    _rotation(SGQuatd::zeros()),
     _refname(random_string()),
     _format(format),
     _size(len),
@@ -188,33 +192,19 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) :
 
 // destructor
 SGSoundSample::~SGSoundSample() {
-    if (_data) free(_data);
+    if ( _data != NULL ) free(_data);
 }
 
 void SGSoundSample::update_pos_and_orientation() {
-    // The rotation rotating from the earth centerd frame to
-    // the horizontal local frame
-    SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos);
 
-    // Compute the sounds orientation and position
-    // wrt the earth centered frame - that is global coorinates
-    SGQuatd sc2body = hlOr*_orientation;
-
-    // This is rotates the x-forward, y-right, z-down coordinate system where
-    // simulation runs into the OpenGL camera system with x-right, y-up, z-back.
-    SGQuatd q(-0.5, -0.5, 0.5, 0.5);
-
-    // The cartesian position of the sounds base location
-    SGVec3d position = SGVec3d::fromGeod(_base_pos);
-
-    _absolute_pos = position;
-#if 0
-    if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
-        _absolute_pos += (sc2body*q).backTransform(_relative_pos);
+    _absolute_pos = _base_pos;
+    if (_relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) {
+       _absolute_pos += _rotation.rotate( _relative_pos );
     }
-#endif
+
+    _orivec = SGVec3f::zeros();
     if ( _direction[0] || _direction[1] || _direction[2] ) {
-        _orivec = toVec3f( (sc2body*q).backTransform(_direction) );
+        _orivec = toVec3f( _rotation.rotate( _direction ) );
     }
 }