Qt中怎么让一个物体或图片沿画好的曲线运动

huagongshou 2015-12-30 07:44:39
知道QT 的QML中PathAnimation类可以实现相关功能,但希望用Qt的C++类实现该功能,求大神指教,最好能有简单例子,
...全文
916 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-01-06
  • 打赏
  • 举报
回复
仅供参考: LineDDA The LineDDA function determines which pixels should be highlighted for a line defined by the specified starting and ending points. BOOL LineDDA( int nXStart, // x-coordinate of line's starting point int nYStart, // y-coordinate of line's starting point int nXEnd, // x-coordinate of line's ending point int nYEnd, // y-coordinate of line's ending point LINEDDAPROC lpLineFunc, // pointer to callback function LPARAM lpData // pointer to application-defined data ); Parameters nXStart Specifies the x-coordinate of the line's starting point. nYStart Specifies the y-coordinate of the line's starting point. nXEnd Specifies the x-coordinate of the line's ending point. nYEnd Specifies the y-coordinate of the line's ending point. lpLineFunc Pointer to an application-defined callback function. For more information, see the LineDDAProc callback function. lpData Pointer to the application-defined data. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks The LineDDA function passes the coordinates for each point along the line, except for the line's ending point, to the application-defined callback function. In addition to passing the coordinates of a point, this function passes any existing application-defined data. The coordinates passed to the callback function match pixels on a video display only if the default transformations and mapping modes are used. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Lines and Curves Overview, Line and Curve Functions, LineDDAProc
bear234 2016-01-05
  • 打赏
  • 举报
回复
思路一: 轨迹,用数学方程来表示-----------解析几何。 如果是不规则的轨迹,就把曲线细分成一段一段有规则的、可以用方程表示曲线段。 思路二: 先设定一个精度,然后一边画曲线、一边取点,比如每隔10的距离就取一个点。如果你是用鼠标画曲线的话,根据精度直接取鼠标的坐标就ok了。 把所有取到的点依序push进FIFO里。 然后你依次pop这个队列,画图。 个人认为思路二更好,实现起来也更容易。
ooolinux 2015-12-31
  • 打赏
  • 举报
回复
移动的图片不是有Left和Top坐标,根据曲线上点的坐标计算、改变图片的坐标不就可以。
huagongshou 2015-12-31
  • 打赏
  • 举报
回复
曲线可以是自己指定点画出,或公式曲线,都可以,能不能发个简单例子,让我试下?
huagongshou 2015-12-31
  • 打赏
  • 举报
回复
首先非常感谢大神的指点,但还是有点模糊,能麻烦大神给出用QT写的简单程序例子可以吗?
zhouxiaofeng1021 2015-12-31
  • 打赏
  • 举报
回复
引用 4 楼 baijiaheizhiganmao 的回复:
就是不断绘制的过程:你从曲线上某一点开始,不断的绘制你的物体,然后偏移这个点,擦除原来的图片,再在这个新的点位置绘制物体。自己控制好偏移的量和偏移的速度(就是物体停留的时间)。然后你移动的轨迹就是你曲线的走向(用这个曲线的公式也可以)。 我的思路就是这样。我这里没有例子。
差不多就是这样呗 将物体移动到曲线上某个位置然后刷新下就可以了 也就是界面重绘下 Onpaint函数就可以这样 MFC
忘世麒麟 2015-12-31
  • 打赏
  • 举报
回复
就是不断绘制的过程:你从曲线上某一点开始,不断的绘制你的物体,然后偏移这个点,擦除原来的图片,再在这个新的点位置绘制物体。自己控制好偏移的量和偏移的速度(就是物体停留的时间)。然后你移动的轨迹就是你曲线的走向(用这个曲线的公式也可以)。 我的思路就是这样。我这里没有例子。
ooolinux 2015-12-30
  • 打赏
  • 举报
回复
曲线是公式计算画出来的还是?如果不是计算出来的,笨办法或许可以事先手工或其它手段获取曲线的节点坐标存在数组里。

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧