protected Vector3I?IntersectCubes(MyCubeGrid grid, out double distance) { distance = 3.4028234663852886E+38; LineD line = new LineD(IntersectionStart, IntersectionStart + (IntersectionDirection * IntersectionDistance)); Vector3I zero = Vector3I.Zero; double maxValue = double.MaxValue; if (grid.GetLineIntersectionExactGrid(ref line, ref zero, ref maxValue)) { distance = Math.Sqrt(maxValue); return(new Vector3I?(zero)); } return(null); }
protected Vector3I?IntersectCubes(MyCubeGrid grid, out double distance) { distance = float.MaxValue; var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance); Vector3I position = Vector3I.Zero; double dstSqr = double.MaxValue; if (grid.GetLineIntersectionExactGrid(ref line, ref position, ref dstSqr)) { distance = Math.Sqrt(dstSqr); return(position); } return(null); }
protected Vector3I? IntersectCubes(MyCubeGrid grid, out double distance) { distance = float.MaxValue; var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance); Vector3I position = Vector3I.Zero; double dstSqr = double.MaxValue; if (grid.GetLineIntersectionExactGrid(ref line, ref position, ref dstSqr)) { distance = Math.Sqrt(dstSqr); return position; } return null; }
public override void Draw() { base.Draw(); if (!MyFakes.ENABLE_ARMOR_HAND) { return; } Vector3 forward = MySector.MainCamera.ForwardVector; Vector3D origin = MySector.MainCamera.Position; Vector3D end = origin + forward * 100f; m_lastCubeGrid = null; m_lastBone = null; var hitInfo = MyPhysics.CastRay(origin, end, MyPhysics.CollisionLayers.ExplosionRaycastLayer); var hitEntity = hitInfo.HasValue ? ((MyPhysicsBody)hitInfo.Value.HkHitInfo.Body.UserObject).Entity : null; var grid = (hitEntity as MyCubeGrid); if (grid != null) { m_lastCubeGrid = grid; double shortestDistance = double.MaxValue; LineD line = new LineD(origin, end); Vector3I hitCube = new Vector3I(); double distanceSquared = double.MaxValue; if (m_lastCubeGrid.GetLineIntersectionExactGrid(ref line, ref hitCube, ref distanceSquared)) { m_lastCube = hitCube; } else { m_lastCube = null; } foreach (var bone in grid.Skeleton.Bones) { var bonePos = (Vector3D)(bone.Key / (float)MyGridSkeleton.BoneDensity) * grid.GridSize + bone.Value; bonePos -= new Vector3D(grid.GridSize / MyGridSkeleton.BoneDensity); Vector3D pos = Vector3D.Transform(bonePos, grid.PositionComp.WorldMatrix); Color color = Color.Red; double distance = MyUtils.GetPointLineDistance(ref origin, ref end, ref pos); if (distance < 0.1f) { double distanceToCamera = (origin - pos).LengthSquared(); if (distanceToCamera < shortestDistance) { shortestDistance = distanceToCamera; color = Color.Blue; m_lastBone = bone.Key; } } MyRenderProxy.DebugDrawSphere(pos, 0.05f, color.ToVector3(), 0.5f, false, true); } } }