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.