Tips - Raycasting with Orthogonal and Perspective camera styles
This code can be used in the OnMousedown event etc.
Given the x and y screen positions, the world positions are calculated on the near and far planes.
These positions are used to get the start position and the direction vector of the ray that can be passed to the various Raycast intersect functions.
I can confirm that the code works with both Perspective and Orthogonal camera styles. Ortho2d and InfinitePerspective haven't been tested.
//variables used
var
p0,p1,raystart,rayvector,ipoint:TVector;
//get the point near the camera (near plane)
p0:=viewer.Buffer.ScreenToWorld(vectormake(x,viewer.height-y,0));
//get the point on the far plane
p1:=viewer.Buffer.ScreenToWorld(vectormake(x,viewer.height-y,1));
//Use the values for raycasting
raystart:=p0;
rayvector:=vectornormalize(vectorsubtract(p1,p0));
if not plane.RayCastIntersect(raystart, rayvector, @ipoint) then
exit;