View Full Version : using value

mikethebike

07-12-2010, 05:55 AM

Hi

I want to use lX,lY,lZ as below. Rotate and use the new value for openal. Why does this below not work?

Thanks Michael

--------

glPushMatrix();

glLoadIdentity();

glTranslatef(lX/10, lY/10, lZ/10);

glRotatef (-pPsi, 0.0,1.0,0.0);

glRotatef (-pTheta,-1.0,0.0,0.0);

glRotatef (-pPhi, 0.0,0.0,1.0);

alSource3f(Sources[1], AL_POSITION, lX/10, lY/10, lZ/

10);

glPopMatrix();

carsten neumann

07-12-2010, 10:33 AM

Assuming with 'does not work' you mean the sound source seems to be at a different location than you expect, i.e. it is not rotated?

OpenAL and OpenGL use a similar looking API but are otherwise completely different beasts. Multiplying a value on the OpenGL matrix stack only means all glVertex() calls done afterwards are affected by it, but it has no effect on alSource() calls.

You need to apply the rotation to your position (IX, IY, IZ) by hand and pass the transformed position to alSource().

mikethebike

07-12-2010, 11:51 PM

Doing this in math is pretty complicated (see my other posting) so i prefer this. Anyway how could i retrieve/print etc. the values after rotation?

Many thanks

Rosario Leonardi

07-13-2010, 04:10 PM

I read your previous post and I think that nobody reply because you make a bad exposition of your problem.

Let's go 2D.

You have a point P in the X Y plane.

I want to rotate this point by 30 deg

It's pretty easy, I have to project my point in my new (rotated) reference system. To rotating the point by 30 deg is like rotating the reference system by -30 deg.

The new reference system is represented by my versor

a = 30 deg

Remember that I have to rotate by -a

Sx = [cos (-a), sin (-a)]

Sy = [sin-(-a), cos (-a)]

cos(-a) = cos(a)

sin(-a) = -sin(a)

sin -(-a) = sin(a)

this became:

Sx = [cos a,-sin a]

Sy = [sin a, cos a]

so

x' = Sx * P = x * cos a - y * sin a

y' = Sy * P = x * sin a + y * cos a

But we already know this, 2D rotation are for children. ;)

Let's go in 3D. In a 3d space everything is more complex, I can rotate in more axes, but if I rotate around one of the versor of my reference system the coordinated of the versor is unchanged.

If I rotate around Y the Y coordinate of my point don't change... so I have a fixed coordinate and two rotating coordinate. mmmm this remember me something, where I already saw something like that?

Oh snap!! 2D ROTATION. Rotation in 3D around a versor is like a 2D rotation with a fixed coordinated, nothing more.

So your complex openGL code became:

void rotatePoint(const vec3 &input, vec3 *output, float theta, float psi, float phi)

{

vec3 tempA, tempB;

tempA.x = input.x * cos(psi) - input.z * sin(psi);

tempA.y = input.y;

tempA.z = input.x * sin(psi) + input.z * cos(psi);

theta = -theta;

tempB.x = tempA.x;

tempB.y = tempA.y * cos(theta) - tempA.z * sin(theta);

tempB.z = tempA.y * sin(theta) + tempA.z * cos(theta);

output->x = tempB.x * cos(phi) - tempB.y * sin(phi);

output->y = tempB.x * sin(phi) + tempB.y * cos(phi);

output->z = tempB.z;

}

The code is not optimized for clarity sake.

By the way, you have chosen a strange rotation order, can I ask why?

mikethebike

07-14-2010, 12:35 AM

Wow many thanks. Hopefully this will solve all my headache. :o

Where can I get those vec3 headers etc.? I need it for Win/Mac/Lin.

My rotation order...maybe it's simply disordered? :D

mikethebike

07-14-2010, 03:14 AM

Now it seems that either my openal sources are not moving or my listener orientation is wrong:

ALfloat ListenerOri[] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 };

The values seem ok so maybe a OpenAL bug with moving sound sources and camera?

Thanks Michael

Rosario Leonardi

07-14-2010, 05:18 AM

for the vec3 simply define a struct

struct vec3

{

float x, y, z;

};

for the ehm... "openAL bug". Check out your rotation order. Composing rotation is not commutative. Different rotation order can give you totally different results.

mikethebike

07-14-2010, 09:36 AM

Hi

I try simply like:

alListener3f(AL_POSITION, cX/10,cY/10,cZ/10);

alListenerfv(AL_ORIENTATION, ListenerOri);

....

alSource3f(Sources[1], AL_POSITION, lX/10, lY/10, lZ/10);

....

cX etc. is the camera/listener

and lX etc. the airplane

http://www.xsquawkbox.net/xpsdk/mediawiki/ScreenCoordinates#Aircraft_Coordinates

Do I need any formula at all? if I print those values it seems ok but only the listener has effects on sound...looks like a bug to me. moving the plane has no sound effect.

Thanks Michael

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.