Ejemplo n.º 1
0
// ----------------------------------------------------------------------------
void IKSolver::HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
{
    using namespace ComponentRemoved;

    if (solver_->tree == NULL)
        return;

    Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
    Component* component = static_cast<Component*>(eventData[P_COMPONENT].GetPtr());

    /*
     * When a solver gets added into the scene, any parent solver's tree will
     * be invalidated. We need to find all parent solvers (by iterating up the
     * tree) and mark them as such.
     */
    if (component->GetType() == IKSolver::GetTypeStatic())
    {
        for (Node* iterNode = node; iterNode != NULL; iterNode = iterNode->GetParent())
        {
            IKSolver* parentSolver = iterNode->GetComponent<IKSolver>();
            if (parentSolver != NULL)
                parentSolver->MarkTreeNeedsRebuild();

        }

        return; // No need to continue processing effectors or constraints
    }

    // If an effector was removed, the tree will have to be rebuilt.
    if (component->GetType() == IKEffector::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
        assert(ikNode != NULL);

        ik_node_destroy_effector(ikNode);
        static_cast<IKEffector*>(component)->SetIKEffectorNode(NULL);
        effectorList_.RemoveSwap(static_cast<IKEffector*>(component));

        ApplyOriginalPoseToScene();
        MarkTreeNeedsRebuild();
        return;
    }

    // Remove the ikNode* reference the IKConstraint was holding
    if (component->GetType() == IKConstraint::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
        assert(ikNode != NULL);

        static_cast<IKConstraint*>(component)->SetIKConstraintNode(NULL);
        constraintList_.RemoveSwap(static_cast<IKConstraint*>(component));
    }
}
int main(int argc, char *argv[])
{
    ResourceFinder rf;
    rf.configure(argc,argv);

    IKSolver solver;
    return solver.runModule(rf);
}
Ejemplo n.º 3
0
// ----------------------------------------------------------------------------
void IKSolver::HandleComponentRemoved(Scene *,Node *node,Component *component)
{
    if (solver_->tree == nullptr)
        return;

    /*
     * When a solver gets added into the scene, any parent solver's tree will
     * be invalidated. We need to find all parent solvers (by iterating up the
     * tree) and mark them as such.
     */
    if (component->GetType() == IKSolver::GetTypeStatic())
    {
        for (Node* iterNode = node; iterNode != nullptr; iterNode = iterNode->GetParent())
        {
            IKSolver* parentSolver = iterNode->GetComponent<IKSolver>();
            if (parentSolver != nullptr)
                parentSolver->MarkTreeNeedsRebuild();

        }

        return; // No need to continue processing effectors or constraints
    }

    // If an effector was removed, the tree will have to be rebuilt.
    if (component->GetType() == IKEffector::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
        assert(ikNode != nullptr);

        ik_node_destroy_effector(ikNode);
        static_cast<IKEffector*>(component)->SetIKEffectorNode(nullptr);
        RemovePopBack(effectorList_,static_cast<IKEffector*>(component));

        ApplyOriginalPoseToScene();
        MarkTreeNeedsRebuild();
        return;
    }

    // Remove the ikNode* reference the IKConstraint was holding
    if (component->GetType() == IKConstraint::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID());
        assert(ikNode != nullptr);

        static_cast<IKConstraint*>(component)->SetIKConstraintNode(nullptr);
        RemovePopBack(constraintList_,static_cast<IKConstraint*>(component));
    }
}
Ejemplo n.º 4
0
// ----------------------------------------------------------------------------
void IKSolver::HandleComponentAdded(StringHash eventType, VariantMap& eventData)
{
    using namespace ComponentAdded;
    (void)eventType;

    Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr());
    Component* component = static_cast<Component*>(eventData[P_COMPONENT].GetPtr());

    /*
     * When a solver gets added into the scene, any parent solver's tree will
     * be invalidated. We need to find all parent solvers (by iterating up the
     * tree) and mark them as such.
     */
    if (component->GetType() == IKSolver::GetTypeStatic())
    {
        for (Node* iterNode = node; iterNode != NULL; iterNode = iterNode->GetParent())
        {
            IKSolver* parentSolver = iterNode->GetComponent<IKSolver>();
            if (parentSolver != NULL)
                parentSolver->MarkTreeNeedsRebuild();

        }

        return; // No need to continue processing effectors or constraints
    }

    if (solver_->tree == NULL)
        return;

    /*
     * Update tree if component is an effector and is part of our subtree.
     */
    if (component->GetType() == IKEffector::GetTypeStatic())
    {
        // Not interested in components that won't be part of our
        if (ComponentIsInOurSubtree(component) == false)
            return;

        BuildTreeToEffector(static_cast<IKEffector*>(component));
        effectorList_.Push(static_cast<IKEffector*>(component));
        return;
    }

    if (component->GetType() == IKConstraint::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        constraintList_.Push(static_cast<IKConstraint*>(component));
    }
}
Ejemplo n.º 5
0
void GLWidget::animate()
{
    if(_animationEnabled) {
        _character->update(*this);
    }

    if(!_endEffectorsTarget.empty()) {
        IKSolver solver = IKSolver(_character->root(), 20);

        for(int i = 0; i < 10; ++i) {
            solver.solve(_endEffectorsTarget, _currentIKMethod);
        }
    }

    updateGL();
}
Ejemplo n.º 6
0
// ----------------------------------------------------------------------------
void IKSolver::HandleComponentAdded(Scene *,Node *node,Component *component)
{

    /*
     * When a solver gets added into the scene, any parent solver's tree will
     * be invalidated. We need to find all parent solvers (by iterating up the
     * tree) and mark them as such.
     */
    if (component->GetType() == IKSolver::GetTypeStatic())
    {
        for (Node* iterNode = node; iterNode != nullptr; iterNode = iterNode->GetParent())
        {
            IKSolver* parentSolver = iterNode->GetComponent<IKSolver>();
            if (parentSolver != nullptr)
                parentSolver->MarkTreeNeedsRebuild();

        }

        return; // No need to continue processing effectors or constraints
    }

    if (solver_->tree == nullptr)
        return;

    /*
     * Update tree if component is an effector and is part of our subtree.
     */
    if (component->GetType() == IKEffector::GetTypeStatic())
    {
        // Not interested in components that won't be part of our
        if (ComponentIsInOurSubtree(component) == false)
            return;

        BuildTreeToEffector(static_cast<IKEffector*>(component));
        effectorList_.push_back(static_cast<IKEffector*>(component));
        return;
    }

    if (component->GetType() == IKConstraint::GetTypeStatic())
    {
        if (ComponentIsInOurSubtree(component) == false)
            return;

        constraintList_.push_back(static_cast<IKConstraint*>(component));
    }
}
Ejemplo n.º 7
0
IKFAST_API bool ComputeIk2(const IkReal* eetrans, const IkReal* eerot, const IkReal* pfree, IkSolutionListBase<IkReal>& solutions, void* pOpenRAVEManip) {
IKSolver solver;
return solver.ComputeIk(eetrans,eerot,pfree,solutions);
}