IKSolver.cpp 20 KB

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