| | |
| | | #include "Common.h" |
| | | #include "Log.h" |
| | | #include "SecsTestDlg.h" |
| | | #include "AlarmManager.h" |
| | | #include <chrono> |
| | | #include <thread> |
| | | #include <cmath> |
| | |
| | | |
| | | void CServoDlg::RotateRobot(float angleInDegrees) |
| | | { |
| | | return; |
| | | // 将角度转换为弧度 |
| | | float angleInRadians = angleInDegrees * (std::acos(-1) / 180.0f); |
| | | float angleInRadians = static_cast<float>(std::acos(-1)) / 180.0f * angleInDegrees; |
| | | |
| | | // 获取机器人图片的当前坐标和中心 |
| | | auto* pImage = m_pGraph->GetImage(IMAGE_ROBOT); |
| | | if (!pImage) return; |
| | | |
| | | // 更新 Rotate 图片的角度,确保角度保持在 [0, 360) 范围内 |
| | | m_pGraph->UpdateImageAngle(IMAGE_ROBOT, static_cast<float>(fmod(pImage->angle + angleInDegrees + 360, 360))); |
| | | |
| | | 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)); |
| | | if (pRobot1 && pRobot2) { |
| | | int newArmX1 = pImage->x + 20; |
| | | int newArmY1 = 294; |
| | | |
| | | 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)); |
| | | int newArmX2 = pImage->x + 73; |
| | | int newArmY2 = 294; |
| | | |
| | | // 更新指示框的位置 |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM1, newArmX1, newArmY1); |
| | | m_pGraph->UpdateIndicateBoxCoordinates(INDICATE_ROBOT_ARM2, newArmX2, newArmY2); |
| | | if (angleInDegrees != 0.0f) { |
| | | // 计算指示框1的新坐标 |
| | | newArmX1 = static_cast<int>(cx + (pRobot1->x - cx) * cos(angleInRadians) - (pRobot1->y - cy) * sin(angleInRadians)); |
| | | newArmY1 = static_cast<int>(cy + (pRobot1->x - cx) * sin(angleInRadians) + (pRobot1->y - cy) * cos(angleInRadians)); |
| | | |
| | | // 计算指示框2的新坐标 |
| | | newArmX2 = static_cast<int>(cx + (pRobot2->x - cx) * cos(angleInRadians) - (pRobot2->y - cy) * sin(angleInRadians)); |
| | | 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(); |
| | | } |
| | | |