mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
76 lines
1.8 KiB
Lua
76 lines
1.8 KiB
Lua
--!optimize 2
|
|
--!native
|
|
--!strict
|
|
|
|
--My versions
|
|
|
|
type EaseFunction = (n: number) -> number
|
|
type LinearFunction = (a: number, b: number, t: number) -> number
|
|
|
|
export type RotationMatrix = {
|
|
Ixx: number,
|
|
Ixy: number,
|
|
Iyx: number,
|
|
Iyy: number,
|
|
Izx: number,
|
|
Izy: number
|
|
}
|
|
|
|
export type Scalar = {
|
|
Distance: number,
|
|
Center: Vector2,
|
|
Rotation: number
|
|
}
|
|
|
|
export type Math = {
|
|
Linear: LinearFunction,
|
|
InOutBack: EaseFunction,
|
|
OutBounce: EaseFunction,
|
|
InQuad: EaseFunction,
|
|
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
|
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar
|
|
}
|
|
|
|
local Math = {} :: Math
|
|
|
|
function Math.RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
|
|
return {
|
|
Ixx = math.cos(Z)*math.cos(X)-math.sin(Z)*math.sin(X)*math.sin(Y);
|
|
Ixy = math.cos(Z)*math.sin(X)*math.sin(Y)+math.sin(Z)*math.cos(X);
|
|
Iyx = -math.cos(Z)*math.sin(X)-math.sin(Z)*math.cos(X)*math.sin(Y);
|
|
Iyy = math.cos(Z)*math.cos(X)*math.sin(Y)-math.sin(Z)*math.sin(X);
|
|
Izx = -math.sin(Z)*math.cos(Y);
|
|
Izy = math.cos(Z)*math.sin(Y)
|
|
}
|
|
end
|
|
|
|
function Math.Scalar(X1: number, Y1: number, X2: number, Y2: number): Scalar
|
|
return {
|
|
Distance = math.sqrt((X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2));
|
|
Center = Vector2.new((X1+X2)/2,(Y1+Y2)/2);
|
|
Rotation = math.deg(math.atan2(Y1-Y2,X1-X2))
|
|
}
|
|
end
|
|
|
|
--My versions
|
|
function Math.Linear(a,b,t)
|
|
return a-a*t+b*t
|
|
end
|
|
|
|
local c = 2.59491
|
|
function Math.InOutBack(n)
|
|
return n<.5 and 2*n*n*(-c+2*n+2*c*n) or 3*(-1+n)*(-1+n)*(-2-c+2*n+2*c*n)
|
|
end
|
|
|
|
local n1, d1 = 7.5625, 2.75
|
|
function Math.OutBounce(n)
|
|
return (n<0.363636 and n*n*n1 or
|
|
n<0.727273 and (.75*(1.*d1-2.*n*n1)) or
|
|
n<0.909091 and (.9375*(1.*d1-2.4*n*n1)/d1)) or (.984375*(1.*d1-2.66667*n*n1))/d1
|
|
end
|
|
|
|
function Math.InQuad(n)
|
|
return n*n
|
|
end
|
|
|
|
return Math |