@@ -50,37 +50,28 @@ private Vector3 GetCoordVector(Vector3D pointVector)
5050
5151 private double GetYDrag ( Point endPoint , Vector3 coordVector )
5252 {
53- // 1.Create a plane at the highlighted point using its position and camera forward vector
54- // 2.Calculate a ray using the camera and mouse x,y position
55- // 3.Intersect the ray with the plane giving a point in world space
56-
57- // Repeat 1,2,3 using the start point and actual mouse point
58- // Calculate the Y delta using 2 positions in world space
59-
6053 if ( Viewport3D == null || coordVector == null ) return double . NaN ;
6154
55+ // Project 3D point to screen, cast a ray through that screen pixel,
56+ // find where the ray intersects a plane perpendicular to the camera
57+ // passing through the original 3D point, and return the Y of that intersection.
6258 var camera = Viewport3D . GetWorld ( ) . GetMainCamera ( ) ;
63- var pointPlane = new TSRPlane ( camera . m_Fwd , coordVector ) ;
64-
6559 var rayStart = new TSRVector3 ( ) ;
6660 var rayDirection = new TSRVector3 ( ) ;
6761 var rayEnd = new TSRVector3 ( ) ;
68-
6962 var viewport = new TSRViewPort
7063 {
7164 Width = Convert . ToUInt32 ( Viewport3D . ViewportSize . Width ) ,
7265 Height = Convert . ToUInt32 ( Viewport3D . ViewportSize . Height )
7366 } ;
7467
75- int iScreenX = 0 ;
76- int iScreenY = 0 ;
77- float fDepth = 0.0f ;
78- camera . TransformIntoScreenCoords ( viewport , coordVector , out iScreenX , out iScreenY , out fDepth ) ;
79- camera . ComputeRay ( viewport , ( int ) iScreenX , ( int ) endPoint . Y , rayStart , rayDirection ) ;
68+ camera . TransformIntoScreenCoords ( viewport , coordVector , out var screenX , out var screenY , out var depth ) ;
69+ camera . ComputeRay ( viewport , ( int ) screenX , ( int ) endPoint . Y , rayStart , rayDirection ) ;
8070 rayEnd . x = rayStart . x + rayDirection . x ;
8171 rayEnd . y = rayStart . y + rayDirection . y ;
8272 rayEnd . z = rayStart . z + rayDirection . z ;
8373
74+ var pointPlane = new TSRPlane ( camera . m_Fwd , coordVector ) ;
8475 var endVector = pointPlane . Split ( rayStart , rayEnd ) ;
8576 return endVector . y ;
8677 }
0 commit comments