Beispiel #1
0
        public static Vector3D?GetLineIntersectionExactAll(MyCubeGrid grid, ref LineD line, out double distance, out IMySlimBlock intersectedBlock)
        {
            intersectedBlock = (IMySlimBlock)null;
            distance         = 3.40282346638529E+38;
            Vector3I?nullable        = new Vector3I?();
            Vector3I zero            = Vector3I.Zero;
            double   distanceSquared = double.MaxValue;

            if (grid.GetLineIntersectionExactGrid(ref line, ref zero, ref distanceSquared))
            {
                distanceSquared = Math.Sqrt(distanceSquared);
                nullable        = new Vector3I?(zero);
            }
            if (!nullable.HasValue)
            {
                return(new Vector3D?());
            }
            distance         = distanceSquared;
            intersectedBlock = grid.GetCubeBlock(nullable.Value);
            if (intersectedBlock == null)
            {
                return(new Vector3D?());
            }
            return(new Vector3D?((Vector3D)zero));
        }
        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.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)grid.Skeleton.BoneDensity) * grid.GridSize + bone.Value;
                    bonePos -= new Vector3D(grid.GridSize / grid.Skeleton.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);
                }
            }
        }