Last active
August 23, 2017 12:54
-
-
Save tpoveda/5fac0430712830dacaa09f1e2e0dd0ab to your computer and use it in GitHub Desktop.
Function that calculates a correct swivel target position for a IKHI solver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Function that calculates a correct swivel target position for a IKHI solver | |
-- The returned position will not produce any kind of pop-up when setting the swivel target of an IKHI solver | |
-- NOTE: All the bones MUST be on the same plane | |
function GetSwivelTargetPosition boneA boneB boneC pvDst:1.0 createLoc:false = | |
( | |
boneAPos = boneA.position | |
boneBPos = boneB.position | |
boneCPos = boneC.position | |
-- Get initial vectors | |
abVec = boneBPos - boneAPos | |
acVec = boneCPos - boneAPos | |
-- Calculate projection length | |
ab_ac_dot = dot abVec acVec | |
proj = (ab_ac_dot as float)/((length acVec) as float) | |
-- Calculate projected vector by normalizing acVec and multiplying | |
--that normalized vector by the projection length | |
acVecN = normalize acVec | |
projVec = acVecN * proj | |
-- Get the vector from the projected vector to the boneB position | |
bProjVec = boneBPos - (boneApos + projVec) | |
-- Calculate final swivel target position | |
bProjVec *= pvDst | |
finalPos = bProjVec + boneB.position | |
if createLoc == true then | |
( | |
testPHlp = CreatePointHelper [0,0,0] 15.0 false false false true | |
testPHlp.position = finalPos | |
return testPHlp | |
) | |
return finalPos | |
) | |
/*boneA = getNodeByName "upperArmBone001" | |
boneB = getNodeByName "lowerArmBone001" | |
boneC = getNodeByName "wristArmBone001" | |
swivelCtrl = getNodeByName "swivelCtrl" | |
swivelCtrl.position = (GetSwivelTargetPosition boneA boneB boneC)*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment