Screen to volume transform?
#7
(02-14-2017, 10:54 AM)abenedik Wrote: When using cameras from Ab3d.PowerToys library, you can easily get the 2D point on the screen from the 3D position with using the Point3DTo2D method on a Ab3d.PowerToys camera.

Then should I switch to using the Ab3dPowerToys camera instead of the Viewport3D camera? How easy is it to replace the Viewport3D camera, what does the XAML and c# look like and what are the consequences?

Quote:If you are not using Ab3d.PowerToys cameras, you can get the 2D screen position with first calculating the view-projection matrix (see viewProj in my previous post).

I didn't understand that matrix, which depends on viewProj because I didn't understand width and height as mentioned in that post . . .
Quote:Matrix.LookAtRH(ref cameraPosition, ref target, ref up, out viewMatrix);

var orthoMatrix = Matrix.OrthoRH(width, height, zNear, zFar);

var viewProj = viewMatrix * orthoMatrix ;

... but I haven't explicitly declared a view volume anywhere and I don't see how a camera with near and far plane distances and a look direction can implicitly specify a volume (because there are no explicit right/left sides or top/bottom, so what goes in width and height for the orthoRH? The MainViewport has a Height and ActualHeight and Width and ActualWith in pixels space - 564 and 936 - but that's clearly not the coordinate system the lines are in. Orthographic cameras have a Width property (but no Height) too but I'm not specifying it in my example.

Quote:Then you need to need to multiply the 3D position (converted into Point4D) with viewProjection and divide by w:

Code:
Point4D point4d = ((Point4D)point3D) * viewProj;

if (point4d.W != 0)
     screenPosition = new Point(point4d.X / point4d.W, point4d.Y / point4d.W);
else
     screenPosition = new Point(double.NaN, double.NaN);

To calculate the ray from 2D position to 3D space, you can use the Ab3d.Cameras.BaseCamera.CreateMouseRay3D static method - the following is the method signature:

public static bool CreateMouseRay3D(Point mousePosition, Size viewportSize, ref Matrix3D viewMatrix, ref Matrix3D projectionMatrix, out Point3D rayOrigin, out Vector3D rayDirection)

Summary:
1. I need to decide if it would be easier to use a power toys camera instead of the one I have now
2. If I stick with the camera I have now I need to understand how to build the matrices
  


Messages In This Thread
Screen to volume transform? - by pnelsonAG - 01-20-2017, 12:26 AM
RE: Screen to volume transform? - by abenedik - 01-23-2017, 09:45 PM
RE: Screen to volume transform? - by pnelsonAG - 01-27-2017, 10:32 PM
RE: Screen to volume transform? - by abenedik - 01-27-2017, 11:02 PM
RE: Screen to volume transform? - by pnelsonAG - 02-14-2017, 02:18 AM
RE: Screen to volume transform? - by abenedik - 02-14-2017, 10:54 AM
RE: Screen to volume transform? - by pnelsonAG - 02-14-2017, 07:05 PM
RE: Screen to volume transform? - by abenedik - 02-15-2017, 10:05 AM

Forum Jump:


Users browsing this thread:
2 Guest(s)