繁体   English   中英

如何在MFC中使光标移动更流畅?

[英]How to make the movement of cursor more smoothly in MFC?

我正在尝试使用Myo移动鼠标光标。

我做到了,但效果并不理想。

我知道在此代码中,Myo的每次移动仅将光标移动5个像素。

我想改进此代码,使其更像真正的鼠标。 (但不是这样的:point.x + 500;)

准确性和覆盖范围都很重要。 Myo的移动很少,我想将光标从监视器的左端移到右端。 (我的意思是0〜65535。)同时,我想保持准确性(为了使单击动作更方便)。

在此代码中..

  • compare_pitch表示先前的pitch_w值。

  • compare_yaw表示先前的yaw_w值。

     if(compare_pitch < collector.pitch_w) { point.y += 5; // Move Cursor Right } if(compare_pitch > collector.pitch_w) point.y -= 5; // Move Cursor Left } if(compare_yaw < collector.yaw_w) { point.x -= 5; // Move Cursor Up } if(compare_yaw > collector.yaw_w) { point.x += 5;// Move Cursor Down } SetCursorPos(point.x, point.y); compare_pitch = collector.pitch_w; compare_yaw = collector.yaw_w; 

以下是collector.pitch_w和collector.yaw_w的函数。 (我没有使用roll_w。)

 // onOrientationData() is called whenever the Myo device provides its current orientation, which is represented
// as a unit quaternion.


void onOrientationData(myo::Myo* myo, uint64_t timestamp, const myo::Quaternion<float>& quat)
{
    using std::atan2;
    using std::asin;
    using std::sqrt;
    using std::max;
    using std::min;

    // Calculate Euler angles (roll, pitch, and yaw) from the unit quaternion.
    float roll = atan2(2.0f * (quat.w() * quat.x() + quat.y() * quat.z()),
                       1.0f - 2.0f * (quat.x() * quat.x() + quat.y() * quat.y()));
    float pitch = asin(max(-1.0f, min(1.0f, 2.0f * (quat.w() * quat.y() - quat.z() * quat.x()))));
    float yaw = atan2(2.0f * (quat.w() * quat.z() + quat.x() * quat.y()),
                    1.0f - 2.0f * (quat.y() * quat.y() + quat.z() * quat.z()));

    // Convert the floating point angles in radians to a scale from 0 to 100.
   roll_w = static_cast<int>((roll + (float)M_PI)/(M_PI * 2.0f) * 100);
   pitch_w = static_cast<int>((pitch + (float)M_PI/2.0f)/M_PI * 100);
   yaw_w = static_cast<int>((yaw + (float)M_PI)/(M_PI * 2.0f) * 100);
}

请给我一些建议。 谢谢。

我的想法是使用加速。

我的想法是使用区别compare_pitch - collector.pitch_wcompare_yaw - collector.yaw_w 如果手快速移动,则此差异将增加。 根据此差异加快指针位置的变化。

point.y += (int)((collector.pitch_w - compare_pitch ) * some_constant_value)
point.x += (int)((collector.yaw_w - compare_yaw) * some_constant_value)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM