   rotate sounds in openAL
  HiI've one local_x,local_y,local_z for sound position, of which I want one to be further away (z).(later also one to the side). I also have values for heading, pitch and rollThree sound as for now and one camera as listener. Currently for the listener I do local_x - camera_x. Works fine but I don't know how to set the three sound positions. Many thanks indeedMichael
  It's still the case that you have to use alListener and alSource with the specifiers AL_POSITION, AL_ORIENTATION and (perhaps) AL_DIRECTION. Make sure that all parameters (i.e. the co-ordinates given to alListener and alSOurce) are given in the same co-ordinate space.Since you compute local_x - camera_x for the listener, the co-ordinate space you've chosen is the so-called view space (in which the camera is at the origin and points along a defined cardinal axis, usually z or y), because it is part of the global-to-local transformation for the camera. So transform the source position to that space, too.The space transformation you're shown consists of a translation only (but no rotation). Do the mentioned "heading, pitch and roll" belong to the camera or to a sound source? In the former case your transformation is incomplete and hence "works fine" could not be true. In the latter case the direction of the source can be used "as is" since it isn't changed by transforming into view space, but that is only true as long as the situation doesn't change (in other words: it is also incomplete in the general case).I still urge you to drop that scalar computations and switch over to matrix math. It is logically not that different from what you're doing (or want to do) but it is much less typing and (especially) much less prone to errors!;  They are all in the same coordinate system. Listener/camera works fine and always points to the plane. Uuh normal for games... I told already that I don't understand matrix. If u understand that why don't you give a complete c++ example? All data I have are from the plane and the sound positions have to move accordingly...lol.   ;Quote:Original post by mike4linuxI told already that I don't understand matrix.Yes, you did. But I ask you (without being offending): Why do you expect from us to spend our time in solving your problem, when we don't see your goodwill to solve your own problem yourself? At least jyk and me have told you that using matrix math at this point will solve your problems easily. Not only that; it will further prepare you with a toolset to solve such problems in the future in a fraction of the time you spend now. When we simply give you a solution for the current problem, you still have no clue what to do with the next one (e.g. what if the sound sources should be directed? what if a sound source outside the airplane should be rendered, too? what if the listener isn't placed with the camera but with the pilot's head?)Matrix math in its entirety is definitely heavy stuff. But the subset of matrix math needed for your purposes is much smaller and easy to learn. Look for how matrices can be used to express linear equation systems (e.g. the rotation formula you are using is in fact a linear equation system). Look for how the matrix product works. Looks for how transformations are expressed in matrix form. Look for the transpose operator for matrices. That's all (from the top of my head) what you currently need. I would say that a day or so is long enough to learn that stuff. Perhaps approximately 2 or 3 other days to implement that stuff, or else a day to pick and learn an existing library.Quote:Original post by mike4linuxIf u understand that why don't you give a complete c++ example?What should that be good for? E.g.EulerRotation3 euler( yaw, pitch, roll, EulerRotation3::YPR );BasisRotation3 basis( euler );creates a matrix representation for a rotation given by Euler's yaw, pitch, and roll (in this order) using my own library. That piece of code is easy to understand, but it doesn't help you. The code behind that is mainlyEulerRotation3::EulerRotation3(angle_t a0, angle_t a1, angle_t a2, order_t order)   :   a0(a0), a1(a1), a2(a2),  _order(order) {}template<typename scalar_g>voidBasisRotation3<scalar_g>::setupFrom(EulerRotation3 const& angles) {   setupFrom(angles.dimensionAt(0), angles.a0);   if(angles.a1!=0) { mulLocal(angles.dimensionAt(1), angles.a1);   }   if(angles.a2!=0) { mulLocal(angles.dimensionAt(2), angles.a2);   }}template<typename scalar_g>voidBasisRotation3<scalar_g>::setupFrom(Space3::dimension_t pivot, angle_t angle) {   // presetting   _vectors = Matrix33<scalar_g>::IDENTITY;   // computing sine and cosine   float sin, cos;   Angle::fsincos(angle, sin, cos);   if(pivot&1) { sin = -sin;   }   // overwriting components of altered dimensions   Space3::dimension_t const alt0 = Space3::ORTHOGONALS[pivot][0];   Space3::dimension_t const alt1 = Space3::ORTHOGONALS[pivot][1];   _vectors[alt0][alt0] = _vectors[alt1][alt1] = cos;   _vectors[alt0][alt1] = +sin;   _vectors[alt1][alt0] = -sin;}template<typename scalar_g>BasisRotation3<scalar_g> &BasisRotation3<scalar_g>::mulLocal(Space3::dimension_t pivot, angle_t angle) {   // computing sine and cosine   float sin, cos;   Angle::fsincos(angle, sin, cos);   if(pivot&1) {   sin = -sin;   }   // temporary variables   Space3::dimension_t const alt0 = Space3::ORTHOGONALS[pivot][0];   Space3::dimension_t const alt1 = Space3::ORTHOGONALS[pivot][1];   register scalar_g t0, t1;   // overwriting components   Vector3_t & v0 = _vectors[alt0];   Vector3_t & v1 = _vectors[alt1];   // ... 1st row   t0 = v0.s0*cos+v1.s0*sin;   t1 = v1.s0*cos-v0.s0*sin;   v0.s0 = t0, v1.s0 = t1;   // ... 2nd row   t0 = v0.s1*cos+v1.s1*sin;   t1 = v1.s1*cos-v0.s1*sin;   v0.s1 = t0, v1.s1 = t1;   // ... 3rd row   t0 = v0.s2*cos+v1.s2*sin;   t1 = v1.s2*cos-v0.s2*sin;   v0.s2 = t0, v1.s2 = t1;   // done   return *this;}// in class EulerRotation3:   typedef enum order_t { /** \brief denotes the order \c roll-yaw-pitch. */ RYP =0x012, /** \brief denotes the order \c yaw-pitch-roll (a.k.a.\ "heading-pitch-bank" in aeronautics). */ YPR =0x201, /** \brief denotes the order \c yaw-pitch-yaw, well known as "the proper Euler angles" order. */ YPY =0x101, /** \brief denotes the order \c yaw-roll-yaw. */ YRY =0x121, /** \brief denotes the default order which is \ref YPR in fact. */ DEFAULT =YPR   };// in class Space3:   typedef enum dimension_t { /** \brief denotes the 1st dimension, orthogonal to the 2nd and 3rd one. */ D0 = 0, /** \brief denotes the 2nd dimension, orthogonal to the 1st and 3rd one. */ D1 = 1, /** \brief denotes the 3rd dimension, orthogonal to the 1st and 2nd one. */ D2 = 2   };Space3::dimension_t constSpace3::ORTHOGONALS[3][2] = {   { D1, D2 },   { D0, D2 },   { D0, D1 }};So what now? Can you guess from this (admittedly not straight-forward implemented) example how code for a "complete example" will look like? The only thing you can do with a "complete example" is to copy-&-paste it. The result will be spaghetti code with much of glue in-between code snippets copied from a dozen authors. That is not my understanding of help. As said, I'm not intended to be offending you with this post. It is just my point of view.Quote:Original post by mike4linuxThey are all in the same coordinate system.So what is the problem? If you have the position and orientation of the listener, as well as the positions of the sources given in the same system, then OpenAL is happy with it. Just convert the yaw, pitch, and roll into the parameters "at" and "up" as required by alListener(AL_ORIENTATION,...). How to do that is demonstrated in the code above: BasisRotation3::v1 will store the "up" vector, and BasisRotation3::v2 will store the "at" vector.   ;  why so complicated...I'm not sure if i find time today to only look through your code and of course mine is much simpler...if only we find the fault. Any openAl guy around? Basically the values seem ok but they are not linear, ie some values going faster and hence no more sound for a while etc.--------------------lX, lY, lZ are the local_x etc. dataref values also using the phi(roll), theta(pitch) and psi(heading) datarefscX etc. are the view_x/camera datarefs for heading i do:    if (pPsi > 180)   pPsi -= 360;    heading = pPsi * 3.14 / 180.0;-----------------    ListenerPos[0] = cX/100;//DleVal[0];// cX/100;//posX;  alListenerfv(AL_POSITION,ListenerPos);  alListenerfv(AL_VELOCITY,    ListenerVel);   //    ListenerOri[0] = pPsi;  alListenerfv(AL_ORIENTATION, ListenerOri);  ListenerPos[1] =  cY/100;//DleVal[1]/10;//cY/100;//posY;alListenerfv(AL_POSITION,ListenerPos);alListenerfv(AL_VELOCITY,    ListenerVel);  //   ListenerOri[1] = pPsi;alListenerfv(AL_ORIENTATION, ListenerOri);ListenerPos[2] =  cZ/100;//DleVal[2];//cZ/100;//posZ;   alListenerfv(AL_POSITION,ListenerPos);   alListenerfv(AL_VELOCITY,    ListenerVel); //  ListenerOri[2] = pPsi;   alListenerfv(AL_ORIENTATION, ListenerOri);    //for(int j = 1; j < NUM_SOURCES; j++)    //    {// Sound 0 is not moving at all SourcesPos[0][0] = 0.0; //pX; SourcesPos[0][1] = 0.0; //pY - 20; SourcesPos[0][2] = 0.0;//pZ + 2// SourcesVel[0][0] = 0.0; //pX;// SourcesVel[0][1] = 0.0; //pY - 20;// SourcesVel[0][2] = 0.0;//pZ + 2 SourcesDir[0][0] = 0.0; //pX; SourcesDir[0][1] = 0.0; //pY - 20; SourcesDir[0][2] = 0.0;//pZ + 2 alSourcefv(Sources[0], AL_POSITION, SourcesPos[0]);// alSourcefv(Sources[0], AL_VELOCITY, SourcesVel[0]); alSourcefv (Sources[0], AL_DIRECTION, SourcesDir[0]); alGetSourcei(Sources[0], AL_SOURCE_STATE, &state); if(state != AL_PLAYING && rainP >= 0.3) { alSourcePlay(Sources[0]);  }   //    alGetSourcefv(Sources[1],AL_POSITION,SourcesPos[1]); alGetSourcei(Sources[1], AL_SOURCE_STATE, &state); if(state != AL_PLAYING) { SourcesPos[1][0] = lX/100-pTheta; SourcesPos[1][1] = lY/100+heading; SourcesPos[1][2] = lZ/100+pPhi+1; //move this sound 1 towards tail SourcesVel[1][0] = 0.0; //pX; SourcesVel[1][1] = 0.0; //pY - 20; SourcesVel[1][2] = 0.0;//pZ + 2 SourcesDir[1][0] = 0.0; //pX; SourcesDir[1][1] = 0.0; //pY - 20; SourcesDir[1][2] = 100.0;//pZ + 2 alSourcef(Sources[1],AL_PITCH,1.0f); alSourcef(Sources[1],AL_GAIN,1.0f); alSourcefv(Sources[1], AL_POSITION, SourcesPos[1]); alSourcefv(Sources[1], AL_VELOCITY, SourcesVel[1]); alSourcefv (Sources[1], AL_DIRECTION, SourcesDir[1]); alSourcei(Sources[1],AL_BUFFER, Buffers[FRONTRIGHT]); alSourcei(Sources[1],AL_LOOPING,AL_FALSE); alGetSourcefv(Sources[1],AL_POSITION,SourcesPos[1]); alSourcePlay(Sources[1]);  };  Anyone sees a fault with such x/y/z positioning:Thanks MichaelSourcesPos[1][0] = lX/100-pTheta;SourcesPos[1][1] = lY/100+heading;SourcesPos[1][2] = lZ/100+pPhi+1; //move this sound 1 towards tail;  Please wrap code of more than a few lines by [source] and [/source] tags; see the forum FAQs.Quote:Original post by mike4linuxwhy so complicated...I'm not sure if i find time today to only look through your code and of course mine is much simpler...You've asked for complete code. You code doesn't contain such an approach at all. The code I've posted (and that isn't intended to be used by you, at least not "as is") shows a typical approach for complex software problems: Divide the problem into smaller pieces and solve each piece in a sufficiently generic way (what may mean to divide it further). You can see that there is a piece of code that handles Euler angles with (some of) their variations. You can see there is a piece of code that handles basis matrices as a kind of rotation representation, among other its conversion from Euler angles. Not shown are the pieces for other transformations (also they are not that variable than rotations) and the matrix product stuff.And although it is more complicted than your code, it has the advantage of unburdening the programmer from thinking, implementing, and testing each particular transformation again and again.Quote:Original post by mike4linuxAnyone sees a fault with such x/y/z positioning:SourcesPos[1][0] = lX/100-pTheta;SourcesPos[1][1] = lY/100+heading;SourcesPos[1][2] = lZ/100+pPhi+1; //move this sound 1 towards tailErrr, do you add angles onto the scalars of a position vector here?I assume you want to implement a rotation of the sound sources. Assuming that the center of rotation is given in the same co-ordinate system as the position of the source is, then the formulap' := C * R * C-1 * pcomputes the effect, where p and p' are the positions before and after the transformation, resp., C is the translation to the center, and R the rotation. If the center is in the origin of the co-ordinate system, then C becomes the identity matrix which does nothing in a matrix product, so that in that special caseC == I => p' = I * R * I-1 * p = R * pthe simple rotation formula remains.However, resolving such a formula into their scalar equations will definitely contain sines and cosines. In you case of using Euler angles, the rotation has to be composed by 3 particular rotations around local space axes. The order in which this has to happen is not clear to us; there are 12 possibilities.The link showing the matrix notation shows also an exemplary matrix after carrying out the matrix product just above the section "Matrix expression for Euler rotations". When you look at that matrix you perhaps start to understand why matrix notation and a suitable library really make things easier. Please notice that the complexity is inherent to the problem but not caused by using matrices. Instead, matrices make the usage easier and more efficient.   