| 1087 | } |
| 1088 | |
| 1089 | void CameraArcBallDemo::onTouchsMoved(const std::vector<Touch*>& touchs, Event* event) |
| 1090 | { |
| 1091 | if (!touchs.empty()) |
| 1092 | { |
| 1093 | if (_operate == OperateCamType::RotateCamera) // arc ball rotate |
| 1094 | { |
| 1095 | Size visibleSize = Director::getInstance()->getVisibleSize(); |
| 1096 | Vec2 prelocation = touchs[0]->getPreviousLocationInView(); |
| 1097 | Vec2 location = touchs[0]->getLocationInView(); |
| 1098 | location.x = 2.0f * (location.x) / (visibleSize.width) - 1.0f; |
| 1099 | location.y = 2.0f * (visibleSize.height - location.y) / (visibleSize.height) - 1.0f; |
| 1100 | prelocation.x = 2.0f * (prelocation.x) / (visibleSize.width) - 1.0f; |
| 1101 | prelocation.y = 2.0f * (visibleSize.height - prelocation.y) / (visibleSize.height) - 1.0f; |
| 1102 | |
| 1103 | Vec3 axes; |
| 1104 | float angle; |
| 1105 | calculateArcBall(axes, angle, prelocation.x, prelocation.y, location.x, |
| 1106 | location.y); // calculate rotation quaternion parameters |
| 1107 | Quaternion quat(axes, angle); // get rotation quaternion |
| 1108 | _rotationQuat = quat * _rotationQuat; |
| 1109 | |
| 1110 | updateCameraTransform(); // update camera Transform |
| 1111 | } |
| 1112 | else if (_operate == OperateCamType::MoveCamera) // camera zoom |
| 1113 | { |
| 1114 | Point newPos = touchs[0]->getPreviousLocation() - touchs[0]->getLocation(); |
| 1115 | _distanceZ -= newPos.y * 0.1f; |
| 1116 | |
| 1117 | updateCameraTransform(); |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | void CameraArcBallDemo::calculateArcBall(ax::Vec3& axis, float& angle, float p1x, float p1y, float p2x, float p2y) |
| 1123 | { |
nothing calls this directly
no test coverage detected