@quenty/sunpositionutils 2.0.1-canary.9c1fd3b.0 → 2.1.1

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 CHANGED
@@ -3,7 +3,7 @@
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.9c1fd3b.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@2.0.0...@quenty/sunpositionutils@2.0.1-canary.9c1fd3b.0) (2021-09-11)
6
+ ## [2.1.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@2.1.0...@quenty/sunpositionutils@2.1.1) (2021-12-30)
7
7
 
8
8
  **Note:** Version bump only for package @quenty/sunpositionutils
9
9
 
@@ -11,6 +11,22 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
+ # [2.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@2.0.0...@quenty/sunpositionutils@2.1.0) (2021-12-18)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Selene linting Vector3.zAxis ([6a24a62](https://github.com/Quenty/NevermoreEngine/commit/6a24a62975d92665b1291e3fbb8a1ea49ee4f69d))
20
+
21
+
22
+ ### Features
23
+
24
+ * Add SunPositionUtils.getSunPosition(clockTime, geoLatitude), SunPositionUtils.getClockTimeFromMoonDirection(direction), and SunPositionUtils.getGeographicalLatitudeFromMoonDirection ([4adeb92](https://github.com/Quenty/NevermoreEngine/commit/4adeb92ecb6a9093062bd4659a8423d16f897454))
25
+
26
+
27
+
28
+
29
+
14
30
  # [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/sunpositionutils@1.2.0...@quenty/sunpositionutils@2.0.0) (2021-09-05)
15
31
 
16
32
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## SunPositionUtils
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -13,6 +13,8 @@
13
13
 
14
14
  Utility to position the sun
15
15
 
16
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/SunPositionUtils">View docs →</a></div>
17
+
16
18
  ## Installation
17
19
  ```
18
20
  npm install @quenty/sunpositionutils --save
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/sunpositionutils",
3
- "version": "2.0.1-canary.9c1fd3b.0",
3
+ "version": "2.1.1",
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": "9c1fd3b43a16f8bc00caafbbb3f7092b4e5cc9eb"
30
+ "gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
31
31
  }
@@ -1,25 +1,57 @@
1
- --- Utility to position the sun
2
- -- @module SunPositionUtils
3
-
1
+ --[=[
2
+ Utility to position the sun
3
+ @class SunPositionUtils
4
+ ]=]
4
5
  local SunPositionUtils = {}
5
6
 
6
7
  local EARTH_TILT = 23.5
7
8
  local NORTH = Vector3.new(0, 0, -1)
9
+ local ZAXIS = Vector3.new(0, 0, 1)
8
10
 
9
11
  function SunPositionUtils.getGeographicalLatitudeFromDirection(direction)
10
12
  local angle = math.atan2(direction.z, math.sqrt(direction.x^2 + direction.y^2))
11
13
  return angle/(math.pi*2)*360+EARTH_TILT
12
14
  end
13
15
 
16
+ SunPositionUtils.getGeographicalLatitudeFromMoonDirection = SunPositionUtils.getGeographicalLatitudeFromDirection
17
+
14
18
  function SunPositionUtils.getClockTimeFromDirection(direction)
15
19
  local altitude = math.atan2(-direction.y, -direction.x)
16
20
 
17
21
  return (altitude/(math.pi*2)*24-6) % 24
18
22
  end
19
23
 
24
+ function SunPositionUtils.getClockTimeFromMoonDirection(direction)
25
+ local altitude = math.atan2(direction.y, direction.x)
26
+
27
+ return (altitude/(math.pi*2)*24-6) % 24
28
+ end
29
+
20
30
  function SunPositionUtils.getDirection(azimuthRad, altitudeRad, north)
21
31
  local cframe = (CFrame.Angles(0, azimuthRad, 0) * CFrame.Angles(altitudeRad, 0, 0))
22
32
  return cframe:vectorToWorldSpace(north or NORTH)
23
33
  end
24
34
 
35
+ function SunPositionUtils.getSunPosition(clockTime, geoLatitude)
36
+ local seconds = clockTime*60*60
37
+ local DAY = 24 * 60 * 60
38
+ local YEAR = 365.2564 * DAY
39
+ local HALFYEAR = 182.6282
40
+ local EARTHTILT = math.rad(23.5)
41
+
42
+ local modTime = seconds - math.floor(seconds / DAY) * DAY
43
+ local sourceAngle = 2 * math.pi * modTime / DAY
44
+ local sunPosition = Vector3.new(math.sin(sourceAngle), -math.cos(sourceAngle), 0)
45
+ local moonPosition = Vector3.new(math.sin(sourceAngle + math.pi), math.cos(sourceAngle + math.pi), 0)
46
+ local dayOfYearOffset = (seconds - (seconds * math.floor(seconds / YEAR))) / DAY
47
+
48
+ local latRad = math.rad(geoLatitude)
49
+ local sunOffset = -EARTHTILT * math.cos(math.pi * (dayOfYearOffset - HALFYEAR) / HALFYEAR) - latRad
50
+
51
+ local trueSunPosition = CFrame.fromAxisAngle(ZAXIS:Cross(sunPosition), sunOffset) * sunPosition
52
+ local trueMoonPosition = CFrame.fromAxisAngle(ZAXIS:Cross(moonPosition), sunOffset) * moonPosition
53
+
54
+ return trueSunPosition, trueMoonPosition*Vector3.new(1, -1, 1)
55
+ end
56
+
25
57
  return SunPositionUtils