@quenty/sunpositionutils 2.0.0 → 2.0.1-canary.235.cd27669.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE.md +1 -1
- package/package.json +2 -2
- package/src/Shared/SunPositionUtils.lua +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.1-canary.235.cd27669.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@2.0.0...@quenty/sunpositionutils@2.0.1-canary.235.cd27669.0) (2021-12-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Selene linting Vector3.zAxis ([cd27669](https://github.com/Quenty/NevermoreEngine/commit/cd276691d3ea5d0b5654f80a49c50da5c810c83b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Add SunPositionUtils.getSunPosition(clockTime, geoLatitude), SunPositionUtils.getClockTimeFromMoonDirection(direction), and SunPositionUtils.getGeographicalLatitudeFromMoonDirection ([30d89da](https://github.com/Quenty/NevermoreEngine/commit/30d89da571e036cb4ac1b13505324f499eb3d2c5))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@1.2.0...@quenty/sunpositionutils@2.0.0) (2021-09-05)
|
|
7
23
|
|
|
8
24
|
|
package/LICENSE.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/sunpositionutils",
|
|
3
|
-
"version": "2.0.0",
|
|
3
|
+
"version": "2.0.1-canary.235.cd27669.0",
|
|
4
4
|
"description": "Utility to position the sun",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "cd276691d3ea5d0b5654f80a49c50da5c810c83b"
|
|
31
31
|
}
|
|
@@ -5,21 +5,52 @@ local SunPositionUtils = {}
|
|
|
5
5
|
|
|
6
6
|
local EARTH_TILT = 23.5
|
|
7
7
|
local NORTH = Vector3.new(0, 0, -1)
|
|
8
|
+
local ZAXIS = Vector3.new(0, 0, 1)
|
|
8
9
|
|
|
9
10
|
function SunPositionUtils.getGeographicalLatitudeFromDirection(direction)
|
|
10
11
|
local angle = math.atan2(direction.z, math.sqrt(direction.x^2 + direction.y^2))
|
|
11
12
|
return angle/(math.pi*2)*360+EARTH_TILT
|
|
12
13
|
end
|
|
13
14
|
|
|
15
|
+
SunPositionUtils.getGeographicalLatitudeFromMoonDirection = SunPositionUtils.getGeographicalLatitudeFromDirection
|
|
16
|
+
|
|
14
17
|
function SunPositionUtils.getClockTimeFromDirection(direction)
|
|
15
18
|
local altitude = math.atan2(-direction.y, -direction.x)
|
|
16
19
|
|
|
17
20
|
return (altitude/(math.pi*2)*24-6) % 24
|
|
18
21
|
end
|
|
19
22
|
|
|
23
|
+
function SunPositionUtils.getClockTimeFromMoonDirection(direction)
|
|
24
|
+
local altitude = math.atan2(direction.y, direction.x)
|
|
25
|
+
|
|
26
|
+
return (altitude/(math.pi*2)*24-6) % 24
|
|
27
|
+
end
|
|
28
|
+
|
|
20
29
|
function SunPositionUtils.getDirection(azimuthRad, altitudeRad, north)
|
|
21
30
|
local cframe = (CFrame.Angles(0, azimuthRad, 0) * CFrame.Angles(altitudeRad, 0, 0))
|
|
22
31
|
return cframe:vectorToWorldSpace(north or NORTH)
|
|
23
32
|
end
|
|
24
33
|
|
|
34
|
+
function SunPositionUtils.getSunPosition(clockTime, geoLatitude)
|
|
35
|
+
local seconds = clockTime*60*60
|
|
36
|
+
local DAY = 24 * 60 * 60
|
|
37
|
+
local YEAR = 365.2564 * DAY
|
|
38
|
+
local HALFYEAR = 182.6282
|
|
39
|
+
local EARTHTILT = math.rad(23.5)
|
|
40
|
+
|
|
41
|
+
local modTime = seconds - math.floor(seconds / DAY) * DAY
|
|
42
|
+
local sourceAngle = 2 * math.pi * modTime / DAY
|
|
43
|
+
local sunPosition = Vector3.new(math.sin(sourceAngle), -math.cos(sourceAngle), 0)
|
|
44
|
+
local moonPosition = Vector3.new(math.sin(sourceAngle + math.pi), math.cos(sourceAngle + math.pi), 0)
|
|
45
|
+
local dayOfYearOffset = (seconds - (seconds * math.floor(seconds / YEAR))) / DAY
|
|
46
|
+
|
|
47
|
+
local latRad = math.rad(geoLatitude)
|
|
48
|
+
local sunOffset = -EARTHTILT * math.cos(math.pi * (dayOfYearOffset - HALFYEAR) / HALFYEAR) - latRad
|
|
49
|
+
|
|
50
|
+
local trueSunPosition = CFrame.fromAxisAngle(ZAXIS:Cross(sunPosition), sunOffset) * sunPosition
|
|
51
|
+
local trueMoonPosition = CFrame.fromAxisAngle(ZAXIS:Cross(moonPosition), sunOffset) * moonPosition
|
|
52
|
+
|
|
53
|
+
return trueSunPosition, trueMoonPosition*Vector3.new(1, -1, 1)
|
|
54
|
+
end
|
|
55
|
+
|
|
25
56
|
return SunPositionUtils
|