| | |
| | | #include "SecsTestDlg.h" |
| | | #include <chrono> |
| | | #include <thread> |
| | | #include <cmath> |
| | | |
| | | |
| | | #ifdef _DEBUG |
| | |
| | | m_crBkgnd = APPDLG_BACKGROUND_COLOR; |
| | | m_hbrBkgnd = nullptr; |
| | | m_bShowLogWnd = FALSE; |
| | | m_bIsRobotMoving = FALSE; |
| | | m_pLogDlg = nullptr; |
| | | } |
| | | |
| | |
| | | auto startTime = std::chrono::steady_clock::now(); |
| | | auto endTime = startTime + std::chrono::milliseconds(duration); |
| | | |
| | | // 开始移动,设置标记 |
| | | m_bIsRobotMoving = TRUE; |
| | | |
| | | // 开始平滑移动 |
| | | while (std::chrono::steady_clock::now() < endTime) { |
| | | auto currentTime = std::chrono::steady_clock::now(); |
| | |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, endX + arm2Offset, 294); |
| | | |
| | | // 界面重绘 |
| | | Invalidate(); |
| | | |
| | | // 动画结束,设置标记 |
| | | m_bIsRobotMoving = FALSE; |
| | | } |
| | | |
| | | void CServoDlg::RotateRobot(float angleInDegrees) |
| | | { |
| | | return; |
| | | // 将角度转换为弧度 |
| | | float angleInRadians = angleInDegrees * (std::acos(-1) / 180.0f); |
| | | |
| | | // 获取机器人图片的当前坐标和中心 |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | int cx = pImage->x + pImage->bmWidth / 2; // 图片中心 X |
| | | int cy = pImage->y + pImage->bmHeight / 2; // 图片中心 Y |
| | | |
| | | // m_pGraph->UpdateImageAngle(IMAGE_ROBOT, angleInDegrees); |
| | | |
| | | auto* pRobot1 = m_pGraph->GetIndicateBox(INDICATE_ROBOT_ARM1); |
| | | auto* pRobot2 = m_pGraph->GetIndicateBox(INDICATE_ROBOT_ARM2); |
| | | |
| | | // 旋转指示框的坐标 |
| | | int newArmX1 = static_cast<int>(cx + (pRobot1->x - cx) * cos(angleInRadians) - (pRobot1->y - cy) * sin(angleInRadians)); |
| | | int newArmY1 = static_cast<int>(cy + (pRobot1->x - cx) * sin(angleInRadians) + (pRobot1->y - cy) * cos(angleInRadians)); |
| | | |
| | | int newArmX2 = static_cast<int>(cx + (pRobot2->x - cx) * cos(angleInRadians) - (pRobot2->y - cy) * sin(angleInRadians)); |
| | | int newArmY2 = static_cast<int>(cy + (pRobot2->x - cx) * sin(angleInRadians) + (pRobot2->y - cy) * cos(angleInRadians)); |
| | | |
| | | // 更新指示框的位置 |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, newArmX1, newArmY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, newArmX2, newArmY2); |
| | | |
| | | Invalidate(); |
| | | } |
| | | |
| | |
| | | BOOL CServoDlg::OnEraseBkgnd(CDC* pDC) |
| | | { |
| | | // TODO: 在此添加消息处理程序代码和/或调用默认值 |
| | | |
| | | //return CDialogEx::OnEraseBkgnd(pDC); |
| | | return TRUE; |
| | | if (m_bIsRobotMoving) { |
| | | // 禁止刷新背景,避免闪烁 |
| | | return TRUE; |
| | | } |
| | | |
| | | return CDialogEx::OnEraseBkgnd(pDC); |
| | | } |