Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured out how to do it. I am a C++ newbie so there may be much better ways to do this, but my way works.</p> <p>(FYI - I wrote an article about this on Nokia's Developer site: <a href="http://developer.nokia.com/Community/Wiki/Multi-touch_handling_using_DirectX_C%2B%2B#PointerPoint" rel="nofollow">http://developer.nokia.com/Community/Wiki/Multi-touch_handling_using_DirectX_C%2B%2B#PointerPoint</a> )</p> <p>You need to keep track of the PointerId inside of the PointerPoint. I store the PointerId in the OnPointerPressed event in a std::unordered_map. The key (unsigned int) is the PointerId. You then erase them from the map when you get the OnPointerReleased event. The PointerId will match up. It turns out that for every new finger, you get a new PointerId... even if you release your first finger and put it back down again. </p> <p>Then, when you get to your OnPointerMoved event handler, you just have to call the size() function on your unordered_map to find out how many touches you currently have on screen. </p> <p>The reason I'm using the unordered_map is because I needed to keep track of previous point positions. I realize that you can probably get old positions using the GetIntermediatePoints method, but I didn't want to have to troubleshoot something new...</p> <p>Anyways, hope this helps. Code below:</p> <p>EDIT: Code updated to handle the x move events you get from each touch for <em>each frame</em>. Like I said, this isn't the best, but it works.</p> <pre><code>#include &lt;unordered_map&gt; std::unordered_map&lt;unsigned int, Windows::UI::Input::PointerPoint^&gt; m_pointerIds; std::unordered_map&lt;unsigned int, Windows::UI::Input::PointerPoint^&gt; m_oldPoints; void Direct3DBackground::OnPointerPressed(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) { m_pointerIds.emplace(args-&gt;CurrentPoint-&gt;PointerId, args-&gt;CurrentPoint); m_oldPoints.emplace(args-&gt;CurrentPoint-&gt;PointerId, args-&gt;CurrentPoint); } void Direct3DBackground::OnPointerMoved(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) { if (m_pointerIds.size() == 1) { DoSomethingForOneTouch(args); } else if (m_pointerIds.size() == 2) { UINT changedPointId = args-&gt;CurrentPoint-&gt;PointerId; UINT frameId = args-&gt;CurrentPoint-&gt;FrameId; UINT otherPointId; for (auto it = m_pointerIds.begin(); it != m_pointerIds.end(); ++it) { if (it-&gt;first != changedPointId) { otherPointId = it-&gt;first; break; } } m_oldPoints[changedPointId] = m_pointerIds[changedPointId]; m_pointerIds[changedPointId] = args-&gt;CurrentPoint; if (m_pointerIds[otherPointId]-&gt;FrameId == frameId) { //DO YOUR CALCULATION using new points and old points //as both touches have been updated for the current frame. } } } void Direct3DBackground::OnPointerReleased(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) { m_pointerIds.erase(args-&gt;CurrentPoint-&gt;PointerId); m_oldPoints.erase(args-&gt;CurrentPoint-&gt;PointerId); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload