我正在尝试为 D3D 应用程序创建一个简单的手势识别器。手势识别器的工作原理是将接收到的每个点存储到容量为 3 的 boost::circular_buffer 中,然后计算缓冲区中相似 FrameID 的数量,如下所示:
UINT Trackball::CalculateGestureSize(Windows::UI::Input::PointerPoint ^ pPoint)
{
// shift the circular buffer queue one if it's full (common case)
if (m_pointQueue.full())
{
m_pointQueue.pop_back();
}
// then store our point
m_pointQueue.push_front(*pPoint);
// now we need to see how many of the points in the
// circular buffer match the frame Id
UINT gestureLength = 0;
for (UINT i = 0; i < MAX_GESTURE_SIZE; i += 1)
{
if (m_pointQueue[i].FrameId == pPoint->FrameId)
{
gestureLength += 1;
}
}
assert(gestureLength != 0);
return gestureLength;
}
但是,编译器无法弄清楚如何实例化这种类型:
// a queue of size 3 that helps determine what kind of gesture we're working with
boost::circular_buffer<Windows::UI::Input::PointerPoint> m_pointQueue;
因为 & 和 * 不能用于 WinRT 对象:
boost/concept_check.hpp(195): error C3699: '&' : cannot use this indirection on type 'const Windows::UI::Input::PointerPoint' compiler replacing '&' with '^' to continue parsing
由于该错误的级联效应,编译器的错误列表会很快增长。
现在,我的解决方案是将 PointerPoint 的必要信息复制到一个结构中,并将其用作 boost::circular_buffer 的类型名,如下所示:
// So WinRT objects (like Windows::UI::Input::PointerPoint) can't
// be used in STL-like containers (like boost::circular_buffer)
// because * and & operators cannot be used on them, so I'm copying
// the necessary info into this struct and using that instead
typedef struct
{
UINT FrameId;
Windows::Foundation::Point Position;
} LocalPoint;
// a queue of size 3 that helps determine what kind of gesture we're working with
boost::circular_buffer<LocalPoint> m_pointQueue;
这绝对有效,但我想知道是否有更好的解决方案。
感谢您阅读并尝试提供帮助。