opensim-core icon indicating copy to clipboard operation
opensim-core copied to clipboard

MOTION ANIMATION INVERSE KINEMATICS

Open Giopestri01 opened this issue 2 years ago • 0 comments

Good morning, Can anyone help me about seeing the Inverse Kinematics motion from a .mot file in a cpp project? I've perfomed the IK: void performIK(Model& model, const string& setupFilePath) { InverseKinematicsTool ikTool(setupFilePath); ikTool.run(); } and then I've tried to visualize the model moving: void visualizeAndAnimateModel(const string& modelFilePath, const string& motionFilePath) { try { Model model(modelFilePath); model.setUseVisualizer(true);

    // Inizializza il modello e il visualizzatore
    SimTK::State& state = model.initSystem();

    // Carica il file .mot come TimeSeriesTable
    auto motionData = TimeSeriesTable(motionFilePath);

    // Converti TimeSeriesTable in una StatesTrajectory
    auto statesTrajectory = StatesTrajectory::createFromStatesTable(model, motionData);

    // Ottieni il visualizzatore
    auto& viz = model.updVisualizer().updSimbodyVisualizer();

    // Ciclo per animare il modello attraverso la traiettoria di stati
    for (const auto& st : statesTrajectory) {
        model.realizePosition(st); // Aggiorna la posizione del modello
        viz.drawFrameNow(st);      // Disegna il frame attuale
        std::this_thread::sleep_for(std::chrono::milliseconds(33)); // Regola la velocità dell'animazione
    }

    cout << "Animazione completata. Premi Invio per uscire..." << endl;
    cin.get();
}
catch (const std::exception& ex) {
    cerr << "Errore durante la visualizzazione del modello: " << ex.what() << endl;
}

} but I'm not able to see it. If anyone could help me, please let me know :)

Giopestri01 avatar Mar 11 '24 16:03 Giopestri01