Hello world.
It's getting late and I finally managed to get a quick bugfix for an OpenGL issue.
Basically, I have two vectors in 3d space, and the angle between them should tend towards 0.
It tends to that in most cases, but in some, it tends towards "minus infinity", and this is the limit of my bugfix: I can't seem to be able to get rid of.. wait a minute, just had an idea about the cause.
Anyway, I figured I'd post the code which sometimes returns minus infinity.
It shouldn't, unless I've forgot something about the acos function in maths...
(scratches head... shouldn't do maths at 1AM I guess, but hey..)
code:
GLfloat vectorMaths::angleBetween(vertex * v1, vertex * v2){
GLfloat dotprod = v1->x*v2->x+v1->y*v2->y+v1->z*v2->z;
return (GLfloat)acos(dotprod / (length(v1) * length(v2)));
}
(Edited by _Mauro on 04-28-2006 01:11)