ecurtiss / CatRom

Creates Catmull-Rom splines for Roblox
https://ecurtiss.github.io/CatRom/
Mozilla Public License 2.0
45 stars 11 forks source link

Implement rotation minimizing frames #4

Closed OttoHatt closed 2 months ago

OttoHatt commented 2 years ago

Broken for straight lines! Check the code comments. Please also double check the maths, as I don't think it's 100% perfect. Optimizations could be done (i.e. removing local functions), but for now I focused on readability.

OttoHatt commented 2 years ago

Looking at this again, it might be better to implement this as some kind of iterator, as precomputing all at once is expensive and not good for animations. Like, you'd call a method (say CreateUniformMinFrameIterator) and it'd return a function that you call with a 't' value.

local iter = CatRom:CreateUniformMinFrameIterator()

local pointA = iter(0) -- The first call would become the reference point.
local pointB = iter(0.1)
local pointC = iter(0.2)
...
OttoHatt commented 2 years ago

I was flipping the lookVectors in the creation of CFrame.new, which broke the transform and creates weird inversions. lookVectors are now correct, but backwards, so I think it'd be best to :Inverse() all CFrame points, even though this'd make the up/right vectors technically incorrect?