@quenty/vector3utils 4.1.0 → 4.1.1-canary.256.3cf0683.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/package.json +4 -4
- package/src/Shared/RandomVector3Utils.lua +37 -1
- package/src/Shared/Vector3Utils.lua +12 -6
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
|
+
## [4.1.1-canary.256.3cf0683.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/vector3utils@4.1.0...@quenty/vector3utils@4.1.1-canary.256.3cf0683.0) (2022-03-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to core libraries ([6e685b3](https://github.com/Quenty/NevermoreEngine/commit/6e685b3cfbcd3816d15962769a4310a1ec57fb7e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Add RandomVector3Utils.getDirectedRandomUnitVector(direction: Vector3, angleRad: number): Vector3 ([8c5e03a](https://github.com/Quenty/NevermoreEngine/commit/8c5e03a0917b2fdf978890dd508dfdcceca7643b))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [4.1.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/vector3utils@4.0.0...@quenty/vector3utils@4.1.0) (2022-03-20)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @quenty/vector3utils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/vector3utils",
|
|
3
|
-
"version": "4.1.0",
|
|
3
|
+
"version": "4.1.1-canary.256.3cf0683.0",
|
|
4
4
|
"description": "Utilities involving Vector3 objects in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/loader": "
|
|
29
|
-
"@quenty/math": "
|
|
28
|
+
"@quenty/loader": "4.0.1-canary.256.3cf0683.0",
|
|
29
|
+
"@quenty/math": "2.1.1-canary.256.3cf0683.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3cf06830affe1e6a6ca452a87969520cd941ccaa"
|
|
35
35
|
}
|
|
@@ -9,7 +9,7 @@ local RandomVector3Utils = {}
|
|
|
9
9
|
Equal distribution unit vectors around a sphere
|
|
10
10
|
@return Vector3
|
|
11
11
|
]=]
|
|
12
|
-
function RandomVector3Utils.getRandomUnitVector()
|
|
12
|
+
function RandomVector3Utils.getRandomUnitVector(): Vector3
|
|
13
13
|
local s = 2*(math.random()-0.5)
|
|
14
14
|
local t = 6.2831853071796*math.random()
|
|
15
15
|
local rx = s
|
|
@@ -19,4 +19,40 @@ function RandomVector3Utils.getRandomUnitVector()
|
|
|
19
19
|
return Vector3.new(rx, ry, rz)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
--[=[
|
|
23
|
+
Gets a uniformally distributed random unit vector3 in the direction
|
|
24
|
+
specified.
|
|
25
|
+
|
|
26
|
+
@param direction Vector3
|
|
27
|
+
@param angleRad number -- Angle in radians
|
|
28
|
+
@return Vector3
|
|
29
|
+
]=]
|
|
30
|
+
function RandomVector3Utils.getDirectedRandomUnitVector(direction: Vector3, angleRad: number): Vector3
|
|
31
|
+
assert(typeof(direction) == "Vector3", "Bad direction")
|
|
32
|
+
assert(type(angleRad) == "number", "Bad angleRad")
|
|
33
|
+
|
|
34
|
+
local s = 1 - (1 - math.cos(angleRad))*math.random()
|
|
35
|
+
local t = 6.2831853071796*math.random()
|
|
36
|
+
local rx = s
|
|
37
|
+
local m = (1-s*s)^0.5
|
|
38
|
+
local ry = m*math.cos(t)
|
|
39
|
+
local rz = m*math.sin(t)
|
|
40
|
+
|
|
41
|
+
local dx, dy, dz = direction.x, direction.y, direction.z
|
|
42
|
+
local d = (dx*dx+dy*dy+dz*dz)^0.5
|
|
43
|
+
|
|
44
|
+
if dx/d < -0.9999 then
|
|
45
|
+
return Vector3.new(-rx, ry, rz)
|
|
46
|
+
elseif dx/d < 0.9999 then
|
|
47
|
+
local coef1 = (rx- dx*(dy*ry+dz*rz)/(dy*dy+dz*dz))/d
|
|
48
|
+
local coef2 = (dz*ry-dy*rz)/(dy*dy+dz*dz)
|
|
49
|
+
return Vector3.new(
|
|
50
|
+
(dx*rx+dy*ry+dz*rz)/d,
|
|
51
|
+
dy*coef1+dz*coef2,
|
|
52
|
+
dz*coef1-dy*coef2)
|
|
53
|
+
else
|
|
54
|
+
return Vector3.new(rx, ry, rz)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
22
58
|
return RandomVector3Utils
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
--[=[
|
|
2
|
-
Utilities involving Vector3 objects in Roblox
|
|
2
|
+
Utilities involving Vector3 objects in Roblox.
|
|
3
3
|
@class Vector3Utils
|
|
4
4
|
]=]
|
|
5
5
|
|
|
@@ -14,7 +14,7 @@ local Vector3Utils = {}
|
|
|
14
14
|
@param vector2 Vector2
|
|
15
15
|
@return Vector3
|
|
16
16
|
]=]
|
|
17
|
-
function Vector3Utils.fromVector2XY(vector2)
|
|
17
|
+
function Vector3Utils.fromVector2XY(vector2: Vector2): Vector3
|
|
18
18
|
return Vector3.new(vector2.x, vector2.y, 0)
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -23,7 +23,7 @@ end
|
|
|
23
23
|
@param vector2 Vector2
|
|
24
24
|
@return Vector3
|
|
25
25
|
]=]
|
|
26
|
-
function Vector3Utils.fromVector2XZ(vector2)
|
|
26
|
+
function Vector3Utils.fromVector2XZ(vector2: Vector2): Vector3
|
|
27
27
|
return Vector3.new(vector2.x, 0, vector2.y)
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ end
|
|
|
33
33
|
@param b Vector3
|
|
34
34
|
@return number?
|
|
35
35
|
]=]
|
|
36
|
-
function Vector3Utils.getAngleRad(a, b)
|
|
36
|
+
function Vector3Utils.getAngleRad(a: Vector3, b: Vector3): number
|
|
37
37
|
if a.magnitude == 0 then
|
|
38
38
|
return nil
|
|
39
39
|
end
|
|
@@ -47,7 +47,7 @@ end
|
|
|
47
47
|
@param b Vector3
|
|
48
48
|
@return number
|
|
49
49
|
]=]
|
|
50
|
-
function Vector3Utils.angleBetweenVectors(a, b)
|
|
50
|
+
function Vector3Utils.angleBetweenVectors(a: Vector3, b: Vector3): number
|
|
51
51
|
local u = b.magnitude*a
|
|
52
52
|
local v = a.magnitude*b
|
|
53
53
|
return 2*math.atan2((v - u).magnitude, (u + v).magnitude)
|
|
@@ -55,11 +55,17 @@ end
|
|
|
55
55
|
|
|
56
56
|
--[=[
|
|
57
57
|
Rounds the vector to the nearest number
|
|
58
|
+
|
|
59
|
+
```lua
|
|
60
|
+
-- Snaps to a grid!
|
|
61
|
+
local snapped = Vector3Utils.round(position, 4)
|
|
62
|
+
```
|
|
63
|
+
|
|
58
64
|
@param vector3 Vector3
|
|
59
65
|
@param amount number
|
|
60
66
|
@return Vector3
|
|
61
67
|
]=]
|
|
62
|
-
function Vector3Utils.round(vector3, amount)
|
|
68
|
+
function Vector3Utils.round(vector3: Vector3, amount: number): number
|
|
63
69
|
return Vector3.new(Math.round(vector3.x, amount), Math.round(vector3.y, amount), Math.round(vector3.z, amount))
|
|
64
70
|
end
|
|
65
71
|
|