Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function QuaternionFromCFrame(cf)
- local mx, my, mz,
- m00, m01, m02,
- m10, m11, m12,
- m20, m21, m22 = cf:components()
- local trace = m00 + m11 + m22
- if trace > 0 then
- local s = math.sqrt(1 + trace)
- local recip = 0.5/s
- return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5
- else
- local i = 0
- if m11 > m00 then i = 1 end
- if m22 > (i == 0 and m00 or m11) then i = 2 end
- if i == 0 then
- local s = math.sqrt(m00-m11-m22+1)
- local recip = 0.5/s
- return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip
- elseif i == 1 then
- local s = math.sqrt(m11-m22-m00+1)
- local recip = 0.5/s
- return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip
- elseif i == 2 then
- local s = math.sqrt(m22-m00-m11+1)
- local recip = 0.5/s
- return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip
- end
- end
- end
- function QuaternionToCFrame(px, py, pz, x, y, z, w)
- local xs, ys, zs = x + x, y + y, z + z
- local wx, wy, wz = w*xs, w*ys, w*zs
- --
- local xx = x*xs
- local xy = x*ys
- local xz = x*zs
- local yy = y*ys
- local yz = y*zs
- local zz = z*zs
- --
- return CFrame.new(px, py, pz,
- 1-(yy+zz), xy - wz, xz + wy,
- xy + wz, 1-(xx+zz), yz - wx,
- xz - wy, yz + wx, 1-(xx+yy))
- end
- function QuaternionSlerp(a, b, t)
- local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4]
- local startInterp, finishInterp;
- if cosTheta >= 0.0001 then
- if (1 - cosTheta) > 0.0001 then
- local theta = math.acos(cosTheta)
- local invSinTheta = 1/math.sin(theta)
- startInterp = math.sin((1-t)*theta)*invSinTheta
- finishInterp = math.sin(t*theta)*invSinTheta
- else
- startInterp = 1-t
- finishInterp = t
- end
- else
- if (1+cosTheta) > 0.0001 then
- local theta = math.acos(-cosTheta)
- local invSinTheta = 1/math.sin(theta)
- startInterp = math.sin((t-1)*theta)*invSinTheta
- finishInterp = math.sin(t*theta)*invSinTheta
- else
- startInterp = t-1
- finishInterp = t
- end
- end
- return a[1]*startInterp + b[1]*finishInterp,
- a[2]*startInterp + b[2]*finishInterp,
- a[3]*startInterp + b[3]*finishInterp,
- a[4]*startInterp + b[4]*finishInterp
- end
- function HermiteInterpolation(y0, y1,y2, y3,mu,tension,bias)
- local m0,m1,mu2,mu3
- local a0,a1,a2,a3
- mu2 = mu * mu
- mu3 = mu2 * mu
- m0 = (y1-y0)*(1+bias)*(1-tension)/2
- m0 = m0 + (y2-y1)*(1-bias)*(1-tension)/2
- m1 = (y2-y1)*(1+bias)*(1-tension)/2
- m1 = m1 + (y3-y2)*(1-bias)*(1-tension)/2
- a0 = 2*mu3 - 3*mu2 + 1
- a1 = mu3 - 2*mu2 + mu
- a2 = mu3 - mu2
- a3 = -2*mu3 + 3*mu2
- return(a0*y1+a1*m0+a2*m1+a3*y2);
- end
- function interpCFrame(x, a, b, y, t, bias, l)
- local qa = {QuaternionFromCFrame(a)}
- local qb = {QuaternionFromCFrame(b)}
- local qr = {QuaternionSlerp(qa, qb, l*l*l*(l*(l*6-15)+10))}
- local xPos = Vector3.new(x.x, x.y, x.z)
- local aPos = Vector3.new(a.x, a.y, a.z)
- local bPos = Vector3.new(b.x, b.y, b.z)
- local yPos = Vector3.new(y.x, y.y, y.z)
- local rPos = HermiteInterpolation(xPos, aPos, bPos, yPos, l, t, bias)
- return QuaternionToCFrame(rPos.x, rPos.y, rPos.z, qr[1], qr[2], qr[3], qr[4])
- end
- ---------------------------------------------------------------------------------------------
- local plr = game.Players.LocalPlayer
- local cam = game.Workspace:WaitForChild('Camera')
- cam.FieldOfView = 20
- local sceneCam = game.Workspace.Cam
- sceneCam.Transparency = 1
- local Sequence = -1
- local cF
- game:GetService("UserInputService").InputBegan:connect(function(input)
- if input.KeyCode == Enum.KeyCode.Return then
- Sequence = 0
- elseif input.KeyCode == Enum.KeyCode.One then
- cF = tick()
- Sequence = 1
- end
- end)
- local c = 0
- local animComplete = false
- local div = 0.75
- local bias = 1
- local spline = 0
- local cB = {}
- for i = 0, 20 do
- local part = game.Workspace:findFirstChild("CamBezier"..i)
- cB[i] = part
- part.Transparency = 1
- end
- game:GetService("RunService").RenderStepped:connect(function()
- if Sequence > -1 then
- if not animComplete and Sequence > 0 then
- local lerpTime1 = (tick() - cF)/div
- lerpTime1 = math.min(math.max(lerpTime1, 0), 1)
- sceneCam.CFrame = interpCFrame(cB[c].CFrame, cB[c + 1].CFrame,
- cB[c + 2].CFrame, cB[c + 3].CFrame, spline, bias, lerpTime1)
- if lerpTime1 == 1 then
- cF = tick()
- lerpTime1 = 0
- c = c + 1
- if (c+3) > #cB then
- animComplete = true
- end
- end
- end
- cam.CoordinateFrame = sceneCam.CFrame
- end
- end)
Add Comment
Please, Sign In to add comment