Skip to content

Commit

Permalink
Improve face distance snapping for brush resizing.
Browse files Browse the repository at this point in the history
Signed-off-by: Kristian Duske <[email protected]>
  • Loading branch information
kduske committed Sep 22, 2013
1 parent 6f4171b commit 64dd375
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Mac/TrenchBroom/TrenchBroom-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>1.1.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2732</string>
<string>2737</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
Expand Down
7 changes: 6 additions & 1 deletion Source/Controller/ResizeBrushesTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ namespace TrenchBroom {
Utility::Grid& grid = document().grid();
const Vec3f relativeFaceDelta = grid.snap(dragDistance) * faceNormal3D;
const Vec3f absoluteFaceDelta = grid.moveDelta(dragFace, faceNormal3D * dragDistance);
const Vec3f faceDelta = relativeFaceDelta.lengthSquared() < absoluteFaceDelta.lengthSquared() ? relativeFaceDelta : absoluteFaceDelta;

// select the delta that is closest to the actual delta indicated by the mouse cursor
const Vec3f faceDelta = (std::abs(relativeFaceDelta.length() - dragDistance) <
std::abs(absoluteFaceDelta.length() - dragDistance) ?
relativeFaceDelta :
absoluteFaceDelta);

if (faceDelta.null())
return true;
Expand Down
9 changes: 5 additions & 4 deletions Source/Utility/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ namespace TrenchBroom {
if (gridSkip > 0)
--gridSkip;
float actualDist = std::numeric_limits<float>::max();
float minDistDelta = std::numeric_limits<float>::max();

do {
// Find the smallest drag distance at which the face boundary is actually moved
Expand All @@ -308,15 +309,15 @@ namespace TrenchBroom {
const Vec3f vertexDelta = ray.direction * vertexDist;
const float vertexNormDist = vertexDelta.dot(face.boundary().normal);

if (std::abs(vertexNormDist) < std::abs(actualDist))
const float normDistDelta = std::abs(vertexNormDist - dist);
if (normDistDelta < minDistDelta) {
actualDist = vertexNormDist;
minDistDelta = normDistDelta;
}
}
++gridSkip;
} while (actualDist == std::numeric_limits<float>::max());

if (std::abs(actualDist) > std::abs(dist))
return Vec3f::Null;

normDelta = face.boundary().normal * actualDist;
const Vec3f deltaNormalized = delta.normalized();
return deltaNormalized * normDelta.dot(deltaNormalized);
Expand Down
2 changes: 1 addition & 1 deletion Windows/TrenchBroom/BuildNo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
365
366

0 comments on commit 64dd375

Please sign in to comment.