IKSolver.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // Copyright (c) 2008-2016 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../IK/IKSolver.h"
  23. #include "../IK/IKConstraint.h"
  24. #include "../IK/IKEvents.h"
  25. #include "../IK/IKEffector.h"
  26. #include "../IK/IKConverters.h"
  27. #include "../Core/Context.h"
  28. #include "../Core/Profiler.h"
  29. #include "../Graphics/Animation.h"
  30. #include "../Graphics/AnimationState.h"
  31. #include "../Graphics/DebugRenderer.h"
  32. #include "../IO/Log.h"
  33. #include "../Scene/SceneEvents.h"
  34. #include <ik/effector.h>
  35. #include <ik/node.h>
  36. #include <ik/solver.h>
  37. namespace Atomic
  38. {
  39. extern const char* IK_CATEGORY;
  40. static bool ChildrenHaveEffector(const Node* node)
  41. {
  42. if (node->HasComponent<IKEffector>())
  43. return true;
  44. const Vector<SharedPtr<Node> >& children = node->GetChildren();
  45. for (Vector<SharedPtr<Node> >::ConstIterator it = children.Begin(); it != children.End(); ++it)
  46. {
  47. if (ChildrenHaveEffector(it->Get()))
  48. return true;
  49. }
  50. return false;
  51. }
  52. // ----------------------------------------------------------------------------
  53. IKSolver::IKSolver(Context* context) :
  54. Component(context),
  55. solver_(NULL),
  56. solverTreeNeedsRebuild_(false),
  57. updateInitialPose_(false),
  58. autoSolveEnabled_(true)
  59. {
  60. context_->RequireIK();
  61. SetAlgorithm(FABRIK);
  62. SubscribeToEvent(E_COMPONENTADDED, ATOMIC_HANDLER(IKSolver, HandleComponentAdded));
  63. SubscribeToEvent(E_COMPONENTREMOVED, ATOMIC_HANDLER(IKSolver, HandleComponentRemoved));
  64. SubscribeToEvent(E_NODEADDED, ATOMIC_HANDLER(IKSolver, HandleNodeAdded));
  65. SubscribeToEvent(E_NODEREMOVED, ATOMIC_HANDLER(IKSolver, HandleNodeRemoved));
  66. }
  67. // ----------------------------------------------------------------------------
  68. IKSolver::~IKSolver()
  69. {
  70. // Destroying the solver tree will destroy the effector objects, so remove
  71. // any references any of the IKEffector objects could be holding
  72. for (PODVector<IKEffector*>::ConstIterator it = effectorList_.Begin(); it != effectorList_.End(); ++it)
  73. (*it)->SetIKEffector(NULL);
  74. ik_solver_destroy(solver_);
  75. context_->ReleaseIK();
  76. }
  77. // ----------------------------------------------------------------------------
  78. void IKSolver::RegisterObject(Context* context)
  79. {
  80. context->RegisterFactory<IKSolver>(IK_CATEGORY);
  81. static const char* algorithmNames[] = {
  82. "FABRIK",
  83. /* not implemented
  84. "Jacobian Inverse",
  85. "Jacobian Transpose",*/
  86. NULL
  87. };
  88. ATOMIC_ENUM_ACCESSOR_ATTRIBUTE("Algorithm", GetAlgorithm, SetAlgorithm, Algorithm, algorithmNames, SOLVER_FABRIK, AM_DEFAULT);
  89. ATOMIC_ACCESSOR_ATTRIBUTE("Max Iterations", GetMaximumIterations, SetMaximumIterations, unsigned, 20, AM_DEFAULT);
  90. ATOMIC_ACCESSOR_ATTRIBUTE("Convergence Tolerance", GetTolerance, SetTolerance, float, 0.001, AM_DEFAULT);
  91. ATOMIC_ACCESSOR_ATTRIBUTE("Bone Rotations", BoneRotationsEnabled, EnableBoneRotations, bool, true, AM_DEFAULT);
  92. ATOMIC_ACCESSOR_ATTRIBUTE("Target Rotation", TargetRotationEnabled, EnableTargetRotation, bool, false, AM_DEFAULT);
  93. ATOMIC_ACCESSOR_ATTRIBUTE("Continuous Solving", ContinuousSolvingEnabled, EnableContinuousSolving, bool, false, AM_DEFAULT);
  94. ATOMIC_ACCESSOR_ATTRIBUTE("Update Pose", UpdatePoseEnabled, EnableUpdatePose, bool, false, AM_DEFAULT);
  95. ATOMIC_ACCESSOR_ATTRIBUTE("Auto Solve", AutoSolveEnabled, EnableAutoSolve, bool, true, AM_DEFAULT);
  96. }
  97. // ----------------------------------------------------------------------------
  98. IKSolver::Algorithm IKSolver::GetAlgorithm() const
  99. {
  100. return algorithm_;
  101. }
  102. // ----------------------------------------------------------------------------
  103. void IKSolver::SetAlgorithm(IKSolver::Algorithm algorithm)
  104. {
  105. algorithm_ = algorithm;
  106. if (solver_ != NULL)
  107. ik_solver_destroy(solver_);
  108. switch (algorithm_)
  109. {
  110. case FABRIK: solver_ = ik_solver_create(SOLVER_FABRIK); break;
  111. }
  112. solver_->flags = SOLVER_CALCULATE_FINAL_ROTATIONS;
  113. }
  114. // ----------------------------------------------------------------------------
  115. unsigned IKSolver::GetMaximumIterations() const
  116. {
  117. return solver_->max_iterations;
  118. }
  119. // ----------------------------------------------------------------------------
  120. void IKSolver::SetMaximumIterations(unsigned iterations)
  121. {
  122. solver_->max_iterations = iterations;
  123. }
  124. // ----------------------------------------------------------------------------
  125. float IKSolver::GetTolerance() const
  126. {
  127. return solver_->tolerance;
  128. }
  129. // ----------------------------------------------------------------------------
  130. void IKSolver::SetTolerance(float tolerance)
  131. {
  132. if (tolerance < M_EPSILON)
  133. tolerance = M_EPSILON;
  134. solver_->tolerance = tolerance;
  135. }
  136. // ----------------------------------------------------------------------------
  137. bool IKSolver::BoneRotationsEnabled() const
  138. {
  139. return (solver_->flags & SOLVER_CALCULATE_FINAL_ROTATIONS) != 0;
  140. }
  141. // ----------------------------------------------------------------------------
  142. void IKSolver::EnableBoneRotations(bool enable)
  143. {
  144. solver_->flags &= ~SOLVER_CALCULATE_FINAL_ROTATIONS;
  145. if (enable)
  146. solver_->flags |= SOLVER_CALCULATE_FINAL_ROTATIONS;
  147. }
  148. // ----------------------------------------------------------------------------
  149. bool IKSolver::TargetRotationEnabled() const
  150. {
  151. return (solver_->flags & SOLVER_CALCULATE_TARGET_ROTATIONS) != 0;
  152. }
  153. // ----------------------------------------------------------------------------
  154. void IKSolver::EnableTargetRotation(bool enable)
  155. {
  156. solver_->flags &= ~SOLVER_CALCULATE_TARGET_ROTATIONS;
  157. if (enable)
  158. solver_->flags |= SOLVER_CALCULATE_TARGET_ROTATIONS;
  159. }
  160. // ----------------------------------------------------------------------------
  161. bool IKSolver::ContinuousSolvingEnabled() const
  162. {
  163. return (solver_->flags & SOLVER_SKIP_RESET) != 0;
  164. }
  165. // ----------------------------------------------------------------------------
  166. void IKSolver::EnableContinuousSolving(bool enable)
  167. {
  168. solver_->flags &= ~SOLVER_SKIP_RESET;
  169. if (enable)
  170. solver_->flags |= SOLVER_SKIP_RESET;
  171. }
  172. // ----------------------------------------------------------------------------
  173. bool IKSolver::UpdatePoseEnabled() const
  174. {
  175. return updateInitialPose_;
  176. }
  177. // ----------------------------------------------------------------------------
  178. void IKSolver::EnableUpdatePose(bool enable)
  179. {
  180. updateInitialPose_ = enable;
  181. }
  182. // ----------------------------------------------------------------------------
  183. void IKSolver::MarkSolverTreeDirty()
  184. {
  185. solverTreeNeedsRebuild_ = true;
  186. }
  187. // ----------------------------------------------------------------------------
  188. bool IKSolver::AutoSolveEnabled() const
  189. {
  190. return autoSolveEnabled_;
  191. }
  192. // ----------------------------------------------------------------------------
  193. void IKSolver::EnableAutoSolve(bool enable)
  194. {
  195. if (autoSolveEnabled_ == enable)
  196. return;
  197. if (enable)
  198. SubscribeToEvent(GetScene(), E_SCENEDRAWABLEUPDATEFINISHED, ATOMIC_HANDLER(IKSolver, HandleSceneDrawableUpdateFinished));
  199. else
  200. UnsubscribeFromEvent(GetScene(), E_SCENEDRAWABLEUPDATEFINISHED);
  201. autoSolveEnabled_ = enable;
  202. }
  203. // ----------------------------------------------------------------------------
  204. static void ApplySolvedDataCallback(ik_node_t* ikNode)
  205. {
  206. Node* node = (Node*)ikNode->user_data;
  207. node->SetWorldRotation(QuatIK2Urho(&ikNode->solved_rotation));
  208. node->SetWorldPosition(Vec3IK2Urho(&ikNode->solved_position));
  209. }
  210. void IKSolver::Solve()
  211. {
  212. ATOMIC_PROFILE(IKSolve);
  213. if (solverTreeNeedsRebuild_)
  214. {
  215. ik_solver_rebuild_data(solver_);
  216. solverTreeNeedsRebuild_ = false;
  217. }
  218. if (updateInitialPose_)
  219. UpdateInitialPose();
  220. for (PODVector<IKEffector*>::ConstIterator it = effectorList_.Begin(); it != effectorList_.End(); ++it)
  221. {
  222. (*it)->UpdateTargetNodePosition();
  223. }
  224. solver_->apply_result = ApplySolvedDataCallback;
  225. ik_solver_solve(solver_);
  226. }
  227. // ----------------------------------------------------------------------------
  228. static void ApplyInitialDataCallback(ik_node_t* ikNode)
  229. {
  230. Node* node = (Node*)ikNode->user_data;
  231. node->SetWorldRotation(QuatIK2Urho(&ikNode->rotation));
  232. node->SetWorldPosition(Vec3IK2Urho(&ikNode->position));
  233. }
  234. void IKSolver::ResetToInitialPose()
  235. {
  236. solver_->apply_result = ApplyInitialDataCallback;
  237. ik_solver_iterate_tree(solver_);
  238. }
  239. // ----------------------------------------------------------------------------
  240. static void UpdateInitialPoseCallback(ik_node_t* ikNode)
  241. {
  242. Node* node = (Node*)ikNode->user_data;
  243. ikNode->rotation = QuatUrho2IK(node->GetWorldRotation());
  244. ikNode->position = Vec3Urho2IK(node->GetWorldPosition());
  245. }
  246. void IKSolver::UpdateInitialPose()
  247. {
  248. solver_->apply_result = UpdateInitialPoseCallback;
  249. ik_solver_iterate_tree(solver_);
  250. }
  251. // ----------------------------------------------------------------------------
  252. /*
  253. * This next section maintains the internal list of effector nodes. Whenever
  254. * nodes are deleted or added to the scene, or whenever components are added
  255. * or removed from nodes, we must check to see which of those nodes are/were
  256. * IK effector nodes and update our internal list accordingly.
  257. *
  258. * Unfortunately, E_COMPONENTREMOVED and E_COMPONENTADDED do not fire when a
  259. * parent node is removed/added containing child effector nodes, so we must
  260. * also monitor E_NODEREMOVED AND E_NODEADDED.
  261. */
  262. // ----------------------------------------------------------------------------
  263. void IKSolver::OnSceneSet(Scene* scene)
  264. {
  265. if (autoSolveEnabled_)
  266. SubscribeToEvent(scene, E_SCENEDRAWABLEUPDATEFINISHED, ATOMIC_HANDLER(IKSolver, HandleSceneDrawableUpdateFinished));
  267. }
  268. // ----------------------------------------------------------------------------
  269. void IKSolver::OnNodeSet(Node* node)
  270. {
  271. ResetToInitialPose();
  272. DestroyTree();
  273. if (node != NULL)
  274. RebuildTree();
  275. }
  276. // ----------------------------------------------------------------------------
  277. ik_node_t* IKSolver::CreateIKNode(const Node* node)
  278. {
  279. ik_node_t* ikNode = ik_node_create(node->GetID());
  280. // Set initial position/rotation and pass in Node* as user data for later
  281. ikNode->position = Vec3Urho2IK(node->GetWorldPosition());
  282. ikNode->rotation = QuatUrho2IK(node->GetWorldRotation());
  283. ikNode->user_data = (void*)node;
  284. // If the node has a constraint, it needs access to the ikNode
  285. IKConstraint* constraint = node->GetComponent<IKConstraint>();
  286. if (constraint != NULL)
  287. constraint->SetIKNode(ikNode);
  288. return ikNode;
  289. }
  290. // ----------------------------------------------------------------------------
  291. void IKSolver::DestroyTree()
  292. {
  293. ik_solver_destroy_tree(solver_);
  294. effectorList_.Clear();
  295. }
  296. // ----------------------------------------------------------------------------
  297. void IKSolver::RebuildTree()
  298. {
  299. assert(node_ != NULL);
  300. ik_node_t* ikRoot = CreateIKNode(node_);
  301. ik_solver_set_tree(solver_, ikRoot);
  302. PODVector<Node*> effectorNodes;
  303. node_->GetChildrenWithComponent<IKEffector>(effectorNodes, true);
  304. for (PODVector<Node*>::ConstIterator it = effectorNodes.Begin(); it != effectorNodes.End(); ++it)
  305. {
  306. BuildTreeToEffector(*it);
  307. }
  308. }
  309. // ----------------------------------------------------------------------------
  310. void IKSolver::BuildTreeToEffector(const Node* node)
  311. {
  312. // Check if the component that was added is an IK effector. If not, then it
  313. // does not concern us.
  314. IKEffector* effector = static_cast<IKEffector*>(node->GetComponent<IKEffector>());
  315. if (effector == NULL || effector->GetType() != IKEffector::GetTypeStatic())
  316. return;
  317. // May need to build tree up to the node where this effector was added. Do
  318. // this by following the chain of parent nodes until we hit a node that
  319. // exists in the solver's tree. Then iterate backwards again and add each
  320. // missing node to the solver's tree.
  321. PODVector<const Node*> missingNodes;
  322. const Node* iterNode = node;
  323. ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
  324. while (ikNode == NULL)
  325. {
  326. missingNodes.Push(iterNode);
  327. iterNode = iterNode->GetParent();
  328. ikNode = ik_node_find_child(solver_->tree, iterNode->GetID());
  329. }
  330. while (missingNodes.Size() > 0)
  331. {
  332. iterNode = missingNodes.Back();
  333. missingNodes.Pop();
  334. ik_node_t* ikChildNode = CreateIKNode(iterNode);
  335. ik_node_add_child(ikNode, ikChildNode);
  336. ikNode = ikChildNode;
  337. }
  338. // The tip of the tree is the effector. The solver library has ownership of
  339. // the effector object, but our IKEffector object also needs to know about
  340. // it.
  341. ik_effector_t* ikEffector = ik_effector_create();
  342. ik_node_attach_effector(ikNode, ikEffector); // ownership of effector
  343. effector->SetIKEffector(ikEffector); // "weak" reference to effector
  344. effector->SetIKSolver(this);
  345. effectorList_.Push(effector);
  346. MarkSolverTreeDirty();
  347. }
  348. // ----------------------------------------------------------------------------
  349. void IKSolver::HandleComponentAdded(StringHash eventType, VariantMap& eventData)
  350. {
  351. using namespace ComponentAdded;
  352. (void)eventType;
  353. if (solver_->tree == NULL)
  354. return;
  355. Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
  356. BuildTreeToEffector(node);
  357. }
  358. // ----------------------------------------------------------------------------
  359. void IKSolver::HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
  360. {
  361. using namespace ComponentRemoved;
  362. if (solver_->tree == NULL)
  363. return;
  364. // If an effector was removed, the tree will have to be rebuilt.
  365. Component* component = static_cast<Component*>(eventData[P_COMPONENT].GetPtr());
  366. if (component->GetType() == IKEffector::GetTypeStatic())
  367. {
  368. IKEffector* effector = static_cast<IKEffector*>(component);
  369. Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
  370. ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
  371. assert(ikNode != NULL);
  372. ik_node_destroy_effector(ikNode);
  373. effector->SetIKEffector(NULL);
  374. effectorList_.RemoveSwap(effector);
  375. ResetToInitialPose();
  376. MarkSolverTreeDirty();
  377. }
  378. // Remove the ikNode* reference the IKConstraint was holding
  379. if (component->GetType() == IKConstraint::GetTypeStatic())
  380. {
  381. IKConstraint* constraint = static_cast<IKConstraint*>(component);
  382. constraint->SetIKNode(NULL); // NOTE: Should restore default settings to the node
  383. }
  384. }
  385. // ----------------------------------------------------------------------------
  386. void IKSolver::HandleNodeAdded(StringHash eventType, VariantMap& eventData)
  387. {
  388. using namespace NodeAdded;
  389. if (solver_->tree == NULL)
  390. return;
  391. Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
  392. PODVector<Node*> nodes;
  393. node->GetChildrenWithComponent<IKEffector>(nodes, true);
  394. for (PODVector<Node*>::ConstIterator it = nodes.Begin(); it != nodes.End(); ++it)
  395. {
  396. BuildTreeToEffector(*it);
  397. effectorList_.Push((*it)->GetComponent<IKEffector>());
  398. }
  399. }
  400. // ----------------------------------------------------------------------------
  401. void IKSolver::HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  402. {
  403. using namespace NodeRemoved;
  404. if (solver_->tree == NULL)
  405. return;
  406. Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
  407. // Remove cached IKEffectors from our list
  408. PODVector<Node*> nodes;
  409. node->GetChildrenWithComponent<IKEffector>(nodes, true);
  410. for (PODVector<Node*>::ConstIterator it = nodes.Begin(); it != nodes.End(); ++it)
  411. {
  412. IKEffector* effector = (*it)->GetComponent<IKEffector>();
  413. effector->SetIKEffector(NULL);
  414. effectorList_.RemoveSwap(effector);
  415. }
  416. // Special case, if the node being destroyed is the root node, destroy the
  417. // solver's tree instead of destroying the single node. Calling
  418. // ik_node_destroy() on the solver's root node will cause segfaults.
  419. ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
  420. if (ikNode != NULL)
  421. {
  422. if (ikNode == solver_->tree)
  423. ik_solver_destroy_tree(solver_);
  424. else
  425. ik_node_destroy(ikNode);
  426. MarkSolverTreeDirty();
  427. }
  428. }
  429. // ----------------------------------------------------------------------------
  430. void IKSolver::HandleSceneDrawableUpdateFinished(StringHash eventType, VariantMap& eventData)
  431. {
  432. Solve();
  433. }
  434. // ----------------------------------------------------------------------------
  435. void IKSolver::DrawDebugGeometry(bool depthTest)
  436. {
  437. DebugRenderer* debug = GetScene()->GetComponent<DebugRenderer>();
  438. if (debug)
  439. DrawDebugGeometry(debug, depthTest);
  440. }
  441. // ----------------------------------------------------------------------------
  442. void IKSolver::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
  443. {
  444. // Draws all scene segments
  445. for (PODVector<IKEffector*>::ConstIterator it = effectorList_.Begin(); it != effectorList_.End(); ++it)
  446. (*it)->DrawDebugGeometry(debug, depthTest);
  447. ORDERED_VECTOR_FOR_EACH(&solver_->effector_nodes_list, ik_node_t*, pnode)
  448. ik_effector_t* effector = (*pnode)->effector;
  449. // Calculate average length of all segments so we can determine the radius
  450. // of the debug spheres to draw
  451. int chainLength = effector->chain_length == 0 ? -1 : effector->chain_length;
  452. ik_node_t* a = *pnode;
  453. ik_node_t* b = a->parent;
  454. float averageLength = 0.0f;
  455. unsigned numberOfSegments = 0;
  456. while (b && chainLength-- != 0)
  457. {
  458. vec3_t v = a->position;
  459. vec3_sub_vec3(v.f, b->position.f);
  460. averageLength += vec3_length(v.f);
  461. ++numberOfSegments;
  462. a = b;
  463. b = b->parent;
  464. }
  465. averageLength /= numberOfSegments;
  466. // connect all chained nodes together with lines
  467. chainLength = effector->chain_length == 0 ? -1 : effector->chain_length;
  468. a = *pnode;
  469. b = a->parent;
  470. debug->AddSphere(
  471. Sphere(Vec3IK2Urho(&a->position), averageLength * 0.1f),
  472. Color(0, 0, 255),
  473. depthTest
  474. );
  475. debug->AddSphere(
  476. Sphere(Vec3IK2Urho(&a->solved_position), averageLength * 0.1f),
  477. Color(255, 128, 0),
  478. depthTest
  479. );
  480. while (b && chainLength-- != 0)
  481. {
  482. debug->AddLine(
  483. Vec3IK2Urho(&a->position),
  484. Vec3IK2Urho(&b->position),
  485. Color(0, 255, 255),
  486. depthTest
  487. );
  488. debug->AddSphere(
  489. Sphere(Vec3IK2Urho(&b->position), averageLength * 0.1f),
  490. Color(0, 0, 255),
  491. depthTest
  492. );
  493. debug->AddLine(
  494. Vec3IK2Urho(&a->solved_position),
  495. Vec3IK2Urho(&b->solved_position),
  496. Color(255, 0, 0),
  497. depthTest
  498. );
  499. debug->AddSphere(
  500. Sphere(Vec3IK2Urho(&b->solved_position), averageLength * 0.1f),
  501. Color(255, 128, 0),
  502. depthTest
  503. );
  504. a = b;
  505. b = b->parent;
  506. }
  507. ORDERED_VECTOR_END_EACH
  508. }
  509. } // namespace Atomic