Horde3D http://www.horde3d.org/forums/ |
|
OpenAL orientation http://www.horde3d.org/forums/viewtopic.php?f=2&t=408 |
Page 1 of 1 |
Author: | Fidora [ 13.07.2008, 22:45 ] |
Post subject: | OpenAL orientation |
I've been playing some with OpenAL and I'm now trying to get it inside my Horde3D application, but I've ran into a problem. When setting the listeners orientation in OpenAL it expects 2 directional vectors, one 'forward' and one 'up'. I'm not that good with math yet and maybe someone could help me by showing the fastest way to convert Horde3D's pitch, yaw and roll into these two directional vectors? |
Author: | Volker [ 14.07.2008, 08:55 ] |
Post subject: | Re: OpenAL orientation |
Just use the transformation matrix of the node without the translation, multiplicate the forward (0 0 1) and the up vector ( 0 1 0 ) with this transformation and normalize the result. |
Author: | Fidora [ 14.07.2008, 11:47 ] |
Post subject: | Re: OpenAL orientation |
Could you provide some code? ![]() I should also mention that this is going to be an Horde3D extension, so it ok to use Horde3D's classes. and forward should be (0 0 -1) right? |
Author: | Volker [ 14.07.2008, 12:11 ] |
Post subject: | Re: OpenAL orientation |
The direction depends on the orientation of your model. You should include the utMath.h file to be able to use the Matrix4f, Vec3/4f classes. Code: // Get absolute transformation of node, since OpenAL uses absolute transformations by default unless you specified // that transformations are defined relative to the listener const float* absMatPtr = Horde3D::getNodeTransformMatrices(node, 0, &mat); Matrix4f absMat(absMatPtr); // Remove translation absMat.x[12] = 0; absMat.x[13] = 0; absMat.x[14] = 0; Vec3f forward = (absMat * Vec3f( 0 0 -1 ) ).normalize() ; Vec3f up = (absMat * Vec3f( 0 1 0 ) ).normalize() ; Another possibility if you have the rotation in radians from somewhere: Code: // Precalculate cos and sin values for better performance const float cosx = cosf(x); const float sinx = sinf(x); const float cosy = cosf(y); const float siny = sinf(y); const float cosz = cosf(z); const float sinz = sinf(z); // Transform 0 0 -1 (At-Vector) with current rotation m_listenerOri[0] = - siny*cosx; m_listenerOri[1] = (sinx); m_listenerOri[2] = - (cosx * cosy); // Transform 0 1 0 (Up-Vector) with current rotation m_listenerOri[3] = - (cosy*sinz+siny*sinx*cosz); m_listenerOri[4] = (cosx*cosz); m_listenerOri[5] = (siny*sinz+cosy*sinx*cosz); This is untested but should show you how you can realize it. Would be nice if you create a Wiki page for that when you got it working. |
Author: | imranhabib [ 09.01.2012, 06:10 ] |
Post subject: | Re: OpenAL orientation |
Volker wrote: The direction depends on the orientation of your model. You should include the utMath.h file to be able to use the Matrix4f, Vec3/4f classes. Code: // Get absolute transformation of node, since OpenAL uses absolute transformations by default unless you specified // that transformations are defined relative to the listener const float* absMatPtr = Horde3D::getNodeTransformMatrices(node, 0, &mat); Matrix4f absMat(absMatPtr); // Remove translation absMat.x[12] = 0; absMat.x[13] = 0; absMat.x[14] = 0; Vec3f forward = (absMat * Vec3f( 0 0 -1 ) ).normalize() ; Vec3f up = (absMat * Vec3f( 0 1 0 ) ).normalize() ; Another possibility if you have the rotation in radians from somewhere: Code: // Precalculate cos and sin values for better performance const float cosx = cosf(x); const float sinx = sinf(x); const float cosy = cosf(y); const float siny = sinf(y); const float cosz = cosf(z); const float sinz = sinf(z); // Transform 0 0 -1 (At-Vector) with current rotation m_listenerOri[0] = - siny*cosx; m_listenerOri[1] = (sinx); m_listenerOri[2] = - (cosx * cosy); // Transform 0 1 0 (Up-Vector) with current rotation m_listenerOri[3] = - (cosy*sinz+siny*sinx*cosz); m_listenerOri[4] = (cosx*cosz); m_listenerOri[5] = (siny*sinz+cosy*sinx*cosz); This is untested but should show you how you can realize it. Would be nice if you create a Wiki page for that when you got it working. Hi Volker Is there any way or function that tells us how to know orientation of the model (character) ? I want to know what is the direction towards which my character is facing Will appreciate your response.. Thank you thanks in advance |
Author: | DarkAngel [ 10.01.2012, 00:17 ] |
Post subject: | Re: OpenAL orientation |
imranhabib wrote: Is there any way or function that tells us how to know orientation of the model (character) ? getNodeTransformMatrices gives you the transform, which contains orientation and position.Quote: I want to know what is the direction towards which my character is facing The forward vector in Volker's example contains this direction.
|
Author: | imranhabib [ 11.01.2012, 05:18 ] |
Post subject: | Re: OpenAL orientation |
DarkAngel wrote: imranhabib wrote: Is there any way or function that tells us how to know orientation of the model (character) ? getNodeTransformMatrices gives you the transform, which contains orientation and position.Quote: I want to know what is the direction towards which my character is facing The forward vector in Volker's example contains this direction.helloo Darkangel well I tried the example given by Volker and i got some success in it I got some values in Vec3f forward forward.x = -0.880587 forward.y = 0.352235 forward.z = -0.317011 Firstly Now i don't understand from these numbers that where my agent is facing Secondly these values do not change even if my entity (a keyboard controlled agent) is walking and changing his direction. i did it in the following way . Code: const float* absMatPtr = Horde3D::getNodeTransformMatrices(node, 0, &mat); this was not working h3dGetNodeTransMats(p->m_characterID,0,&relMat); I used this because i think its almost the same function Matrix4f absMat(relMat); absMat.x[12] = 0; absMat.x[13] = 0; absMat.x[14] = 0; //Vec3f forward = (absMat * Vec3f(0,0,-1 ) ).normalize(); This was not working Vec3f forward = absMat * Vec3f(0,0,-1 ); forward.normalize(); when i know the direction of its face i can take some decision based on its face direction with respect to another entity, that's why i want to find direction. How do i know this direction now from Vec3F forward Thanks in advance |
Author: | DarkAngel [ 11.01.2012, 06:10 ] |
Post subject: | Re: OpenAL orientation |
Quote: Firstly Now i don't understand from these numbers that where my agent is facing Those numbers are a vector that represents the direction the agent is facing --- I assumed these were the numbers you were trying to find, so now I'm confused...Can you explain what you mean by "direction"? Do you want a number that represents an angle? |
Author: | imranhabib [ 11.01.2012, 19:35 ] |
Post subject: | Re: OpenAL orientation |
DarkAngel wrote: Quote: Firstly Now i don't understand from these numbers that where my agent is facing Those numbers are a vector that represents the direction the agent is facing --- I assumed these were the numbers you were trying to find, so now I'm confused...Can you explain what you mean by "direction"? Do you want a number that represents an angle? I want to know the direction towards which my agent is facing or looking at . Facing towards. You are right may i need an angle to another entity . Infact I want to calculate the angle to an entity(wall or an obstacle) and then decide to allow its translation if it changes its angle from 90' to 180' then i willl allow its translation or if an entity(wall or an obstacle) is right infront of it i wana stop its translation and if an entity is at an angle to it then i wana allow it to keep moving I hope i have made my question clear |
Author: | shd [ 11.01.2012, 23:03 ] |
Post subject: | Re: OpenAL orientation |
Quote: forward.x = -0.880587 forward.y = 0.352235 forward.z = -0.317011 Excuse me if i'll make some kind of mistake in following post because i'm quite terrible in maths, but these are basics (like highschool i guess) so i'll try to answer. Anyways, as DarkAngel already said, these numbers are vector where your entity is facing (v2 in my example). As you can read on http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm, angle between vectors is Quote: angle = acos(v1•v2) .acos is reverse of cosinus function v1 is vector between your character and obstacle center v2 might be your vector which you already got • is dot product which you can call as dot(v1, v2) in your GLSL shader, v1.dot(v2) in Horde3D so code will look like: Code: float getAngle(H3DNode from, H3DNode to) { Matrix4f relMat = Matrix4f(); h3dGetNodeTransMats(from,0,&relMat); Matrix4f fromAbsMat(relMat); h3dGetNodeTransMats(to,0,&relMat); Matrix4f toAbsMat(relMat); // [x1, y1, z1, w1] 0, 1, 2, 3 // [x2, y2, z2, w2] 4, 5, 6, 7 // [x3, y3, z3, w3] 8, 9, 10, 11 // [x4, y4, z4, w4] 12, 13, 14, 15 // x4 aka. 12, y4 aka. 13, z4 aka. 14 are translation values // v1 is your vector between 'from' and 'to' Vec3f v1 = Vec3f(toAbsMat.x[12] - fromAbsMat.x[12], toAbsMat.x[13] - fromAbsMat.x[13], toAbsMat.x[14] - fromAbsMat.x[14]); v1.normalize(); // you need to normalize it so length will be == 1 absMat.x[12] = 0; absMat.x[13] = 0; absMat.x[14] = 0; // i don't really know why .x is there, but i'm usually not programming in C++ Vec3f v2 = from * Vec3f(0,0,-1); // flip Z axis ?? v2.normalize(); // it needs to be normalized as well return acos(v2.dot(v1)); } It will be useful for you to read something about linear algebra, and/or books like http://www.amazon.com/Game-Engine-Archi ... 1568814135 . Depending on your use, you can avoid computing acos by comparing resulting dot product to particular [-1, 1] value (more about that in literature). You can compute angle for your end-users like artists, but i see no point in doing that inside code. There are a lot free resources on the net about maths, 3d graphics, and game engines, so you don't have to buy any books too. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |