Well, what about trigonometry except the essentials doesn't give me a headache... ?
I guess this could also have gone in the SDK forum, but the problem is majorly mathematical, although the formulation is in Orbiterish.
basically, all I need is the cosine of the angle between a surface and the sun.
I have the direction the surface is facing as a normalised vector vessel-relative. So I convert it to global, which I think should give me the direction the surface is facing relative to the sun (0,0,0; close enough for my purposes):
Next I need the angle between my vessel and the sun, which should simply be the inverse of its global position. Then, as far as I understood it (which is obviously wrong, judging by my results) the cosine between these two vectors should be the dot product divided by the distance to the sun, which would be
However, I get complete gibberish. I don't know much, but I know that a well behaved cosine isn't larger than 1. So, what am I doing wrong?
I guess this could also have gone in the SDK forum, but the problem is majorly mathematical, although the formulation is in Orbiterish.
basically, all I need is the cosine of the angle between a surface and the sun.
I have the direction the surface is facing as a normalised vector vessel-relative. So I convert it to global, which I think should give me the direction the surface is facing relative to the sun (0,0,0; close enough for my purposes):
Code:
vessel->Local2Global(openDirections[di], globalDir);
Next I need the angle between my vessel and the sun, which should simply be the inverse of its global position. Then, as far as I understood it (which is obviously wrong, judging by my results) the cosine between these two vectors should be the dot product divided by the distance to the sun, which would be
Code:
double cosDir = dotp(globalDir, -vesselGlobalPos) / sunDist;
However, I get complete gibberish. I don't know much, but I know that a well behaved cosine isn't larger than 1. So, what am I doing wrong?