Angle between two vectors

Hello guys!

I changed the name of the variable, and I still have the problem.

I don’t know what I have to do…

Thank you for the moment

Best regards

Kurt

I suspect that you were right when you supposed that the problem was in your use of gluUnproject. Have you checked the values you are getting out of that to make sure they are correct?

Ok…

I will check the result that comes from the gluUnProject.

Thanks

Best regards

Kurt

I checked it and it worked, but there were some things I think
you should change:

1.: #define NC_PI 3.1415926
No good, cause the compiler will create a double but you want a float. Add an ‘f’ to the number or, better, use
const float NC_PI 3.1415926f

2.: You pass your VECTOR structures to your functions by value. Bad. These functions are really small, inline them.
So better use this:
inline float dot_product(const VECTOR &_V1, const VECTOR &_V2)
{
return ((_V1.x * _V2.x) + (_V1.y * _V2.y));
}
inline float vector_length(const VECTOR &_V1)
{
return (float)sqrt((double)((_V1.x * _V1.x) + (_V1.y * _V1.y)));
}

3.: In the function Get_Angle_Between_Points you write
angle=acos((vf_dot_product/(vf_length_V1vf_length_V2)));
I once had a compiler problem with something similar. I used some trig-function that wanted a double as parameter (just like acos). If I didn’t explicitly cast the parameter to be a double it crashed. Since then I don’t trust the compilers no more and always write
angle = (float)acos((double)(vf_dot_product/(vf_length_V1
vf_length_V2)));

4.: Instead of angle=angle*(180/NC_PI) better use angle*=(180.0f/NC_PI) or define another constant
const float NC_PI180=(180.0f/NC_PI);
and use that instead.
angle*=NC_PI180;

As I said at the beginning, none of these are normally a source for failures
as you described them, but especially #defines can often, depending on the
compiler, lead to some unwanted behaviour.

i dont feel like reading all those replies to see if this has already been said but have you taken into consideration the fact that two angles have the same acos(x). for instace acos(-.034202) =110 (thats what the computer will tell you) bit it also equals 250.

Hello guys!!!

I found the problem…now I´m happy!!!

Thanks for all the help.

Kurt

Well what was the problem?

The input value, that I was sending to the function was wrong.

Thanks

Kurt