private Vector3 GetBoneOnSphere(Vector3I center, Vector3I bonePos, MyCubeGrid grid) { Vector3D worldCenter = BoneToWorld(center, Vector3.Zero, grid); Vector3D worldBone = BoneToWorld(bonePos, Vector3.Zero, grid); BoundingSphereD sphere = new BoundingSphereD(worldCenter, grid.GridSize); Vector3D direction = worldCenter - worldBone; direction.Normalize(); RayD ray = new RayD(worldBone, direction); double tmin, tmax; if (sphere.IntersectRaySphere(ray, out tmin, out tmax)) { Vector3D onSphere = worldBone + direction * tmin; var worldOnSphere = Vector3D.Transform(onSphere, grid.PositionComp.WorldMatrixInvScaled); worldOnSphere += new Vector3D(grid.GridSize / grid.Skeleton.BoneDensity); return(worldOnSphere - (Vector3D)(bonePos / (float)grid.Skeleton.BoneDensity) * grid.GridSize); } else { return(Vector3.Zero); } }
private void CheckInput() { MatrixD headMatrix = MyAPIGateway.Session.ControlledObject.GetHeadMatrix(true); RayD ray = new RayD(headMatrix.Translation, headMatrix.Forward); BoundingSphereD holoSphere = new BoundingSphereD(m_offset.ToWorld(m_block), m_radiusHolo); double tmin, tmax; if (!holoSphere.IntersectRaySphere(ray, out tmin, out tmax) || tmin > CrosshairRange) { return; } int scroll = MyAPIGateway.Input.DeltaMouseScrollWheelValue(); if (scroll != 0) { int scrollSteps = (int)Math.Round(scroll * InputScrollMulti); float rangeMulti = 1f; while (scrollSteps > 0) { rangeMulti *= ScrollRangeMulti; scrollSteps--; } while (scrollSteps < 0) { rangeMulti /= ScrollRangeMulti; scrollSteps++; } m_rangeDetection *= rangeMulti; } if (MyAPIGateway.Input.IsNewRightMousePressed()) { m_centreEntityId = 0L; } else if (MyAPIGateway.Input.IsNewLeftMousePressed()) { IMyEntity firstHit = null; double firstHitDistance = CrosshairRange; foreach (SeenHolo sh in m_holoEntities.Values) { if (sh.Holo.Render.Visible && sh.Holo.PositionComp.WorldAABB.Intersect(ref ray, out tmin, out tmax) && tmin < firstHitDistance) { firstHit = sh.Seen.Entity; firstHitDistance = tmin; } } if (firstHit != null) { m_centreEntityId = firstHit.EntityId; } } }
public static bool Intersect(this BoundingSphereD Sphere, ref LineD line, out LineD intersectedLine) { var ray = new RayD(line.From, line.Direction); double t1, t2; if (!Sphere.IntersectRaySphere(ray, out t1, out t2)) { intersectedLine = line; return(false); } t1 = Math.Max(t1, 0); t2 = Math.Min(t2, line.Length); intersectedLine.From = line.From + line.Direction * t1; intersectedLine.To = line.From + line.Direction * t2; intersectedLine.Direction = line.Direction; intersectedLine.Length = t2 - t1; return(true); }
private void CheckInput() { MatrixD headMatrix = MyAPIGateway.Session.ControlledObject.GetHeadMatrix(true); RayD ray = new RayD(headMatrix.Translation, headMatrix.Forward); BoundingSphereD holoSphere = new BoundingSphereD(m_offset.ToWorld(m_block), m_radiusHolo.Value); double tmin, tmax; if (!holoSphere.IntersectRaySphere(ray, out tmin, out tmax) || tmin > CrosshairRange) return; int scroll = MyAPIGateway.Input.DeltaMouseScrollWheelValue(); if (scroll != 0) { int scrollSteps = (int)Math.Round(scroll * InputScrollMulti); float rangeMulti = 1f; while (scrollSteps > 0) { rangeMulti *= ScrollRangeMulti; scrollSteps--; } while (scrollSteps < 0) { rangeMulti /= ScrollRangeMulti; scrollSteps++; } m_rangeDetection.Value *= rangeMulti; } if (MyAPIGateway.Input.IsNewRightMousePressed()) { m_centreEntityId.Value = 0L; } else if (MyAPIGateway.Input.IsNewLeftMousePressed()) { IMyEntity firstHit = null; double firstHitDistance = CrosshairRange; foreach (SeenHolo sh in m_holoEntities.Values) if (sh.Holo.Render.Visible && sh.Holo.PositionComp.WorldAABB.Intersect(ref ray, out tmin, out tmax) && tmin < firstHitDistance) { firstHit = sh.Seen.Entity; firstHitDistance = tmin; } if (firstHit != null) m_centreEntityId.Value = firstHit.EntityId; } }
private Vector3 GetBoneOnSphere(Vector3I center, Vector3I bonePos, MyCubeGrid grid) { Vector3D worldCenter = BoneToWorld(center, Vector3.Zero, grid); Vector3D worldBone = BoneToWorld(bonePos, Vector3.Zero, grid); BoundingSphereD sphere = new BoundingSphereD(worldCenter, grid.GridSize); Vector3D direction = worldCenter - worldBone; direction.Normalize(); RayD ray = new RayD(worldBone, direction); double tmin, tmax; if (sphere.IntersectRaySphere(ray, out tmin, out tmax)) { Vector3D onSphere = worldBone + direction * tmin; var worldOnSphere = Vector3D.Transform(onSphere, grid.PositionComp.WorldMatrixInvScaled); worldOnSphere += new Vector3D(grid.GridSize / MyGridSkeleton.BoneDensity); return (worldOnSphere - (Vector3D)(bonePos / (float)MyGridSkeleton.BoneDensity) * grid.GridSize); } else { return Vector3.Zero; } }