| 456 | } |
| 457 | |
| 458 | void SDFEditor::rotateGridPlane( |
| 459 | const float mouseDiff, |
| 460 | const float3& rotationVector, |
| 461 | const float3& inNormal, |
| 462 | const float3& inRightVector, |
| 463 | float3& outNormal, |
| 464 | float3& outRightVector, |
| 465 | const bool fromPreviousMouse |
| 466 | ) |
| 467 | { |
| 468 | const float diagonal = length(float2(mFrameDim)); |
| 469 | const float maxAngle = float(M_PI) * 0.05f; |
| 470 | float angle; |
| 471 | |
| 472 | if (fromPreviousMouse) |
| 473 | { |
| 474 | const float speedFactor = 2.0f * float(M_PI) * 0.075f / diagonal; |
| 475 | angle = mouseDiff * std::abs(mouseDiff) * speedFactor; |
| 476 | angle = std::clamp(angle, -maxAngle, maxAngle); |
| 477 | } |
| 478 | else // From the start position -- which is better when doing constrained rotation (around a single axis). |
| 479 | { |
| 480 | const float speedFactor = 2.0f * float(M_PI) * 0.5f / diagonal; |
| 481 | angle = mouseDiff * speedFactor; |
| 482 | } |
| 483 | float4x4 rotationMatrix = math::rotate(float4x4::identity(), angle, rotationVector); |
| 484 | |
| 485 | outNormal = normalize(transformVector(rotationMatrix, inNormal)); |
| 486 | outRightVector = normalize(transformVector(rotationMatrix, inRightVector)); |
| 487 | } |
| 488 | |
| 489 | void SDFEditor::translateGridPlane(const float mouseDiff, const float3& translationVector, const float3& inPosition, float3& outPosition) |
| 490 | { |