Programming Question Please help with night activated engines

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
382
Reaction score
254
Points
78
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
Hey everyone, just playing around with some ideas for the SLS project i have started work on, and i want to give the launchpad spotlight effects at night, simmilar to the effect in AMSO or BrianJ's Delta II ad-on. To make the lights i have simply made some thrusters with no thrust and assigned them local light sources, but what i dont know what to do is turn the thrusters on at night, and off at day. I cant seemto be able to find anything on this in the orbiter api docs, so any help would be really appreciated :) thanks in advance

- Mr Martian
 
... You can have local light sources without engines...

Also, for telling if it is night, I suggest you the following concept:

Normalize your relative position to the reference gravity body into a direction vector pointing "up".
Normalize your global position (The sun is effectively the center) into a direction vector pointing away from the sun.

If the scalar product (dotp) of these two vectors is positive, the sun is below the horizon. If it is positive and above a set threshold (cos(elevation_angle)), you can define what kind of night you want - eg, if you are interested in astronomical night.
 
Last edited:
I recommend not to use engines, because in some cases, even a ridiculously tiny thrust can cause the launchpad to bounce around like if it was a rubber castle. So I think it's better to stay safe and only use spotlights that will get activated/deactivated by the conditions you will set.
 
I would suggest to look at FOIs addons on OH,they have great looking night effects,such as spotlights,and also the beam effects,similar to AMSO-L-39pad effects.:thumbup:
 

Attachments

  • 13.04.03 11-02-39 Quasar_220-E.jpg
    13.04.03 11-02-39 Quasar_220-E.jpg
    173.7 KB · Views: 21
In the code from a lua script by Wishbone, there is a function that checks if an object is in daylight or not. It shouldn't be too hard to transform into C++

Here is the code:

Code:
function is_in_daylight(obj)
   local retv
   local rs_angle -- rbody to sun angle
   local rh_angle -- rbody to horizon angle
   local rppos
   local rspos
   local obj_v = vessel.get_interface(obj)
   local body = obj_v:get_surfaceref()
   rppos = obj_v:get_relativepos(body)
   rh_angle = math.asin(oapi.get_size(body)/vec.length(rppos))
   rppos = vec.div(rppos,vec.length(rppos)) -- normalise
   local star = oapi.get_objhandle('Sun')
   rspos = obj_v:get_relativepos(star) -- sun position
   rspos = vec.div(rspos,vec.length(rspos)) -- normalise
   rs_angle = math.acos(vec.dotp(rppos,rspos))+(50/60*RAD)
   if (rs_angle > rh_angle) then
     retv = 1
   else
     retv = 0
   end
   return retv
end
 
Back
Top