Skip to content

Commit b0a12e2

Browse files
committed
improve how is calculated mouse position in Revit model
1 parent 447adf1 commit b0a12e2

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

sources/RevitDBExplorer/Application.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public static (string, XYZ, XYZ, bool) GetMouseStatus()
139139
var min = corners[0];
140140
var max = corners[1];
141141
var v = max - min;
142-
var l = v.GetLength();
143142

144143
var vr = dx * new XYZ(v.X * view.RightDirection.X, v.Y * view.RightDirection.Y, v.Z * view.RightDirection.Z);
145144
var vu = dy * new XYZ(v.X * view.UpDirection.X, v.Y * view.UpDirection.Y, v.Z * view.UpDirection.Z);
@@ -150,31 +149,45 @@ public static (string, XYZ, XYZ, bool) GetMouseStatus()
150149
min -= vv;
151150
max -= vv;
152151

153-
if ((Math.Abs(view.RightDirection.X) < 0.999) && (Math.Abs(view.RightDirection.Y) < 0.999) && (Math.Abs(view.RightDirection.Z) < 0.999))
154-
{
155-
return ("(?,,)", min, max, false);
156-
}
157-
if ((Math.Abs(view.UpDirection.X) < 0.999) && (Math.Abs(view.UpDirection.Y) < 0.999) && (Math.Abs(view.UpDirection.Z) < 0.999))
158-
{
159-
return ("(,?,)", min, max, false);
160-
}
161-
if ((Math.Abs(view.ViewDirection.X) < 0.999) && (Math.Abs(view.ViewDirection.Y) < 0.999) && (Math.Abs(view.ViewDirection.Z) < 0.999))
152+
//
153+
154+
var upDirection = view.UpDirection;
155+
var forwardDirection = view.ViewDirection;
156+
157+
if (view is View3D view3D)
162158
{
163-
return ("(,,?)", min, max, false);
164-
}
159+
if (view3D.IsPerspective)
160+
{
161+
return ("(?,,)", min, max, false);
162+
}
163+
164+
var orientation = view3D.GetOrientation();
165+
upDirection = orientation.UpDirection;
166+
forwardDirection = orientation.ForwardDirection;
167+
}
168+
169+
var rightDirection = forwardDirection.CrossProduct(upDirection).Normalize();
170+
171+
var diagVector = corners[0] - corners[1];
172+
double height = Math.Abs(diagVector.DotProduct(view.UpDirection));
173+
double width = Math.Abs(diagVector.DotProduct(view.RightDirection));
174+
175+
var r = corners[0] + (rightDirection * width * dx) + (upDirection * height * dy);
165176

166177
if (view.ViewDirection.IsParallelTo(XYZ.BasisX))
167178
{
168-
return ($"(-,--, {q.Y:f3}, {q.Z:f3})", min, max, true);
179+
return ($"(-,--, {r.Y:f3}, {r.Z:f3})", min, max, true);
169180
}
170181
if (view.ViewDirection.IsParallelTo(XYZ.BasisY))
171182
{
172-
return ($"({q.X:f3}, -,--, {q.Z:f3})", min, max, true);
183+
return ($"({r.X:f3}, -,--, {r.Z:f3})", min, max, true);
173184
}
174185
if (view.ViewDirection.IsParallelTo(XYZ.BasisZ))
175186
{
176-
return ($"({q.X:f3}, {q.Y:f3}, -,--)", min, max, true);
187+
return ($"({r.X:f3}, {r.Y:f3}, -,--)", min, max, true);
177188
}
189+
190+
return ("(-,--,-,--,-,--)", XYZ.Zero, XYZ.Zero, true);
178191
}
179192
catch
180193
{

sources/RevitDBExplorer/Domain/Selectors/SnoopElementsOnScreen.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using Autodesk.Revit.DB;
45
using Autodesk.Revit.UI;
@@ -36,7 +37,8 @@ public IEnumerable<SnoopableObject> Snoop(UIApplication app)
3637
//var deltaBottom = currentElevation - bottomElevation;
3738
}
3839

39-
var view = app.ActiveUIDocument.ActiveView;
40+
var view = app.ActiveUIDocument.ActiveGraphicalView;
41+
if (view == null) return null;
4042

4143
if (view.ViewDirection.IsParallelTo(XYZ.BasisX) == false && view.ViewDirection.IsParallelTo(XYZ.BasisY) == false && view.ViewDirection.IsParallelTo(XYZ.BasisZ) == false)
4244
return null;

0 commit comments

Comments
 (0)