Add a picking example

Open
#264 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp

Research direction

The issue names DirectXTK::BoundingSphere, SimpleMath::Matrix, and the view, projection, and world matrices, but no repository files or tests. Start by locating existing examples and the bounding-volume or picking APIs, then determine how translated objects should be handled. Done means a documented picking example that addresses the reported translation case.

Written by the indexing model from the issue text.

Description

documentation

It would help to have a picking method.

I'm trying to make my own, it doesn't work fully, what if the object is translated.


std::shared_ptr<item> Pick(float mouseX,float mouseY)
{
     
    // Right Hand conversion
    float pointX = (((2.0f * (float)mouseX) / (float)wi) - 1.0f) * -1.0f;
    float pointY = (((2.0f * (float)mouseY) / (float)he) - 1.0f);

    Vector3 origin = Vector3(pointX, pointY, 0);
    Vector3 farx = Vector3(pointX, pointY, 1);

    for (auto& m : models)
    {
        DirectXTK::BoundingSphere b = m->get_bounding_sphere();  // uses DirectXTK
        SimpleMath::Matrix worldMatrix = m->world;  // how to use this?

        auto m1 = m_view * m_proj;
        Matrix m2;
        m1.Invert(m2);

        // Now transform the ray origin and the ray direction from view space to world space.
        auto rayOrigin = XMVector3TransformCoord(origin, m2);
        auto rayend = XMVector3TransformCoord(farx, m2);

        // Normalize the ray direction.
        auto rayDirection = XMVector3Normalize(rayend - rayOrigin);

        float radius = 0;
        bool intersect = b.Intersects(rayOrigin, rayDirection, radius);

        if (intersect == true)
            return m;

        }
    return nullptr;
}
Dominant language
C++
Stars
2.9k
Forks
538
Avg merge
3d 7h
Merged PRs (30d)
5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/DirectXTK

All issues in microsoft/DirectXTK

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.