Dose anyone know the formula Roblox Used to convert Lighting Data (eg. TimeOfDay and GeographicLatitude) to the direction of the sun? I know there is a inbuilt Roblox Method but I want to know as I am trying to use this formula for a Blender add-on to replicate Roblox Lighting so i need the actual formula.
Ive tried to rip and read the code from a Sun Position Plugin… but… fr, just look at this Unreadable mess
function ToTimeOfDay(n)
local i,f = math.modf(n)
local m = f*60
local mi,mf = math.modf(m)
m = tostring(math.abs(math.floor(m)))
local s = tostring(math.abs(math.floor(mf*60)))
return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
end
function rad_sc(n)
return n/(math.pi*2)
end
function sc_rad(n)
return n*(math.pi*2)
end
function ToLatLon(d)
d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
local lon = math.atan2(d.y,d.x)
lat = rad_sc(lat)*360 + 23.5
lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
return lat,lon
end
???. I’m a little confused on what you mean… but I think you mean“Are there any existing Blender plugins that do this”. Now I don’t think so as I’ve tried to look before, but even if this dose exist, I think it would be a good exercise for myself to get the hang of BlenderPy.
Dose bro even know what the inverse of a math function is?
Basically an inverse is NOT just 1 / function (that’s a reciprocal ), its a version of the same function, that when you Input in to the Inverse its Original Function’s Outputs It returns the the what the Original function’s inputs would be to get that output…
Example:
local y_from_normal = foo(x)
local x_from_inverse = foo_inverse(y_from_normal)
print(x_from_inverse == x) -- Should be true in almost all cases, although the sign may change (eg, `x = -1`, but `x_from_inverse = 1`)
Examples of inverse functions are: x^2 and sqrt(x), 10^x and log(x), tan(x) and arctan(x)(yes, arctan2(), the fuction used for converting x,y → angle is just a slightly modified version of the arctan() the inverse of tan()), Etc.
To create an inverse function is not easy, as you have to create an entirely new function by swaping, X and Y and then solving for X. (Eg: y = 10x + 3 → x = 10y + 3 → x - 3 = 10y → 1/10(x - 3) = y → 1/10x - 3/10 = y → y = 1/10x - 3/10)
sorry for the math lesson folks
Short Explination of Inverse Functions
Also GetSunDirection()is the exact function I want, its just that since I’m not currently inside Roblox, I need a function that esentially dose the same with just the ClockTime and GeographicLatitude values passed in.
No, he can’t, he is referring to that method because that is what is in the actual ROBLOX studio, he wants to do that but in Blender rather than in our studio engine.