protected Vector3D?IntersectExact(MyCubeGrid grid, ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock) { double num; intersection = Vector3D.Zero; LineD line = new LineD(IntersectionStart, IntersectionStart + (IntersectionDirection * IntersectionDistance)); Vector3D?nullable = grid.GetLineIntersectionExactAll(ref line, out num, out intersectedBlock); if (nullable != null) { Vector3D vectord = Vector3D.Transform(IntersectionStart, (MatrixD)inverseGridWorldMatrix); intersection = vectord + (num * Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, (MatrixD)inverseGridWorldMatrix))); intersection *= 1f / grid.GridSize; } return(nullable); }
/// <summary> /// Calculates exact intersection point (in uniform grid coordinates) of eye ray with the given grid of all cubes. /// Returns position of intersected object in uniform grid coordinates /// </summary> protected Vector3D?IntersectExact(MyCubeGrid grid, ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock) { intersection = Vector3D.Zero; var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance); double distance; Vector3D?intersectedObjectPos = grid.GetLineIntersectionExactAll(ref line, out distance, out intersectedBlock); if (intersectedObjectPos != null) { Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix); Vector3D rayDir = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix)); intersection = rayStart + distance * rayDir; intersection *= 1.0f / grid.GridSize; } return(intersectedObjectPos); }
/// <summary> /// Calculates exact intersection point (in uniform grid coordinates) of eye ray with the given grid of all cubes. /// Returns position of intersected object in uniform grid coordinates /// </summary> protected Vector3D? IntersectExact(MyCubeGrid grid, ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock) { intersection = Vector3D.Zero; var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance); double distance; Vector3D? intersectedObjectPos = grid.GetLineIntersectionExactAll(ref line, out distance, out intersectedBlock); if (intersectedObjectPos != null) { Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix); Vector3D rayDir = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix)); intersection = rayStart + distance * rayDir; intersection *= 1.0f / grid.GridSize; } return intersectedObjectPos; }