| 96 | { |
| 97 | |
| 98 | void performPatchRotateTest(bool clockwise) |
| 99 | { |
| 100 | auto worldspawn = GlobalMapModule().findOrInsertWorldspawn(); |
| 101 | auto patchNode = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1"); |
| 102 | |
| 103 | auto patch = Node_getIPatch(patchNode); |
| 104 | patch->scaleTextureNaturally(); |
| 105 | patch->controlPointsChanged(); |
| 106 | |
| 107 | Node_setSelected(patchNode, true); |
| 108 | |
| 109 | auto bounds = algorithm::getTextureSpaceBounds(*patch); |
| 110 | |
| 111 | std::vector<Vector2> oldTexCoords; |
| 112 | algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { oldTexCoords.push_back(ctrl.texcoord); }); |
| 113 | |
| 114 | // Set the rotation in the registry, TexRotate will pick it up |
| 115 | constexpr auto angle = 15.0f; |
| 116 | registry::setValue("user/ui/textures/surfaceInspector/rotStep", angle); |
| 117 | GlobalCommandSystem().executeCommand("TexRotate", { cmd::Argument(clockwise ? "1" : "-1") }); |
| 118 | |
| 119 | // Rotate each texture coordinate around the patch center with a manual transform |
| 120 | auto transform = Matrix3::getTranslation({ -bounds.origin.x(), -bounds.origin.y() }); |
| 121 | transform.premultiplyBy(Matrix3::getRotation(degrees_to_radians(clockwise ? angle : -angle))); |
| 122 | transform.premultiplyBy(Matrix3::getTranslation({ bounds.origin.x(), bounds.origin.y() })); |
| 123 | |
| 124 | auto old = oldTexCoords.begin(); |
| 125 | algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) |
| 126 | { |
| 127 | auto transformed = transform * (*old++); |
| 128 | EXPECT_TRUE(math::isNear(transformed, ctrl.texcoord, 0.02)) |
| 129 | << "Transformed UV coords should be " << transformed << " but was " << ctrl.texcoord; |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | } |
| 134 |
no test coverage detected