- Joined
- Mar 27, 2008
- Messages
- 194
- Reaction score
- 0
- Points
- 0
I'm working on a bit of code to determine sun angle to a set of solar arrays. Overall the code works but there is some weirdness. I'm sure it something simple, but I haven't been able to figure it out yet ![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Here is my code:
It is loosely based on tblaxland's planet shadow code that I found here on the board, that code works great, I've got a nice little indicator on the hud (for testing) that tells me if I'm in the shadow of the planet I'm orbiting. My code has a few weird things, and an unxepcted output. this is most likely due to my lack of knowledge of vectors ![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
The thing that really mystifies me is that the output is off by ~6.2 degrees. Once I added that in I get 90 when I'm looking at the sun. Anyone know what makes that happen? the second thing that I'm unclear about is why I get 90 degrees when looking at the sun, I expected 0. I'm getting the angle between the z axis of the ship and the position of the sun in normalized local coordinates. It seems to me that should 0 when they are aligned, but I am vectors noob :lol: It is also possible that you can't do what I'm doing and it just happens to look like it is working.
Any feedback is greatly appreciated!
Here is my code:
Code:
//Check to see what the angle between the sun and solar arrays
VECTOR3 rspos, lspos;//holder for relative sun position, local sun position
VECTOR3 lppos = {0,0,1};//solar panels always point along z axis
VESSEL * v = oapiGetVesselInterface(vesselObject);//identify our vessel
OBJHANDLE h1 = oapiGetObjectByName("Sun");//identify the sun
v->GetRelativePos(h1, rspos); //relative sun position
Global2Local(rspos,lspos);//convert relative postion to local position
lspos = lspos/length(lspos);//normalize local position
sunAngle = (((acos(dotp(lspos,lppos)))*(180/PI))+6.2);//calculate angle "+6.2" to get 90 degrees when directly facing sun
The thing that really mystifies me is that the output is off by ~6.2 degrees. Once I added that in I get 90 when I'm looking at the sun. Anyone know what makes that happen? the second thing that I'm unclear about is why I get 90 degrees when looking at the sun, I expected 0. I'm getting the angle between the z axis of the ship and the position of the sun in normalized local coordinates. It seems to me that should 0 when they are aligned, but I am vectors noob :lol: It is also possible that you can't do what I'm doing and it just happens to look like it is working.
Any feedback is greatly appreciated!
Last edited: