So I was reading this, then I was quite alarmed as I believe I went a bit overboard after discovering the power of objects oriented programming.
I’m particularly concerned with using objects within objects, and how these two objects are sharing a table between them and methods as well…
--So I store these variables in the original LimbChain Object
obj.LimbVectorTable = LimbVectorTable
-- Stores the limb vector table in the iterated version
obj.IteratedLimbVectorTable = IteratedLimbVectorTable
--Then I pass them into another object....is that ok?
--The other object is the FabrikSolver object which does the math stuff
--Once the limb vectors are initialized store them in a FabrikSolver object which does the Fabrik iteration
local LimbFabrikSolver = FabrikSolver.new(IteratedLimbVectorTable,LimbLengthTable,LimbConstraintTable,obj)
--yeah obj the LimbChain itself but it's a different issue so ignore it for now
--due to the constraint system and IterateUntil and the Parts CFrames...
--A lot of stuff
--Then I store that object in this LimbChain object
obj.LimbFabrikSolver = LimbFabrikSolver
--Inside the iterate once method
--function LimbChain:IterateOnce(parameters stuff)
--Do the iteration in the object
--Then the LimbChain copies the homework from this other object
self.IteratedLimbVectorTable = self.LimbFabrikSolver:IterateOnce(originJointCF,targetPosition, tolerance)
Is this ok, it works but it feels a bit redundant…
I was mainly trying to pass this iteration variable back and forth through functions like in my old module before I used OOP on it like the limbLengthTable is a constant variable for a single chain. You can see this in my IKAnimation folder in replicated storage as Fabrik.lua.
--A lot of the same parameters passed back and forth
local function FabrikAlgo(tolerance, originCF, targetPos, limbVectorTable,
limbLengthTable, limbConstraintTable)
--do stuff
end
local function Backwards(originCF, targetPos, limbVectorTable,
limbLengthTable)
end
local function Forwards(originCF, targetPos, limbVectorTable, limbLengthTable)
end
You can see all the code here since it’s open source:
https://github.com/datlass/fabrik-ik-motor6d/tree/master/src/ReplicatedStorage/ObjectFolder
Plus any other issues, primarily:
-
Code readability and structure
-
Some other optimization issue?