@quenty/vector3utils 4.1.1-canary.256.edbbcfc.0 → 5.0.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 CHANGED
@@ -3,7 +3,18 @@
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.edbbcfc.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/vector3utils@4.1.0...@quenty/vector3utils@4.1.1-canary.256.edbbcfc.0) (2022-03-27)
6
+ # [5.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/vector3utils@4.2.0...@quenty/vector3utils@5.0.0) (2022-05-21)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add Vector3Utils.slerp() and Vector3Utils.constrainToCone() ([dff82af](https://github.com/Quenty/NevermoreEngine/commit/dff82afeabd56a4c85e8143683be71cbbe8a2bbf))
12
+
13
+
14
+
15
+
16
+
17
+ # [4.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/vector3utils@4.1.0...@quenty/vector3utils@4.2.0) (2022-03-27)
7
18
 
8
19
 
9
20
  ### Bug Fixes
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2021 Quenty
3
+ Copyright (c) 2014-2022 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/vector3utils",
3
- "version": "4.1.1-canary.256.edbbcfc.0",
3
+ "version": "5.0.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": "4.0.1-canary.256.edbbcfc.0",
29
- "@quenty/math": "2.1.1-canary.256.edbbcfc.0"
28
+ "@quenty/loader": "^5.0.0",
29
+ "@quenty/math": "^2.2.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "edbbcfc38516772a791d50dc43cd6b304ffc4aff"
34
+ "gitHead": "9f7eaea7543c33c89d2e32c38491b13f9271f4f7"
35
35
  }
@@ -42,7 +42,7 @@ function Vector3Utils.getAngleRad(a: Vector3, b: Vector3): number
42
42
  end
43
43
 
44
44
  --[=[
45
- Computes the angle between 2 vectors
45
+ Computes the angle between 2 vectors in radians
46
46
  @param a Vector3
47
47
  @param b Vector3
48
48
  @return number
@@ -53,6 +53,40 @@ function Vector3Utils.angleBetweenVectors(a: Vector3, b: Vector3): number
53
53
  return 2*math.atan2((v - u).magnitude, (u + v).magnitude)
54
54
  end
55
55
 
56
+ --[=[
57
+ Spherically lerps between start and finish
58
+ @param start Vector3
59
+ @param finish Vector3
60
+ @param t number -- Amount to slerp. 0 is start, 1 is finish. beyond that is extended as expected.
61
+ @return Vector3
62
+ ]=]
63
+ function Vector3Utils.slerp(start: Vector3, finish: Vector3, t: number)
64
+ local dot = math.clamp(start:Dot(finish), -1, 1)
65
+
66
+ local theta = math.acos(dot)*t
67
+ local relVec = (finish - start*dot).unit
68
+ return ((start*math.cos(theta)) + (relVec*math.sin(theta)))
69
+ end
70
+
71
+ --[=[
72
+ Constrains a Vector3 into a cone.
73
+ @param direction Vector3 -- The vector direction to constrain
74
+ @param coneDirection Vector3 -- The direction of the cone.
75
+ @param coneAngleRad -- Angle of the cone
76
+ @return Vector3 -- Constrained angle
77
+ ]=]
78
+ function Vector3Utils.constrainToCone(direction: Vector3, coneDirection: Vector3, coneAngleRad: number): Vector3
79
+ local angle = Vector3Utils.angleBetweenVectors(direction, coneDirection)
80
+ local coneHalfAngle = 0.5*coneAngleRad
81
+
82
+ if angle > coneHalfAngle then
83
+ local proportion = coneHalfAngle / angle
84
+ return Vector3Utils.slerp(coneDirection.unit, direction.unit, proportion) * direction.magnitude
85
+ end
86
+
87
+ return direction
88
+ end
89
+
56
90
  --[=[
57
91
  Rounds the vector to the nearest number
58
92