@inglorious/engine 0.1.0 → 0.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/package.json +11 -12
- package/src/docs/ai/movement/dynamic/align.js +0 -131
- package/src/docs/ai/movement/dynamic/arrive.js +0 -88
- package/src/docs/ai/movement/dynamic/dynamic.mdx +0 -99
- package/src/docs/ai/movement/dynamic/dynamic.stories.js +0 -58
- package/src/docs/ai/movement/dynamic/evade.js +0 -72
- package/src/docs/ai/movement/dynamic/face.js +0 -90
- package/src/docs/ai/movement/dynamic/flee.js +0 -38
- package/src/docs/ai/movement/dynamic/look-where-youre-going.js +0 -114
- package/src/docs/ai/movement/dynamic/match-velocity.js +0 -92
- package/src/docs/ai/movement/dynamic/pursue.js +0 -72
- package/src/docs/ai/movement/dynamic/seek.js +0 -37
- package/src/docs/ai/movement/dynamic/wander.js +0 -71
- package/src/docs/ai/movement/kinematic/align.js +0 -122
- package/src/docs/ai/movement/kinematic/arrive.js +0 -78
- package/src/docs/ai/movement/kinematic/face.js +0 -82
- package/src/docs/ai/movement/kinematic/flee.js +0 -36
- package/src/docs/ai/movement/kinematic/kinematic.mdx +0 -67
- package/src/docs/ai/movement/kinematic/kinematic.stories.js +0 -42
- package/src/docs/ai/movement/kinematic/seek.js +0 -34
- package/src/docs/ai/movement/kinematic/wander-as-seek.js +0 -62
- package/src/docs/ai/movement/kinematic/wander.js +0 -28
- package/src/docs/bounds.js +0 -7
- package/src/docs/code-reuse.js +0 -35
- package/src/docs/collision/circles.js +0 -58
- package/src/docs/collision/collision.mdx +0 -27
- package/src/docs/collision/collision.stories.js +0 -22
- package/src/docs/collision/platform.js +0 -76
- package/src/docs/collision/tilemap.js +0 -181
- package/src/docs/empty.js +0 -1
- package/src/docs/engine.mdx +0 -81
- package/src/docs/engine.stories.js +0 -37
- package/src/docs/event-handlers.js +0 -68
- package/src/docs/framerate.js +0 -37
- package/src/docs/game.jsx +0 -15
- package/src/docs/image/image.js +0 -19
- package/src/docs/image/image.stories.js +0 -22
- package/src/docs/image/sprite.js +0 -39
- package/src/docs/image/tilemap.js +0 -84
- package/src/docs/input/controls.js +0 -67
- package/src/docs/input/gamepad.js +0 -67
- package/src/docs/input/input.mdx +0 -55
- package/src/docs/input/input.stories.js +0 -27
- package/src/docs/input/keyboard.js +0 -58
- package/src/docs/input/mouse.js +0 -32
- package/src/docs/instances.js +0 -49
- package/src/docs/player/dynamic/double-jump.js +0 -90
- package/src/docs/player/dynamic/dynamic.stories.js +0 -32
- package/src/docs/player/dynamic/jump.js +0 -83
- package/src/docs/player/dynamic/modern-controls.js +0 -57
- package/src/docs/player/dynamic/shooter-controls.js +0 -51
- package/src/docs/player/dynamic/tank-controls.js +0 -44
- package/src/docs/player/kinematic/double-jump.js +0 -90
- package/src/docs/player/kinematic/jump.js +0 -82
- package/src/docs/player/kinematic/kinematic.stories.js +0 -32
- package/src/docs/player/kinematic/modern-controls.js +0 -56
- package/src/docs/player/kinematic/shooter-controls.js +0 -48
- package/src/docs/player/kinematic/tank-controls.js +0 -42
- package/src/docs/quick-start/first-game.js +0 -49
- package/src/docs/quick-start/hello-world.js +0 -1
- package/src/docs/quick-start.mdx +0 -127
- package/src/docs/quick-start.stories.js +0 -17
- package/src/docs/recipes/add-and-remove.js +0 -71
- package/src/docs/recipes/add-instance.js +0 -42
- package/src/docs/recipes/decision-tree.js +0 -169
- package/src/docs/recipes/random-instances.js +0 -25
- package/src/docs/recipes/recipes.mdx +0 -81
- package/src/docs/recipes/recipes.stories.js +0 -37
- package/src/docs/recipes/remove-instance.js +0 -52
- package/src/docs/recipes/states.js +0 -64
- package/src/docs/ui/button.js +0 -28
- package/src/docs/ui/form.stories.js +0 -55
- package/src/docs/ui-chooser.jsx +0 -6
- package/src/docs/utils/data-structures/object.mdx +0 -47
- package/src/docs/utils/data-structures/objects.mdx +0 -30
- package/src/docs/utils/functions/functions.mdx +0 -34
- package/src/docs/utils/math/geometry/circle.mdx +0 -55
- package/src/docs/utils/math/geometry/point.mdx +0 -38
- package/src/docs/utils/math/geometry/rectangle.mdx +0 -24
- package/src/docs/utils/math/geometry/segment.mdx +0 -55
- package/src/docs/utils/math/geometry/triangle.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/2d.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/quaternion.mdx +0 -21
- package/src/docs/utils/math/linear-algebra/quaternions.mdx +0 -22
- package/src/docs/utils/math/linear-algebra/vector.mdx +0 -177
- package/src/docs/utils/math/linear-algebra/vectors.mdx +0 -58
- package/src/docs/utils/math/numbers.mdx +0 -76
- package/src/docs/utils/math/random.mdx +0 -35
- package/src/docs/utils/math/statistics.mdx +0 -38
- package/src/docs/utils/math/trigonometry.mdx +0 -85
- package/src/docs/utils/physics/friction.mdx +0 -20
- package/src/docs/utils/physics/gravity.mdx +0 -28
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
angle,
|
|
5
|
-
clamp,
|
|
6
|
-
conjugate,
|
|
7
|
-
divide,
|
|
8
|
-
fromAngle,
|
|
9
|
-
magnitude,
|
|
10
|
-
mod,
|
|
11
|
-
multiply,
|
|
12
|
-
normalize,
|
|
13
|
-
rotate,
|
|
14
|
-
setAngle,
|
|
15
|
-
setMagnitude,
|
|
16
|
-
shift,
|
|
17
|
-
toCartesian,
|
|
18
|
-
toCylindrical,
|
|
19
|
-
toPolar,
|
|
20
|
-
toString,
|
|
21
|
-
unit,
|
|
22
|
-
} from '@inglorious/utils/math/linear-algebra/vector'
|
|
23
|
-
import { pi, cos, sin } from '@inglorious/utils/math/trigonometry'
|
|
24
|
-
|
|
25
|
-
<Meta title="Utils/Math/Linear Algebra/Vector" />
|
|
26
|
-
|
|
27
|
-
# Vector
|
|
28
|
-
|
|
29
|
-
Functions that deal with a single vector.
|
|
30
|
-
|
|
31
|
-
## Angle
|
|
32
|
-
|
|
33
|
-
Returns the angle of a vector, calculated as the `atan2` between the last and first coordinate.
|
|
34
|
-
|
|
35
|
-
<code>angle([1, 1]) == {angle([1, 1]).toFixed(3)}</code> (≈π/4)
|
|
36
|
-
|
|
37
|
-
<code>angle([1, 0, 1]) == {angle([1, 0, 1]).toFixed(3)}</code> (≈π/4)
|
|
38
|
-
|
|
39
|
-
## Clamp
|
|
40
|
-
|
|
41
|
-
Limits the magnitude of a vector to a lower and upper bound.
|
|
42
|
-
|
|
43
|
-
<code>clamp([6, 8], 0, 5) == {toString(clamp([6, 8], 0, 5))}</code>
|
|
44
|
-
|
|
45
|
-
<code>clamp([3, 4], 0, 5) == {toString(clamp([3, 4], 0, 5))}</code>
|
|
46
|
-
|
|
47
|
-
Bounds can be specified as other vectors too.
|
|
48
|
-
|
|
49
|
-
<code>clamp([6, 8], [0, 0], [3, 4]) == {toString(clamp([6, 8], [0, 0], [3, 4]))}</code>
|
|
50
|
-
|
|
51
|
-
## Conjugate
|
|
52
|
-
|
|
53
|
-
Flips the sign of all coordinates except the first one.
|
|
54
|
-
|
|
55
|
-
<code>conjugate([1, 2, 3]) == {toString(conjugate([1, 2, 3]))}</code>
|
|
56
|
-
|
|
57
|
-
## Divide
|
|
58
|
-
|
|
59
|
-
Divides any vector by a scalar.
|
|
60
|
-
|
|
61
|
-
<code>divide([4, 8, 12], 4) == {toString(divide([4, 8, 12], 4))}</code>
|
|
62
|
-
|
|
63
|
-
## From Angle
|
|
64
|
-
|
|
65
|
-
Creates a 3D unit vector from a given angle.
|
|
66
|
-
|
|
67
|
-
<code>fromAngle(pi() / 4) == {toString(fromAngle(pi() / 4))}</code>
|
|
68
|
-
|
|
69
|
-
## Length
|
|
70
|
-
|
|
71
|
-
Alias of `magnitude`.
|
|
72
|
-
|
|
73
|
-
## Magnitude
|
|
74
|
-
|
|
75
|
-
Computes the magnitude of any vector (alias `length`).
|
|
76
|
-
|
|
77
|
-
<code>magnitude([3, 4]) == {magnitude([3, 4])}</code>
|
|
78
|
-
|
|
79
|
-
## Mod
|
|
80
|
-
|
|
81
|
-
Applies the `mod` operator on any vector (alias `remainder`).
|
|
82
|
-
|
|
83
|
-
<code>mod([10, 12, -18], 12) == {toString(mod([10, 12, -18], 12))}</code>
|
|
84
|
-
|
|
85
|
-
## Multiply
|
|
86
|
-
|
|
87
|
-
Multiplies a vector with a scalar (alias `times`).
|
|
88
|
-
|
|
89
|
-
<code>multiply([1, 2, 3], 4) == {toString(multiply([1, 2, 3], 4))}</code>
|
|
90
|
-
|
|
91
|
-
## Normalize
|
|
92
|
-
|
|
93
|
-
Gives the vector unit length while maintaining its angle.
|
|
94
|
-
|
|
95
|
-
<code>normalize([3, 4]) == {toString(normalize([3, 4]), 1)}</code>
|
|
96
|
-
|
|
97
|
-
<code>normalize([-3, -4]) == {toString(normalize([-3, -4]), 1)}</code>
|
|
98
|
-
|
|
99
|
-
## Remainder
|
|
100
|
-
|
|
101
|
-
Alias of `mod`.
|
|
102
|
-
|
|
103
|
-
## Rotate
|
|
104
|
-
|
|
105
|
-
Adds the given angle to a 2D or 3D vector using quaternions.
|
|
106
|
-
|
|
107
|
-
<code>rotate([1, 0], 0) == {toString(rotate([1, 0], 0))}</code>
|
|
108
|
-
|
|
109
|
-
<code>rotate([1, 0], pi() / 4) == {toString(rotate([1, 0], pi() / 4), 3)}</code> (≈[cos(π/4), sin(π/4)])
|
|
110
|
-
|
|
111
|
-
<code>rotate([1, 0, 0], 0) == {toString(rotate([1, 0, 0], 0))}</code>
|
|
112
|
-
|
|
113
|
-
<code>rotate([1, 0, 0], pi() / 4) == {toString(rotate([1, 0, 0], pi() / 4), 3)}</code> (≈[cos(π/4), 0, sin(π/4)])
|
|
114
|
-
|
|
115
|
-
<code>rotate([-1, 0, 0], pi() / 4) == {toString(rotate([-1, 0, 0], pi() / 4), 3)}</code> (≈[cos(-3/4*π), 0, sin(-3/4*π)])
|
|
116
|
-
|
|
117
|
-
## Set Angle
|
|
118
|
-
|
|
119
|
-
Changes the angle of a vector.
|
|
120
|
-
|
|
121
|
-
<code>setAngle([cos(pi() / 4), 0, sin(pi() / 4)], pi() / 2) == {toString(setAngle([cos(pi() / 4), 0, sin(pi() / 4)], pi() / 2))}</code>
|
|
122
|
-
|
|
123
|
-
## Set Magnitude
|
|
124
|
-
|
|
125
|
-
Changes the magnitude of any vector, keeping its angle.
|
|
126
|
-
|
|
127
|
-
<code>setMagnitude([3, 4], 10) == {toString(setMagnitude([3, 4], 10))}</code>
|
|
128
|
-
|
|
129
|
-
<code>setMagnitude([-3, -4], 10) == {toString(setMagnitude([-3, -4], 10))}</code>
|
|
130
|
-
|
|
131
|
-
## Shift
|
|
132
|
-
|
|
133
|
-
Moves coordinates around by a certain index.
|
|
134
|
-
|
|
135
|
-
<code>shift([1, 2, 3, 4, 5], 2) == {toString(shift([1, 2, 3, 4, 5], 2))}</code>
|
|
136
|
-
|
|
137
|
-
## Times
|
|
138
|
-
|
|
139
|
-
Alias of `multiply`.
|
|
140
|
-
|
|
141
|
-
## To Cartesian
|
|
142
|
-
|
|
143
|
-
Converts a 2D polar vector into cartesian coordinates.
|
|
144
|
-
|
|
145
|
-
<code>toCartesian([2 ** 0.5, pi() / 4]) == {toString(toCartesian([2 ** 0.5, pi() / 4]))}</code>
|
|
146
|
-
|
|
147
|
-
## To Cylindrical
|
|
148
|
-
|
|
149
|
-
Converts a 3D cartesian vector to cylindrical coordinates.
|
|
150
|
-
|
|
151
|
-
<code>toCylindrical([1, 1, 1]) == {toString(toCylindrical([1, 1, 1]), 3)}</code>
|
|
152
|
-
|
|
153
|
-
## To Polar
|
|
154
|
-
|
|
155
|
-
Converts a 2D cartesian vector to polar coordinates.
|
|
156
|
-
|
|
157
|
-
<code>toPolar([1, 1]) == {toString(toPolar([1, 1]))}</code> (≈[√2, π/4])
|
|
158
|
-
|
|
159
|
-
## To Spherical
|
|
160
|
-
|
|
161
|
-
TBD
|
|
162
|
-
|
|
163
|
-
## To String
|
|
164
|
-
|
|
165
|
-
Returns a string representation of any vector, up to optional decimal points.
|
|
166
|
-
|
|
167
|
-
<code>toString([1, 0]) == "{toString([1, 0])}"</code>
|
|
168
|
-
|
|
169
|
-
<code>toString([cos(pi() / 4), 0], 3) == "{toString([cos(pi() / 4), 0], 3)}"</code>
|
|
170
|
-
|
|
171
|
-
## Unit
|
|
172
|
-
|
|
173
|
-
Returns a unit 3D vector at a given optional angle.
|
|
174
|
-
|
|
175
|
-
<code>unit() == {toString(unit())}</code>
|
|
176
|
-
|
|
177
|
-
<code>unit(pi() / 2) == {toString(unit(pi() / 2))}</code>
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
cross,
|
|
5
|
-
dot,
|
|
6
|
-
scalarProduct,
|
|
7
|
-
subtract,
|
|
8
|
-
sum,
|
|
9
|
-
vectorProduct,
|
|
10
|
-
} from '@inglorious/utils/math/linear-algebra/vectors'
|
|
11
|
-
import { toString } from '@inglorious/utils/math/linear-algebra/vector'
|
|
12
|
-
import { pi, cos, sin } from '@inglorious/utils/math/trigonometry'
|
|
13
|
-
|
|
14
|
-
<Meta title="Utils/Math/Linear Algebra/Vectors" />
|
|
15
|
-
|
|
16
|
-
# Vectors
|
|
17
|
-
|
|
18
|
-
Functions that deal with a multiple vectors.
|
|
19
|
-
|
|
20
|
-
## Cross
|
|
21
|
-
|
|
22
|
-
Performs the cross product between multiple vectors (alias `vectorProduct`).
|
|
23
|
-
|
|
24
|
-
<code>cross([1, 2, 3], [4, 5, 6]) == {toString(cross([1, 2, 3], [4, 5, 6]))}</code>
|
|
25
|
-
|
|
26
|
-
<code>cross([1, 2, 3], [4, 5, 6], [7, 8, 9]) == {toString(cross([1, 2, 3], [4, 5, 6], [7, 8, 9]))}</code>
|
|
27
|
-
|
|
28
|
-
## Dot
|
|
29
|
-
|
|
30
|
-
Performs the dot product between multiple vectors (alias `scalarProduct`).
|
|
31
|
-
|
|
32
|
-
<code>dot([1, 2, 3], [4, 5, 6]) == {dot([1, 2, 3], [4, 5, 6])}</code>
|
|
33
|
-
|
|
34
|
-
<code>dot([1, 2, 3], [4, 5, 6], [7, 8, 9]) == {dot([1, 2, 3], [4, 5, 6], [7, 8, 9])}</code>
|
|
35
|
-
|
|
36
|
-
## Scalar Product
|
|
37
|
-
|
|
38
|
-
Alias of `dot`.
|
|
39
|
-
|
|
40
|
-
## Subtract
|
|
41
|
-
|
|
42
|
-
Subtracts all other vectors from the first one.
|
|
43
|
-
|
|
44
|
-
<code>subtract([1, 2, 3], [4, 5, 6]) == {toString(subtract([1, 2, 3], [4, 5, 6]))}</code>
|
|
45
|
-
|
|
46
|
-
<code>subtract([1, 2, 3], [4, 5, 6], [7, 8, 9]) == {toString(subtract([1, 2, 3], [4, 5, 6], [7, 8, 9]))}</code>
|
|
47
|
-
|
|
48
|
-
## Sum
|
|
49
|
-
|
|
50
|
-
Sums all coordinates together.
|
|
51
|
-
|
|
52
|
-
<code>sum([1, 2, 3], [4, 5, 6]) == {toString(sum([1, 2, 3], [4, 5, 6]))}</code>
|
|
53
|
-
|
|
54
|
-
<code>sum([1, 2, 3], [4, 5, 6], [7, 8, 9]) == {toString(sum([1, 2, 3], [4, 5, 6], [7, 8, 9]))}</code>
|
|
55
|
-
|
|
56
|
-
## Vector Product
|
|
57
|
-
|
|
58
|
-
Alias of `cross`.
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { toString } from '@inglorious/utils/data-structures/boolean.js'
|
|
4
|
-
import { abs, clamp, isClose, mod, sign, sqrt } from '@inglorious/utils/math/numbers.js'
|
|
5
|
-
|
|
6
|
-
<Meta title="Utils/Math/Numbers" />
|
|
7
|
-
|
|
8
|
-
# Numbers
|
|
9
|
-
|
|
10
|
-
Basic functions that deal with numbers.
|
|
11
|
-
|
|
12
|
-
## Abs
|
|
13
|
-
|
|
14
|
-
Returns the absolute value of any number.
|
|
15
|
-
|
|
16
|
-
<code>abs(42) == {abs(42)}</code>
|
|
17
|
-
|
|
18
|
-
<code>abs(-42) == {abs(-42)}</code>
|
|
19
|
-
|
|
20
|
-
## Clamp
|
|
21
|
-
|
|
22
|
-
Limits the given number to the specified bounds.
|
|
23
|
-
|
|
24
|
-
<code>clamp(42, 0, 100) == {clamp(42, 0, 100)}</code>
|
|
25
|
-
|
|
26
|
-
<code>clamp(-42, 0, 100) == {clamp(-42, 0, 100)}</code>
|
|
27
|
-
|
|
28
|
-
<code>clamp(142, 0, 100) == {clamp(142, 0, 100)}</code>
|
|
29
|
-
|
|
30
|
-
## Is Close
|
|
31
|
-
|
|
32
|
-
Checks if two numbers are close to each other, given some tolerance (which is *0.1* by default).
|
|
33
|
-
|
|
34
|
-
<code>isClose(42, 42.1, 0.2) == {toString(isClose(42, 42.1, 0.2))}</code>
|
|
35
|
-
|
|
36
|
-
<code>isClose(42, 43, 0.2) == {toString(isClose(42, 43, 0.2))}</code>
|
|
37
|
-
|
|
38
|
-
<code>isClose(42, 42.1) == {toString(isClose(42, 42.1))}</code>
|
|
39
|
-
|
|
40
|
-
## Mod
|
|
41
|
-
|
|
42
|
-
Computes the remainder of the integer division, always giving a positive value (alias `remainder`).
|
|
43
|
-
|
|
44
|
-
<code>mod(2, 2) == {mod(2, 2)}</code>
|
|
45
|
-
|
|
46
|
-
<code>mod(3, 2) == {mod(3, 2)}</code>
|
|
47
|
-
|
|
48
|
-
<code>mod(-3, 2) == {mod(-3, 2)}</code>
|
|
49
|
-
|
|
50
|
-
<code>mod(5 / 4, 1) == {mod(5 / 4, 1)}</code> (=1/4)
|
|
51
|
-
|
|
52
|
-
<code>mod(5 / 4, 1) == {mod(5 / 4, 1)}</code> (=1/4)
|
|
53
|
-
|
|
54
|
-
<code>mod(13 / 4, 1) == {mod(13 / 4, 1)}</code> (=1/4)
|
|
55
|
-
|
|
56
|
-
<code>mod(-5 / 4, 1) == {mod(-5 / 4, 1)}</code> (=3/4)
|
|
57
|
-
|
|
58
|
-
## Remainder
|
|
59
|
-
|
|
60
|
-
Alias of `mod`.
|
|
61
|
-
|
|
62
|
-
## Sign
|
|
63
|
-
|
|
64
|
-
Returns +1 if the given number is positive, -1 if negative, 0 otherwise.
|
|
65
|
-
|
|
66
|
-
<code>sign(42) == {sign(42)}</code>
|
|
67
|
-
|
|
68
|
-
<code>sign(-42) == {sign(-42)}</code>
|
|
69
|
-
|
|
70
|
-
<code>sign(0) == {sign(0)}</code>
|
|
71
|
-
|
|
72
|
-
## Sqrt
|
|
73
|
-
|
|
74
|
-
Return the square roo of the given number.
|
|
75
|
-
|
|
76
|
-
<code>sqrt(9) == {sqrt(9)}</code>
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { random, randomBinomial } from '@inglorious/utils/math/rng'
|
|
4
|
-
|
|
5
|
-
<Meta title="Utils/Math/Rng" />
|
|
6
|
-
|
|
7
|
-
# Rng
|
|
8
|
-
|
|
9
|
-
Random number generators.
|
|
10
|
-
|
|
11
|
-
## Random
|
|
12
|
-
|
|
13
|
-
Generates a random number with optional parameters that specify range and step.
|
|
14
|
-
|
|
15
|
-
No parameters will generate a random number in the range `[0, 1)` (zero included, one excluded).
|
|
16
|
-
|
|
17
|
-
<code>random() == {random()}</code>
|
|
18
|
-
|
|
19
|
-
A parameter `n` means the random number will be an integer in the range `[0, n]` (zero and `n` included).
|
|
20
|
-
|
|
21
|
-
<code>random(6) == {random(6)}</code>
|
|
22
|
-
|
|
23
|
-
Two parameters `n` and `m` means the random number will be an integer in the range `[n, m]` (both numbers included).
|
|
24
|
-
|
|
25
|
-
<code>random(1, 6) == {random(1, 6)}</code>
|
|
26
|
-
|
|
27
|
-
A third parameter allows to specify the step.
|
|
28
|
-
|
|
29
|
-
<code>random(2, 6, 2) == {random(2, 6, 2)}</code>
|
|
30
|
-
|
|
31
|
-
## Random Binomial
|
|
32
|
-
|
|
33
|
-
Generates a random number in the range `(-1, 1)` (minus one excluded, one excluded), with probability following the [Binomial Distribution](https://en.wikipedia.org/wiki/Binomial_distribution).
|
|
34
|
-
|
|
35
|
-
<code>randomBinomial() == {randomBinomial()}</code>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { mean, median, mode } from '@inglorious/utils/math/statistics'
|
|
4
|
-
import { toString } from '@inglorious/utils/data-structures/object'
|
|
5
|
-
|
|
6
|
-
<Meta title="Utils/Math/Statistics" />
|
|
7
|
-
|
|
8
|
-
# Statistics
|
|
9
|
-
|
|
10
|
-
Basic statistics functions.
|
|
11
|
-
|
|
12
|
-
## Average
|
|
13
|
-
|
|
14
|
-
Alias of `mean`.
|
|
15
|
-
|
|
16
|
-
## Mean
|
|
17
|
-
|
|
18
|
-
Returns the mathematical mean of a list of numbers.
|
|
19
|
-
|
|
20
|
-
<code>mean(1, 3, 2) == {mean(1, 3, 2)}</code>
|
|
21
|
-
|
|
22
|
-
## Median
|
|
23
|
-
|
|
24
|
-
Returns the median value from a list of numbers.
|
|
25
|
-
|
|
26
|
-
When the list has odd length, the median is whatever value sits in between:
|
|
27
|
-
|
|
28
|
-
<code>median(1, 3, 2) == {median(1, 3, 2)}</code>
|
|
29
|
-
|
|
30
|
-
When the list has an even length, the median is the average of its two values in between (in this case, 2 and 3):
|
|
31
|
-
|
|
32
|
-
<code>median(1, 3, 2, 4) == {median(1, 3, 2, 4)}</code>
|
|
33
|
-
|
|
34
|
-
## Mode
|
|
35
|
-
|
|
36
|
-
Returns the most frequent item in a list of values.
|
|
37
|
-
|
|
38
|
-
<code>mode("rarely", "sometimes", "sometimes", "always") == {toString(mode("rarely", "sometimes", "sometimes", "always"))}</code>
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { atan2, cos, cosine, pi, sin, sine, toDegrees, toRadians, toRange } from '@inglorious/utils/math/trigonometry'
|
|
4
|
-
|
|
5
|
-
<Meta title="Utils/Math/Trigonometry" />
|
|
6
|
-
|
|
7
|
-
# Trigonometry
|
|
8
|
-
|
|
9
|
-
Basic trigonometry functions.
|
|
10
|
-
|
|
11
|
-
## Atan2
|
|
12
|
-
|
|
13
|
-
Returns the atan2 of y and x.
|
|
14
|
-
|
|
15
|
-
<code>atan2(0, 0) == {atan2(0, 0)}</code>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<code>atan2(0, pi() / 2) == {atan2(0, pi() / 2)}</code>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<code>atan2(pi() / 2, 0) == {atan2(pi() / 2, 0)}</code>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<code>atan2(pi() / 2, pi() / 2) == {atan2(pi() / 2, pi() / 2)}</code>
|
|
25
|
-
|
|
26
|
-
## Cos
|
|
27
|
-
|
|
28
|
-
Returns the cosine of an angle in radians (alias `cosine`).
|
|
29
|
-
|
|
30
|
-
<code>cos(0) == {cos(0)}</code>
|
|
31
|
-
|
|
32
|
-
<code>cos(pi() / 4) == {cos(pi() / 4).toFixed(3)}</code>
|
|
33
|
-
|
|
34
|
-
<code>cos(pi() / 2) == {cos(pi() / 2)}</code> (≈0)
|
|
35
|
-
|
|
36
|
-
## Cosine
|
|
37
|
-
|
|
38
|
-
Alias of `cos`.
|
|
39
|
-
|
|
40
|
-
## Pi
|
|
41
|
-
|
|
42
|
-
Returns an approximation of π.
|
|
43
|
-
|
|
44
|
-
<code>pi() == {pi()}</code> (≈π)
|
|
45
|
-
|
|
46
|
-
## Sin
|
|
47
|
-
|
|
48
|
-
Return the sine of an angle in degrees (alias `sine`).
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<code>sin(0) == {sin(0)}</code>
|
|
52
|
-
|
|
53
|
-
<code>sin(pi() / 4) == {sin(pi() / 4).toFixed(3)}</code>
|
|
54
|
-
|
|
55
|
-
<code>sin(pi() / 2) == {sin(pi() / 2)}</code>
|
|
56
|
-
|
|
57
|
-
## Sine
|
|
58
|
-
|
|
59
|
-
Alias of `sin`.
|
|
60
|
-
|
|
61
|
-
## To Degrees
|
|
62
|
-
|
|
63
|
-
Converts radians into degrees.
|
|
64
|
-
|
|
65
|
-
<code>toDegrees(pi() / 4) == {toDegrees(pi() / 4)}</code>
|
|
66
|
-
|
|
67
|
-
## To Radians
|
|
68
|
-
|
|
69
|
-
Converts degrees into radians.
|
|
70
|
-
|
|
71
|
-
<code>toRadians(45) == {toRadians(45)}</code> (≈π/4)
|
|
72
|
-
|
|
73
|
-
## To Range
|
|
74
|
-
|
|
75
|
-
Clamps any angle into the range [-π, π].
|
|
76
|
-
|
|
77
|
-
<code>toRange(5 / 4 * pi()) == {toRange((5 / 4) * pi())}</code> (≈-3/4π)
|
|
78
|
-
|
|
79
|
-
<code>toRange(13 / 4 * pi()) == {toRange((13 / 4) * pi())}</code> (≈-3/4π)
|
|
80
|
-
|
|
81
|
-
<code>toRange(-5 / 4 * pi()) == {toRange((-5 / 4) * pi())}</code> (≈3/4π)
|
|
82
|
-
|
|
83
|
-
<code>toRange(-13 / 4 * pi()) == {toRange((-13 / 4) * pi())}</code> (≈3/4π)
|
|
84
|
-
|
|
85
|
-
<code>toRange(3 / 4 * pi()) == {toRange((3 / 4) * pi())}</code> (≈3/4π)
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { applyFriction } from '@inglorious/utils/physics/friction'
|
|
4
|
-
import { toString } from '@inglorious/utils/math/linear-algebra/vector'
|
|
5
|
-
|
|
6
|
-
<Meta title="Utils/Physics/Friction" />
|
|
7
|
-
|
|
8
|
-
# Friction
|
|
9
|
-
|
|
10
|
-
Friction is a force that resists movement. It is directly related to the body's momentum, which is mass times velocity, but for our purposes we can safely ignore mass and apply it directly to velocity.
|
|
11
|
-
|
|
12
|
-
A friction that is equal to the velocity's magnitude will eventually stop the body after some time.
|
|
13
|
-
|
|
14
|
-
<code>applyFriction(\{ velocity: [8, 0, 6], friction: 5 \}, \{ dt: 1 \}) == {toString(applyFriction({ velocity: [8, 0, 6], friction: 5 }, { dt: 1 }))}</code>
|
|
15
|
-
|
|
16
|
-
<code>applyFriction(\{ velocity: [8, 0, 6], friction: 5 \}, \{ dt: 2 \}) == {toString(applyFriction({ velocity: [8, 0, 6], friction: 5 }, { dt: 2 }))}</code>
|
|
17
|
-
|
|
18
|
-
When the body is still then no friction will be applied:
|
|
19
|
-
|
|
20
|
-
<code>applyFriction(\{ velocity: [0, 0, 0], friction: 5 \}, \{ dt: 1 \}) == {toString(applyFriction({ velocity: [0, 0, 0], friction: 5 }, { dt: 1 }))}</code>
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Meta } from '@storybook/blocks'
|
|
2
|
-
|
|
3
|
-
import { applyGravity } from '@inglorious/utils/physics/gravity'
|
|
4
|
-
import { toString } from '@inglorious/utils/data-structures/object'
|
|
5
|
-
|
|
6
|
-
<Meta title="Utils/Physics/Gravity" />
|
|
7
|
-
|
|
8
|
-
# Gravity
|
|
9
|
-
|
|
10
|
-
We can consider gravity as a constant acceleration downards. [This video](https://youtu.be/hG9SzQxaCm8) shows how to calculate this acceleration based on the curve that we want our character to draw when jumping. Also, it rightfully warns to keep jump parameters separate from our world coordinates. That's why we need a specific acceleration and velocity to model our jumps, while directly integrating into the position vector.
|
|
11
|
-
|
|
12
|
-
- `maxJump` is the maximum height that we want to achieve;
|
|
13
|
-
- `maxLeap` is the maximum distance we want to cover with a jump;
|
|
14
|
-
- `maxSpeed` is the maximum horizontal speed when running;
|
|
15
|
-
- `vy` is the current jump velocity;
|
|
16
|
-
- `position[Y]` is the current world height.
|
|
17
|
-
|
|
18
|
-
<code>applyGravity(\{ maxJump: 10, maxLeap: 10, maxSpeed: 10, vy: 10, position: [0,10,0] \}, \{ dt: 1 \}) == {toString(applyGravity({ maxJump: 10, maxLeap: 10, maxSpeed: 10, vy: 10, position: [0,10,0] }, { dt: 1 }))}</code>
|
|
19
|
-
|
|
20
|
-
Not specifying `maxJump` and `maxSpeed` will result in no gravity being applied:
|
|
21
|
-
|
|
22
|
-
<code>applyGravity(\{ maxLeap: 10, maxSpeed: 10, vy: 10, position: [0,10,0] \}, \{ dt: 1 \}) == {toString(applyGravity({ maxLeap: 10, maxSpeed: 10, vy: 10, position: [0,10,0] }, { dt: 1 }))}</code>
|
|
23
|
-
|
|
24
|
-
<code>applyGravity(\{ maxJump: 10, maxSpeed: 10, vy: 10, position: [0,10,0] \}, \{ dt: 1 \}) == {toString(applyGravity({ maxJump: 10, maxLeap: 10, vy: 10, position: [0,10,0] }, { dt: 1 }))}</code>
|
|
25
|
-
|
|
26
|
-
While not specifying `maxLeap` will result in an error, since we have to divide by this quantity:
|
|
27
|
-
|
|
28
|
-
<code>applyGravity(\{ maxJump: 10, maxSpeed: 10, vy: 10, position: [0,10,0] \}, \{ dt: 1 \}) == Error(['maxLeap'])</code>
|