static Ray3d GetCameraRay(V2d uv, M44d invViewProj) { var deviceCoord = new V2d(uv.X * 2 - 1, -uv.Y * 2 + 1); var nearPoint = invViewProj.TransformPosProj(deviceCoord.XYO); var farPoint = invViewProj.TransformPosProj(deviceCoord.XYI); return(new Ray3d(nearPoint, (farPoint - nearPoint).Normalized)); }
/// <summary> /// Projects outline of a box from given position to a plane. /// Returns null if position is inside the box. /// </summary> /// <param name="box"></param> /// <param name="fromPosition"></param> /// <param name="box2plane">Transformation from world/box-space to plane z=0</param> public static V2d[] GetOutlineProjected(this Box3d box, V3d fromPosition, M44d box2plane) { var ps = box.GetOutlineCornersCW(fromPosition); if (ps == null) { return(null); } var qs = ps.Map(p => box2plane.TransformPosProj(p)); var behindPositionCount = 0; for (var i = 0; i < qs.Length; i++) { if (qs[i].Z < 0.0) { behindPositionCount++; } } if (behindPositionCount == qs.Length) { return(new V2d[0]); } if (behindPositionCount > 0) { return(null); } return(qs.Map(p => p.XY)); }