Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiki Issue for Getting Started -> Animating using model bones #218

Open
focusright opened this issue Mar 27, 2024 · 3 comments
Open

Wiki Issue for Getting Started -> Animating using model bones #218

focusright opened this issue Mar 27, 2024 · 3 comments
Assignees

Comments

@focusright
Copy link

In this wiki documentation

https://github.com/microsoft/DirectXTK12/wiki/Animating-using-model-bones#modifying-model-bones

The result does not match the screenshot provided. The problem can be addressed either in the model or the CreateLookAt() function in Game::CreateWindowSizeDependentResources(). Since I don't have the original source file of the model I fixed it in the code with

void Game::CreateWindowSizeDependentResources()
{
    // TODO: Initialize windows-size dependent objects here.

    auto size = m_deviceResources->GetOutputSize();
    m_view = Matrix::CreateLookAt(Vector3(10, 2, 0),
        Vector3(0, 2, 0), Vector3::UnitY);
    m_proj = Matrix::CreatePerspectiveFieldOfView(XM_PI / 4.f,
        float(size.right) / float(size.bottom), 0.1f, 10000.f);
}

The main fix being in changing the Vector3 parameters in the CreateLookAt() function.

@focusright
Copy link
Author

@walbourn
Copy link
Member

FWIW, all the tutorials source can be found https://github.com/walbourn/directxtk-tutorials

@walbourn walbourn self-assigned this Mar 27, 2024
@focusright
Copy link
Author

I looked at the tutorial source and found the culprit, the line

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

needs to remain right after the lines where the bone arrays are made:

m_drawBones = ModelBone::MakeArray(nbones);
m_animBones = ModelBone::MakeArray(nbones);

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

uint32_t index = 0;
for (const auto& it : m_model->bones)
{
    if (_wcsicmp(it.name.c_str(), L"tank_geo") == 0)
    {
        // Need to recenter the model.
        m_animBones[index] = XMMatrixIdentity();
    }

    ++index;  
}

In this section of the wiki

https://github.com/microsoft/DirectXTK12/wiki/Animating-using-model-bones#modifying-model-bones

the last sentence is "(after you have loaded the model and created the bone arrays):"

which made my code like this:

m_drawBones = ModelBone::MakeArray(nbones);
m_animBones = ModelBone::MakeArray(nbones);

uint32_t index = 0;
for (const auto& it : m_model->bones)
{
    if (_wcsicmp(it.name.c_str(), L"tank_geo") == 0)
    {
        // Need to recenter the model.
        m_animBones[index] = XMMatrixIdentity();
    }

    ++index;  
}

m_model->CopyBoneTransformsTo(nbones, m_animBones.get());

Hopefully this will help someone else who tries to follow the tutorial like I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants