Rotation matrix UI and Interactions dir

This commit is contained in:
2024-04-19 00:24:25 -04:00
parent a9391feb87
commit e76e38bf0f
7 changed files with 181 additions and 67 deletions

File diff suppressed because one or more lines are too long

View File

@@ -4,7 +4,39 @@
--Not a good idea to call modules from other services here --Not a good idea to call modules from other services here
--Who said UI on here cant look like a web design lole, type RotationMatrix = {
Ixx: number,
Ixy: number,
Iyx: number,
Iyy: number,
Izx: number,
Izy: number
}
type Scalar = {
Distance: number,
Center: Vector2,
Rotation: number
}
type Stepped = RBXScriptConnection
type GuiDependencies = {
IntroGui: ScreenGui,
Frame: Frame,
FrameGradient: UIGradient,
TextShadow: TextLabel,
ShadowGradient: UIGradient,
FrameworkText: TextLabel,
SandboxText: TextLabel,
DeveloperText: TextLabel,
Xframe: Frame,
Yframe: Frame,
Zframe: Frame,
Xframe_text: TextLabel,
Yframe_text: TextLabel,
Zframe_text: TextLabel,
}
local RS = game:GetService("RunService") local RS = game:GetService("RunService")
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
@@ -12,101 +44,138 @@ local TS = game:GetService("TestService")
local LoadingFun = true local LoadingFun = true
local function GuiDependencies(IntroGui: ScreenGui) local function GuiDependencies(IntroGui: ScreenGui): GuiDependencies
IntroGui.Enabled = true IntroGui.Enabled = true
local Frame = IntroGui:WaitForChild("Frame") local Frame = IntroGui:WaitForChild("Frame") :: Frame
local Viewport = Frame:WaitForChild("ViewportFrame")
local FrameGradient = Frame:WaitForChild("UIGradient") local FrameGradient = Frame:WaitForChild("UIGradient") :: UIGradient
local TextShadow = Frame:WaitForChild("TextShadow") local TextShadow = Frame:WaitForChild("TextShadow") :: TextLabel
local FrameworkText = Frame:WaitForChild("Framework") local FrameworkText = Frame:WaitForChild("Framework") :: TextLabel
local SandboxText = Frame:WaitForChild("Sandbox") local SandboxText = Frame:WaitForChild("Sandbox") :: TextLabel
local DeveloperText = Frame:WaitForChild("Developer") local DeveloperText = Frame:WaitForChild("Developer") :: TextLabel
local ShadowGradient = TextShadow:WaitForChild("UIGradient") local ShadowGradient = TextShadow:WaitForChild("UIGradient") :: UIGradient
local ViewportCamera = Instance.new("Camera") local Xframe = Frame:WaitForChild("X") :: Frame
ViewportCamera.FieldOfView = 50 local Yframe = Frame:WaitForChild("Y") :: Frame
ViewportCamera.Parent = Viewport local Zframe = Frame:WaitForChild("Z") :: Frame
Viewport.CurrentCamera = ViewportCamera
local GL_Cube = Viewport:WaitForChild("GL_Cube") local Xframe_text = Frame:WaitForChild("X_text") :: TextLabel
local Yframe_text = Frame:WaitForChild("Y_text") :: TextLabel
local Zframe_text = Frame:WaitForChild("Z_text") :: TextLabel
return { return {
IntroGui = IntroGui, IntroGui = IntroGui,
Frame = Frame, Frame = Frame,
Viewport = Viewport,
ViewportCamera = ViewportCamera,
GL_Cube = GL_Cube,
FrameGradient = FrameGradient, FrameGradient = FrameGradient,
TextShadow = TextShadow, TextShadow = TextShadow,
ShadowGradient = ShadowGradient, ShadowGradient = ShadowGradient,
FrameworkText = FrameworkText, FrameworkText = FrameworkText,
SandboxText = SandboxText, SandboxText = SandboxText,
DeveloperText = DeveloperText DeveloperText = DeveloperText,
Xframe = Xframe,
Yframe = Yframe,
Zframe = Zframe,
Xframe_text = Xframe_text,
Yframe_text = Yframe_text,
Zframe_text = Zframe_text,
} }
end end
type GUIs = typeof(GuiDependencies) local function GUI_LoadFinish(Stepped: Stepped, Gui: GuiDependencies) --We can now access the framework
type Stepped = RBXScriptConnection
local function GUI_LoadFinish(Stepped: Stepped, Gui: GUIs) --We can now access the framework
--Image if we had HTML and CSS... --Image if we had HTML and CSS...
local Tween = require(Storage:WaitForChild("Tween")) local Tween = require(Storage:WaitForChild("Tween"))
local EaseStyle = Enum.EasingStyle.Linear local FrameTween_Constructor = Tween.constructor(TweenInfo.new(1, Enum.EasingStyle.Linear), Gui.Frame, {
local FrameTween_Constructor = Tween.constructor(TweenInfo.new(1, EaseStyle), Gui.Frame, {
BackgroundTransparency = 1 BackgroundTransparency = 1
}) })
local DeveloperTween_Constructor = Tween.constructor(TweenInfo.new(1, EaseStyle), Gui.DeveloperText, { local DeveloperTween_Constructor = Tween.constructor(TweenInfo.new(1, Enum.EasingStyle.Linear), Gui.DeveloperText, {
TextTransparency = 1 TextTransparency = 1
}) })
local ViewportFrame_Constructor = Tween.constructor(TweenInfo.new(3, EaseStyle), Gui.Viewport, {
Position = UDim2.fromScale(0.5, 2) --Guaranteed off screen
})
FrameTween_Constructor:Start() local FrameTween = FrameTween_Constructor:Start()
DeveloperTween_Constructor:Start() DeveloperTween_Constructor:Start()
local ViewportTween = ViewportFrame_Constructor:Start() --The longest tween
--Text deleting effect --Text deleting effect
task.spawn(function() task.spawn(function()
local sandbox_text_len = #Gui.SandboxText.Text for n: number = #Gui.SandboxText.Text, 1, -1 do --"A sandbox experience" has the longest text
Gui.SandboxText.Text = Gui.SandboxText.Text:sub(1,n-1)
for i = sandbox_text_len, 1, -1 do --"A sandbox experience" has the longest text if #Gui.FrameworkText.Text ~= 0 then
local rhpid_text_len = #Gui.FrameworkText.Text Gui.FrameworkText.Text = Gui.FrameworkText.Text:sub(1,n-1)
Gui.SandboxText.Text = Gui.SandboxText.Text:sub(1,i-1)
if rhpid_text_len ~= 0 then
Gui.FrameworkText.Text = Gui.FrameworkText.Text:sub(1,i-1)
Gui.TextShadow.Text = Gui.FrameworkText.Text --heh hack Gui.TextShadow.Text = Gui.FrameworkText.Text --heh hack
end end
task.wait(.05) task.wait(.05)
end end
end) end)
ViewportTween.Completed:Wait() FrameTween.Completed:Wait()
Stepped:Disconnect() Stepped:Disconnect()
Gui.IntroGui:Destroy() --We dont need the intro gui anymore Gui.IntroGui:Destroy() --We dont need the intro gui anymore
end end
type GL_Cube = Instance local function RotationMatrix(X: number, Y: number, Z: number): RotationMatrix
type GL_Side = Instance 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
local function 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
local Size = 300
local WorldSize = 3
return function(IntroGui: ScreenGui, load_elapse_start: number) return function(IntroGui: ScreenGui, load_elapse_start: number)
local Gui = GuiDependencies(IntroGui) local Gui = GuiDependencies(IntroGui)
Gui.ViewportCamera.CFrame = CFrame.lookAt(Gui.GL_Cube.Position-Vector3.new(3,-2.5,5), Gui.GL_Cube.Position) local Stepped = RS.Stepped:Connect(function(Delta: number, dt: number)
local ScreenD = workspace.CurrentCamera.ViewportSize
local CenterX = ScreenD.X/2
local CenterY = ScreenD.Y/1.4
local Cube_CF = Gui.GL_Cube.CFrame local mX = Delta/1.5
local Stepped = RS.Stepped:Connect(function(delta, dt) local mY = Delta/1.5
--Magic number heaven local mZ = -7.65
local d2 = delta*10
Gui.FrameGradient.Rotation=d2
Gui.ShadowGradient.Rotation=d2*4
Gui.GL_Cube.CFrame = Cube_CF*CFrame.Angles(math.rad(100*math.cos(delta/8)), 0, delta/2) local RMatrix = RotationMatrix(mX,mY,mZ)
local X = {Size*RMatrix.Ixx, Size*RMatrix.Ixy}
local Y = {Size*RMatrix.Iyx, Size*RMatrix.Iyy}
local Z = {Size*RMatrix.Izx, Size*RMatrix.Izy}
local AXIS_R_3DScalar_X = Scalar(CenterX+X[1],CenterY+X[2],CenterX,CenterY)
local AXIS_R_3DScalar_Y = Scalar(CenterX+Y[1],CenterY+Y[2],CenterX,CenterY)
local AXIS_R_3DScalar_Z = Scalar(CenterX+Z[1],CenterY+Z[2],CenterX,CenterY)
Gui.Xframe.Size = UDim2.fromOffset(AXIS_R_3DScalar_X.Distance, WorldSize)
Gui.Xframe.Position = UDim2.fromOffset(AXIS_R_3DScalar_X.Center.X, AXIS_R_3DScalar_X.Center.Y)
Gui.Xframe.Rotation = AXIS_R_3DScalar_X.Rotation
Gui.Xframe_text.Position = UDim2.fromOffset(AXIS_R_3DScalar_X.Center.X, AXIS_R_3DScalar_X.Center.Y)
Gui.Xframe_text.Rotation = Gui.Xframe.Rotation
Gui.Yframe.Size = UDim2.fromOffset(AXIS_R_3DScalar_Y.Distance, WorldSize)
Gui.Yframe.Position = UDim2.fromOffset(AXIS_R_3DScalar_Y.Center.X, AXIS_R_3DScalar_Y.Center.Y)
Gui.Yframe.Rotation = AXIS_R_3DScalar_Y.Rotation
Gui.Yframe_text.Position = UDim2.fromOffset(AXIS_R_3DScalar_Y.Center.X, AXIS_R_3DScalar_Y.Center.Y)
Gui.Yframe_text.Rotation = Gui.Yframe.Rotation
Gui.Zframe.Size = UDim2.fromOffset(AXIS_R_3DScalar_Z.Distance, WorldSize)
Gui.Zframe.Position = UDim2.fromOffset(AXIS_R_3DScalar_Z.Center.X, AXIS_R_3DScalar_Z.Center.Y)
Gui.Zframe.Rotation = AXIS_R_3DScalar_Z.Rotation
Gui.Zframe_text.Position = UDim2.fromOffset(AXIS_R_3DScalar_Z.Center.X, AXIS_R_3DScalar_Z.Center.Y)
Gui.Zframe_text.Rotation = Gui.Zframe.Rotation
end) end)
task.spawn(function() task.spawn(function()

View File

@@ -8,7 +8,7 @@ local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Players = game:GetService("Players") local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
local DisabledInStudio = game:GetService("RunService"):IsStudio() local DisabledInStudio = false
local IntroGui = nil local IntroGui = nil
local function LoadedBind() local function LoadedBind()
@@ -21,6 +21,8 @@ local function LoadedBind()
end end
local function LoadingIntroGUI() local function LoadingIntroGUI()
ReplicatedFirst:RemoveDefaultLoadingScreen()
local RunIntroGui = require(script:WaitForChild("IntroGui")) local RunIntroGui = require(script:WaitForChild("IntroGui"))
local Player = Players.LocalPlayer local Player = Players.LocalPlayer
@@ -47,5 +49,3 @@ if not DisabledInStudio then
end end
LoadedBind() LoadedBind()
ReplicatedFirst:RemoveDefaultLoadingScreen()

View File

@@ -2,7 +2,7 @@
--!native --!native
--!strict --!strict
local MapDir = script.Parent local MapDir = script.Parent.Parent
local MainDir = MapDir.Parent local MainDir = MapDir.Parent
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
@@ -19,7 +19,7 @@ type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
Create: (self: ClassConstructor) -> (), Init: (self: ClassConstructor) -> (),
} & Impl_Static_Props } & Impl_Static_Props
type Impl_Static_Props = { type Impl_Static_Props = {
@@ -38,8 +38,6 @@ Lights.__index = Lights
Lights.SwitchAnimationTime = .1 Lights.SwitchAnimationTime = .1
local LightSwitchTween = TweenModule.constructor(TweenInfo.new(Lights.SwitchAnimationTime, Enum.EasingStyle.Linear))
function Lights.constructor(LightSwitches) function Lights.constructor(LightSwitches)
return setmetatable({ return setmetatable({
LightSwitches = LightSwitches LightSwitches = LightSwitches
@@ -65,6 +63,8 @@ local function ToggleSwitchLight(EnabledState: boolean, LightObject: BasePart, L
end end
end end
local LightSwitchTween = TweenModule.constructor(TweenInfo.new(Lights.SwitchAnimationTime, Enum.EasingStyle.Linear))
local function SwitchAnimation(EnabledState: boolean, LightProperties: LightProperties) local function SwitchAnimation(EnabledState: boolean, LightProperties: LightProperties)
local Switch = LightProperties.Switch local Switch = LightProperties.Switch
@@ -85,7 +85,7 @@ end
Guide for lights with toggable switches: Guide for lights with toggable switches:
TODO TODO
]] ]]
function Lights:Create() function Lights:Init()
for _, LightProperties in self.LightSwitches do for _, LightProperties in self.LightSwitches do
if LightProperties.Prompt and LightProperties.Switch then if LightProperties.Prompt and LightProperties.Switch then
local Prompt = PromptsConstructor.constructor(LightProperties.Prompt, LightProperties.Switch) local Prompt = PromptsConstructor.constructor(LightProperties.Prompt, LightProperties.Switch)
@@ -104,7 +104,7 @@ function Lights:Create()
end end
end) end)
else else
warn(`Prompt failed`) warn(`LightSwitch hook failed, a required field is missing:\n-----\nColorDeactivated = {LightProperties.ColorDeactivated}\nColorActivated = {LightProperties.ColorActivated}\nPrompt = {LightProperties.Prompt}\nLights = {LightProperties.Lights}\n-----`)
end end
end end
end end

View File

@@ -77,7 +77,6 @@ export type InteractablesTree = {
LightSwitches: LightSwitchTree LightSwitches: LightSwitchTree
} }
export type ButtonsTree = { export type ButtonsTree = {
Landing: ButtonProperties, Landing: ButtonProperties,
Car: ButtonProperties, Car: ButtonProperties,
@@ -237,7 +236,7 @@ function Tags:__Interactables()
if InteractType == Enums.Interactables.LightSwitch then if InteractType == Enums.Interactables.LightSwitch then
local ptr = Interactables.LightSwitches[InteractObjectLocation] local ptr = Interactables.LightSwitches[InteractObjectLocation]
local itype = type(Inst) == "table" local itype = type(Inst) == "table"
local Switch = itype and (Inst :: {Instance})[1] or Inst :: Instance local Switch = (itype and (Inst :: {Instance})[1] or Inst :: Instance) :: BasePart
if itype then if itype then
warn(`2 or more light switch tags were present under the same name, using the first index. "{TagName}". This feature is not implemented yet`) warn(`2 or more light switch tags were present under the same name, using the first index. "{TagName}". This feature is not implemented yet`)
end end
@@ -249,6 +248,7 @@ function Tags:__Interactables()
Prompt.HoldDuration = Tags.MaxLightSwitchHoldDuration Prompt.HoldDuration = Tags.MaxLightSwitchHoldDuration
Prompt.Parent = Attachment Prompt.Parent = Attachment
local ClickSound = Instance.new("Sound") :: Sound local ClickSound = Instance.new("Sound") :: Sound
ClickSound.Volume = .1
ClickSound.SoundId = Tags.LightSwitchActivateSoundId ClickSound.SoundId = Tags.LightSwitchActivateSoundId
ClickSound.Parent = Switch ClickSound.Parent = Switch
@@ -281,7 +281,7 @@ function Tags:__Interactables()
ptr.Lights = Inst ptr.Lights = Inst
else else
ptr.Lights = {} ptr.Lights = {}
table.insert(ptr.Lights :: {Instance}, Inst) table.insert(ptr.Lights :: {BasePart}, Inst :: BasePart)
end end
end end
end end

View File

@@ -8,6 +8,11 @@ local Storage = game:GetService("ReplicatedStorage")
local Enums = require(Storage:WaitForChild("Enums")) local Enums = require(Storage:WaitForChild("Enums"))
local Elevators = script:WaitForChild("Elevators") local Elevators = script:WaitForChild("Elevators")
local Maps = script:WaitForChild("Map")
local Interactions = Maps:WaitForChild("Interactions")
local LightSwitches = require(Interactions:WaitForChild("LightSwitches"))
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960")) local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
local TagsModule = require(script:WaitForChild("Tags")) local TagsModule = require(script:WaitForChild("Tags"))
@@ -30,6 +35,10 @@ Workspace_Stuff()
local Interactables = TagsConstructor:__Interactables() local Interactables = TagsConstructor:__Interactables()
print("[DEBUG] Interactables=", Interactables) print("[DEBUG] Interactables=", Interactables)
--Interactables
local LightSwitchesConstructor = LightSwitches.constructor(Interactables.LightSwitches)
LightSwitchesConstructor:Init()
--Start the elevators --Start the elevators
local Buttons = TagsConstructor:__ElevatorButtons() local Buttons = TagsConstructor:__ElevatorButtons()
print("[DEBUG] Buttons=", Buttons) print("[DEBUG] Buttons=", Buttons)

View File

@@ -7,16 +7,52 @@
type EaseFunction = (n: number) -> number type EaseFunction = (n: number) -> number
type LinearFunction = (a: number, b: number, t: 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 = { export type Math = {
Linear: LinearFunction, Linear: LinearFunction,
InOutBack: EaseFunction, InOutBack: EaseFunction,
OutBounce: EaseFunction, OutBounce: EaseFunction,
InQuad: EaseFunction, InQuad: EaseFunction,
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
Scalar: (X1: number, Y1: number, X2: number, Y2: number) -> Scalar
} }
local Math = {} :: Math local Math = {} :: Math
--Google straight up gives wrong/bad 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) function Math.Linear(a,b,t)
return a-a*t+b*t return a-a*t+b*t
end end