private void DrawHudOnce()
        {
            foreach (var textureToDraw in _drawList)
            {
                if (textureToDraw.UvDraw)
                {
                    MyQuadD quad;
                    MyUtils.GetBillboardQuadOriented(out quad, ref textureToDraw.Position, textureToDraw.Width, textureToDraw.Height, ref textureToDraw.Left, ref textureToDraw.Up);

                    if (textureToDraw.Color != Color.Transparent)
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                    }
                    else
                    {
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                        MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                    }
                }
                else
                {
                    textureToDraw.Position = Vector3D.Transform(textureToDraw.Position, _cameraWorldMatrix);
                    MyTransparentGeometry.AddBillboardOriented(textureToDraw.Material, textureToDraw.Color, textureToDraw.Position, _cameraWorldMatrix.Left, _cameraWorldMatrix.Up, textureToDraw.Height, textureToDraw.Blend);
                }

                if (!textureToDraw.Persistant)
                {
                    _textureDrawPool.Enqueue(textureToDraw);
                }
            }
        }
Exemple #2
0
        void UpdateTreadmill()
        {
            if (!IsControlled)
            {
                return;
            }

            MatrixD matrix = cockpit.WorldMatrix;

            matrix *= MatrixD.CreateFromAxisAngle(matrix.Right, MathHelper.ToRadians(5));

            treadmillCounter += treadmillUVOffset;

            if (treadmillCounter > 1)
            {
                treadmillCounter = 0;
            }

            Vector2 offset = new Vector2(treadmillCounter, 0);

            MyTransparentGeometry.AddBillboardOriented(
                MyStringId.GetOrCompute("Treadmill"),
                Color.White.ToVector4(),
                cockpit.GetPosition() + (cockpit.WorldMatrix.Up * -0.948f) + (cockpit.WorldMatrix.Forward * -0.2f),
                matrix.Backward,
                matrix.Right,
                0.6f,
                0.25f,
                Vector2.Zero + offset);
        }
        public void DrawHud(IMyCameraController camera, long playerId)
        {
            MyGunStatusEnum status;

            CanShoot(MyShootActionEnum.PrimaryAction, playerId, out status);

            if (status == MyGunStatusEnum.OK || status == MyGunStatusEnum.Cooldown)
            {
                var matrix = m_gunBase.GetMuzzleWorldMatrix();
                var from   = matrix.Translation;
                var to     = from + 50 * matrix.Forward;

                Vector3D target = Vector3D.Zero;
                if (MyHudCrosshair.GetTarget(from, to, ref target))
                {
                    float distance = (float)Vector3D.Distance(MySector.MainCamera.Position, target);

                    MyTransparentGeometry.AddBillboardOriented(
                        "RedDot",
                        Vector4.One,
                        target,
                        MySector.MainCamera.LeftVector,
                        MySector.MainCamera.UpVector,
                        distance / 300.0f);
                }
            }
        }
Exemple #4
0
        private void updateCamera(IMyEntity target)
        {
            if (target == null)
            {
                return;
            }

            hasCamTarget = true;

            var          Material = MyStringId.GetOrCompute("Crosshair");
            float        width    = (float)target.WorldAABB.Extents.X;
            float        height   = (float)target.WorldAABB.Extents.Z;
            BoundingBoxD box      = target.WorldAABB;

            box.Translate(target.WorldMatrix);
            Vector3D center = target.WorldAABB.Min;

            center.X += box.HalfExtents.X;
            center.Y += box.HalfExtents.Y;
            center.Z += box.HalfExtents.Z;

            try {
                MyTransparentGeometry.AddBillboardOriented(Material, Color.WhiteSmoke.ToVector4(), center, MyAPIGateway.Session.Camera.WorldMatrix.Left, MyAPIGateway.Session.Camera.WorldMatrix.Up, height, BlendTypeEnum.SDR);
            } catch (NullReferenceException ex) {
                //MyLog.Default.Error("Error while drawing billboard: " + ex);
            }
            //MyLog.Default.WriteLine("Drawing Billbord at: " + center);
        }
        public void DrawHud(IMyCameraController camera, long playerId)
        {
            ProfilerShort.Begin("Can shoot");
            MyGunStatusEnum status;

            CanShoot(MyShootActionEnum.PrimaryAction, playerId, out status);
            ProfilerShort.End();

            if (status == MyGunStatusEnum.OK || status == MyGunStatusEnum.Cooldown)
            {
                var from = PositionComp.GetPosition() + PositionComp.WorldMatrix.Forward;
                var to   = PositionComp.GetPosition() + 50 * PositionComp.WorldMatrix.Forward;

                Vector3D target = Vector3D.Zero;
                if (MyHudCrosshair.GetTarget(from, to, ref target))
                {
                    float distance = (float)Vector3D.Distance(MySector.MainCamera.Position, target);

                    MyTransparentGeometry.AddBillboardOriented(
                        "RedDot",
                        Vector4.One,
                        target,
                        MySector.MainCamera.LeftVector,
                        MySector.MainCamera.UpVector,
                        distance / 300.0f);
                }
            }
        }
        internal void DrawWheel()
        {
            var    position    = new Vector3D(_wheelPosition.X, _wheelPosition.Y, 0);
            var    fov         = Session.Camera.FovWithZoom;
            double aspectratio = Session.Camera.ViewportSize.X / MyAPIGateway.Session.Camera.ViewportSize.Y;
            var    scale       = 0.075 * Math.Tan(fov * 0.5);

            position.X *= scale * aspectratio;
            position.Y *= scale;
            var cameraWorldMatrix = Session.Camera.WorldMatrix;

            position = Vector3D.Transform(new Vector3D(position.X, position.Y, -.1), cameraWorldMatrix);

            var origin = position;
            var left   = cameraWorldMatrix.Left;
            var up     = cameraWorldMatrix.Up;

            scale = 1 * scale;
            var currentItem = GetCurrentMenuItem();
            var foreTexture = currentItem.ForeTexture;
            var backTexture = currentItem.BackTexture;
            var foreColor   = Color.White * Session.UiOpacity;
            var backColor   = Color.White * Session.UiBkOpacity;

            SetCurrentMessage();
            if (backTexture != MyStringId.NullOrEmpty)
            {
                MyTransparentGeometry.AddBillboardOriented(backTexture, backColor, origin, left, up, (float)scale, BlendTypeEnum.PostPP);
            }
            if (foreTexture != MyStringId.NullOrEmpty)
            {
                MyTransparentGeometry.AddBillboardOriented(foreTexture, foreColor, origin, left, up, (float)scale, BlendTypeEnum.PostPP);
            }
        }
        private void DrawNormalGlare(float distance, float maxDistance, Vector3 position, Vector3 cameraToLight)
        {
            if (m_occlusionRatio <= MyMwcMathConstants.EPSILON)
            {
                return;
            }

            var intensity = GetIntensity();

            float alpha = m_occlusionRatio * intensity;

            const int minGlareRadius = 20;
            const int maxGlareRadius = 40;
            float     radius         = MathHelper.Clamp(m_parent.Range, minGlareRadius, maxGlareRadius);

            float drawingRadius = radius;

            cameraToLight = (1.0f / distance) * cameraToLight;
            float dot = Vector3.Dot(cameraToLight, m_parent.ReflectorDirection);

            alpha *= MathHelper.Min(1, 6 * dot);

            if (alpha <= MyMwcMathConstants.EPSILON)
            {
                return;
            }

            if (distance > maxDistance * .5f)
            {
                // distance falloff
                float falloff = (distance - .5f * maxDistance) / (.5f * maxDistance);
                falloff = 1 - falloff;
                if (falloff < 0)
                {
                    falloff = 0;
                }
                drawingRadius *= falloff;
                alpha         *= falloff;
            }

            if (drawingRadius <= float.Epsilon)
            {
                return;
            }

            drawingRadius *= 0.01f * distance;
            if (drawingRadius < radius)
            {
                drawingRadius = radius;
            }

            var color = m_parent.Color;

            color.W = 0;

            MyTransparentGeometry.AddBillboardOriented(
                MyTransparentMaterialEnum.LightGlare, color * alpha, position,
                MyCamera.LeftVector, MyCamera.UpVector, drawingRadius);
        }
 public override void Draw()
 {
     if (m_on)
     {
         Matrix world = WorldMatrix;
         MyTransparentGeometry.AddBillboardOriented(MyTransparentMaterialEnum.scanner_01, Color, world.Translation, world.Left, world.Up, Size.X / 2f, Size.Y / 2f, new Vector2(uvOffset, uvOffset), 0, true);
     }
 }
Exemple #9
0
        private void DrawTarget()
        {
            var s = _session;
            var focus = s.TrackingAi.Focus;
            for (int i = 0; i < focus.TargetState.Length; i++)
            {
                if (focus.Target[i] == null || s.WheelUi.WheelActive && i > 0) continue;

                var targetState = focus.TargetState[i];

                var displayCount = 0;
                foreach (var icon in _targetIcons.Keys)
                {
                    int iconLevel;
                    if (!IconStatus(icon, targetState, out iconLevel)) continue;

                    Vector3D offset;
                    float scale;
                    MyStringId textureName;
                    _targetIcons[icon][iconLevel].GetTextureInfo(i, displayCount, s.WheelUi.WheelActive, s, out textureName, out scale, out offset);
                    var color = Color.White;
                    MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);

                    if (focus.ActiveId == i && displayCount == 0)
                    {
                        var focusTexture = focus.ActiveId == 0 && displayCount == 0 ? _focus : _focusSecondary;
                        MyTransparentGeometry.AddBillboardOriented(focusTexture, Color.White, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                    }

                    displayCount++;
                }
                if (i == focus.ActiveId)
                {
                    var targetSphere = focus.Target[focus.ActiveId].PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos = s.Camera.WorldToScreen(ref targetCenter);
                    var fov = MyAPIGateway.Session.Camera.FovWithZoom;
                    double aspectratio = MyAPIGateway.Session.Camera.ViewportSize.X / MyAPIGateway.Session.Camera.ViewportSize.Y;
                    var screenScale = 0.1 * Math.Tan(fov * 0.5);
                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y = -1;
                    }

                    var dotpos = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));

                    dotpos.X *= (float)(screenScale * aspectratio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);
                }
            }
        }
Exemple #10
0
        private void UpdateIcon(bool reInforce)
        {
            var    position    = new Vector3D(_shieldIconPos.X, _shieldIconPos.Y, 0);
            var    fov         = MyAPIGateway.Session.Camera.FovWithZoom;
            double aspectratio = MyAPIGateway.Session.Camera.ViewportSize.X / MyAPIGateway.Session.Camera.ViewportSize.Y;
            var    scale       = 0.075 * Math.Tan(fov * 0.5);

            position.X *= scale * aspectratio;
            position.Y *= scale;
            var cameraWorldMatrix = MyAPIGateway.Session.Camera.WorldMatrix;

            position = Vector3D.Transform(new Vector3D(position.X, position.Y, -.1), cameraWorldMatrix);

            var origin = position;
            var left   = cameraWorldMatrix.Left;
            var up     = cameraWorldMatrix.Up;

            scale = 0.08 * scale;

            var   percent      = DsState.State.ShieldPercent;
            var   icon2FSelect = percent < 99 ? GetIconMeterfloat() : 0;
            var   heat         = DsState.State.Heat;
            var   icon1        = GetHudIcon1FromFloat(percent);
            var   icon2        = GetHudIcon2FromFloat(icon2FSelect);
            var   icon3        = GetHudIcon3FromInt(heat, _count < 30);
            var   showIcon2    = DsState.State.Online;
            Color color;
            var   flashRed = (percent > 0 && percent < 10 & !reInforce) && _count < 30;

            if (flashRed)
            {
                color = Color.Red;
            }
            else if (reInforce)
            {
                color = Color.LightSkyBlue;
            }
            else
            {
                color = Color.White;
            }

            MyTransparentGeometry.AddBillboardOriented(icon1, color, origin, left, up, (float)scale, BlendTypeEnum.PostPP);
            if (showIcon2 && icon2 != MyStringId.NullOrEmpty)
            {
                MyTransparentGeometry.AddBillboardOriented(icon2, Color.White, origin, left, up, (float)scale * 1.11f, BlendTypeEnum.PostPP);
            }
            if (icon3 != MyStringId.NullOrEmpty)
            {
                MyTransparentGeometry.AddBillboardOriented(icon3, Color.White, origin, left, up, (float)scale * 1.11f, BlendTypeEnum.PostPP);
            }
        }
Exemple #11
0
        void DrawColorSelector(MatrixD camMatrix, Vector3D worldPos, float scaleFOV, float bgAlpha)
        {
            PlayerInfo localInfo = Main.Palette.LocalInfo;

            if (!localInfo.ApplyColor)
            {
                return; // only hide if player hid it
            }
            bool enabled = localInfo.SkinAllowsColor;

            float       squareWidth    = 0.0014f * scaleFOV;
            float       squareHeight   = 0.0010f * scaleFOV;
            float       selectedWidth  = (squareWidth + (squareWidth / 3f));
            float       selectedHeight = (squareHeight + (squareHeight / 3f));
            double      spacingAdd     = 0.0006 * scaleFOV;
            double      spacingWidth   = (squareWidth * 2) + spacingAdd;
            double      spacingHeight  = (squareHeight * 2) + spacingAdd;
            const int   MIDDLE_INDEX   = 7;
            const float BG_WIDTH_MUL   = 3.85f;
            const float BG_HEIGHT_MUL  = 1.3f;

            Color bgColor = Utils.HUDColorAlpha(PALETTE_BG_COLOR, bgAlpha);

            MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_BACKGROUND, bgColor, worldPos, camMatrix.Left, camMatrix.Up, (float)(spacingWidth * BG_WIDTH_MUL), (float)(spacingHeight * BG_HEIGHT_MUL), Vector2.Zero, GUI_BG_BLENDTYPE);

            Vector3D pos = worldPos + camMatrix.Left * (spacingWidth * (MIDDLE_INDEX / 2)) + camMatrix.Up * (spacingHeight / 2);

            for (int i = 0; i < localInfo.ColorsMasks.Count; i++)
            {
                Vector3 colorMask = localInfo.ColorsMasks[i];
                Color   rgb       = Utils.ColorMaskToRGB(colorMask);

                if (!enabled)
                {
                    rgb = rgb.ToGray();
                }

                if (i == MIDDLE_INDEX)
                {
                    pos += camMatrix.Left * (spacingWidth * MIDDLE_INDEX) + camMatrix.Down * spacingHeight;
                }

                if (enabled && i == localInfo.SelectedColorSlot)
                {
                    MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_COLOR, Color.White, pos, camMatrix.Left, camMatrix.Up, selectedWidth, selectedHeight, Vector2.Zero, GUI_FG_BLENDTYPE);
                }

                MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_COLOR, rgb, pos, camMatrix.Left, camMatrix.Up, squareWidth, squareHeight, Vector2.Zero, GUI_FG_BLENDTYPE);

                pos += camMatrix.Right * spacingWidth;
            }
        }
Exemple #12
0
        private void DrawFlightPathMarker(Vector3 direction, Color color)
        {
            var head  = util.Camera.WorldMatrix;
            var width = util.Camera.FovWithZoom * WIDTH_ANGLE;

            MyTransparentGeometry.AddBillboardOriented(
                material: MyStringId.GetOrCompute("WhiteDot"),
                color: color,
                origin: head.Translation + direction * CROSSHAIR_DISTANCE,
                leftVector: head.Left,
                upVector: head.Up,
                radius: width);
        }
Exemple #13
0
        private void DrawSelector()
        {
            var s = _session;

            if (!_cachedPointerPos) InitPointerOffset(0.05);
            if (!_cachedTargetPos) InitTargetOffset();
            var offetPosition = Vector3D.Transform(PointerOffset, _session.CameraMatrix);

            if (s.UiInput.FirstPersonView)
            {
                if (!MyUtils.IsZero(_pointerPosition.Y))
                {
                    _pointerPosition.Y = 0f;
                    InitPointerOffset(0.05);
                }
            }
            else if (s.UiInput.CtrlPressed)
            {
                if (s.UiInput.PreviousWheel != s.UiInput.CurrentWheel)
                {
                    var currentPos = _pointerPosition.Y;
                    if (s.UiInput.CurrentWheel > s.UiInput.PreviousWheel) currentPos += 0.05f;
                    else currentPos -= 0.05f;
                    var clampPos = MathHelper.Clamp(currentPos, -1.25f, 1.25f);
                    _3RdPersonPos.Y = clampPos;
                    InitPointerOffset(0.05);
                }
                if (!MyUtils.IsEqual(_pointerPosition, _3RdPersonPos))
                {
                    _pointerPosition = _3RdPersonPos;
                    InitPointerOffset(0.05);
                }
            }
            else if (!MyUtils.IsEqual(_pointerPosition, _3RdPersonPos))
            {
                _pointerPosition = _3RdPersonPos;
                InitPointerOffset(0.05);
            }
            
            SelectTarget(manualSelect: false);

            if (s.Tick - _lastDrawTick > 1 && _delay++ < 10) return;
            _delay = 0;
            _lastDrawTick = s.Tick;
            MyTransparentGeometry.AddBillboardOriented(_cross, _reticleColor, offetPosition, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)PointerAdjScale, BlendTypeEnum.PostPP);
            DrawReticle = true;
        }
        private void AddBoundingBillboard(bool entered, Vector3 localForward, Vector3 localUp, Vector3 localRight, Vector3 localTranslation, float radius, Vector4 color)
        {
            Matrix localRot = Matrix.Identity;

            localRot.Forward     = localForward;
            localRot.Up          = localUp;
            localRot.Right       = localRight;
            localRot.Translation = localTranslation;
            Matrix matrix = localRot * this.GetOrientation();

            matrix.Translation += this.GetPosition();


            MyTransparentGeometry.AddBillboardOriented(
                MyTransparentMaterialEnum.ContainerBorderSelected, color,
                matrix.Translation, matrix.Left, matrix.Up, radius);
        }
Exemple #15
0
        private void DrawVolumetricGlare(float distance, Vector3D position)
        {
            var intensity = GetIntensity();

            float alpha = m_occlusionRatio * intensity;

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            const int minGlareRadius = 5;
            const int maxGlareRadius = 150;
            float     radius         = MathHelper.Clamp(m_parent.Range * distance / 100.0f, minGlareRadius, maxGlareRadius);

            float drawingRadius = radius;

            Debug.Assert(MyRender.CurrentRenderSetup.LodTransitionBackgroundStart != null, "lod transition is not set in render setup");
            var startFadeout = MyRender.CurrentRenderSetup.LodTransitionBackgroundStart.Value;

            Debug.Assert(MyRender.CurrentRenderSetup.LodTransitionBackgroundEnd != null, "lod transition is not set in render setup");
            var endFadeout = MyRender.CurrentRenderSetup.LodTransitionBackgroundEnd.Value;

            if (distance > startFadeout)
            {
                var fade = (distance - startFadeout) / (endFadeout - startFadeout);
                alpha *= (1 - fade);
            }

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            var color = m_parent.Color;

            color.A = 0;

            var material = (Type == MyGlareTypeEnum.Distant && distance > MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE) ? "LightGlareDistant" : "LightGlare";

            //var material = MyTransparentMaterials.GetMaterial("LightGlare");

            MyTransparentGeometry.AddBillboardOriented(
                material, color * alpha, position,
                MyRenderCamera.LeftVector, MyRenderCamera.UpVector, drawingRadius);
        }
        private void DrawCrossHair()
        {
            if (!MyHud.Visible)
            {
                return;
            }

            // Recompute crosshair size for zoom mode
            float crosshairSize = 1150;

            if (MyCamera.Zoom.GetZoomLevel() < 1)
            {
                crosshairSize = crosshairSize / (float)(Math.Tan(MyCamera.FieldOfView / 2) / Math.Tan(MyCamera.Zoom.GetFOV() / 2));
            }

            MyTransparentGeometry.AddBillboardOriented(MyTransparentMaterialEnum.Crosshair, Vector4.One, WorldMatrix.Translation + WorldMatrix.Forward * 25000,
                                                       WorldMatrix.Up, WorldMatrix.Right, crosshairSize, 1);
        }
        private void DrawVolumetricGlare(float distance, Vector3D position)
        {
            var intensity = GetIntensity();

            float alpha = m_occlusionRatio * intensity;

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            const int minGlareRadius = 5;
            const int maxGlareRadius = 150;
            float     radius         = MathHelper.Clamp(m_parent.Range * distance / 100.0f, minGlareRadius, maxGlareRadius);

            float drawingRadius = radius;

            var startFadeout = MyRenderCamera.NEAR_PLANE_FOR_BACKGROUND;

            var endFadeout = MyRenderCamera.FAR_PLANE_FOR_BACKGROUND;

            if (distance > startFadeout)
            {
                var fade = (distance - startFadeout) / (endFadeout - startFadeout);
                alpha *= (1 - fade);
            }

            if (alpha < MyMathConstants.EPSILON)
            {
                return;
            }

            var color = m_parent.Color;
            //color.A = 0;

            var material = (Type == MyGlareTypeEnum.Distant && distance > MyRenderConstants.MAX_GPU_OCCLUSION_QUERY_DISTANCE) ? "LightGlareDistant" : "LightGlare";

            //var material = MyTransparentMaterials.GetMaterial("LightGlare");

            MyTransparentGeometry.AddBillboardOriented(
                material, color * alpha, position,
                MyRenderCamera.LeftVector, MyRenderCamera.UpVector, drawingRadius);
        }
Exemple #18
0
        public bool Draw()
        {
            if (!Update())
            {
                return(false);
            }

            //draw the texture oriented to the shipyard grid
            if (_scanningZ)
            {
                MyTransparentGeometry.AddBillboardOriented(TextureId, _color, _line.Origin, _line.ZLeft, _line.ZUp, _line.ZWidth, _line.ZLength);
            }
            else
            {
                MyTransparentGeometry.AddBillboardOriented(TextureId, _color, _line.Origin, _line.XLeft, _line.XUp, _line.XWidth, _line.XLength);
            }

            return(true);
        }
Exemple #19
0
        private void updateCamera()
        {
            Vector3D startPos = MyAPIGateway.Session.Camera.WorldMatrix.Translation;
            Vector3  dirA     = targetPos - startPos;
            float    distance = dirA.Length();

            dirA.Normalize();
            //MyLog.Default.WriteLine("Data: " + (targetPos - startPos));
            //drawAt = targetPos;

            float scale;
            float dis;

            if (distance < 150)
            {
                scale = 2.5f;
                dis   = 50f;
            }
            else
            {
                scale = 7.5f;
                dis   = 150f;
            }

            Vector3D drawAt = startPos + dirA * dis;

            var Material = MyStringId.GetOrCompute("Crosshair_Center");

            try {
                if (hasCamTarget)
                {
                    MyTransparentGeometry.AddBillboardOriented(Material, Color.Red.ToVector4(), drawAt, MyAPIGateway.Session.Camera.WorldMatrix.Left, MyAPIGateway.Session.Camera.WorldMatrix.Up, scale, BlendTypeEnum.SDR);
                }
                else
                {
                    MyTransparentGeometry.AddBillboardOriented(Material, Color.White.ToVector4(), drawAt, MyAPIGateway.Session.Camera.WorldMatrix.Left, MyAPIGateway.Session.Camera.WorldMatrix.Up, scale, BlendTypeEnum.SDR);
                }
            } catch (NullReferenceException ex) {
                //MyLog.Default.Error("Error while drawing billboard: " + ex);
            }
            hasCamTarget = false;
        }
Exemple #20
0
        public static void ProcessAvatarDisplay()
        {
            if (SoundEmitter == null)
            {
                return;
            }

            if (!SoundEmitter.IsPlaying || string.IsNullOrWhiteSpace(CurrentAvatar))
            {
                SoundsPlaying = false;
                return;
            }


            var camera    = MyAPIGateway.Session.Camera;
            var camCenter = camera.Position + camera.ViewMatrix.Forward;
            var screenPos = camera.WorldToScreen(ref camCenter);

            MyTransparentGeometry.AddBillboardOriented(MyStringId.GetOrCompute("Avatar-Glitchy-Berserk"), Color.White, screenPos, camera.ViewMatrix.Left, camera.ViewMatrix.Up, (float)1 * 0.075f, 4);
        }
Exemple #21
0
            protected override void Draw()
            {
                if (Visible)
                {
                    MatrixD    cameraMatrix;
                    Quaternion rotquad;
                    Vector3D   boardPos;
                    Vector2D   boardOrigin, boardSize;

                    ScaledSize = Instance.GetScaledSize(Size, Scale);
                    ScaledPos  = Instance.GetScaledPos(Origin + Offset);

                    boardSize = ScaledSize * Instance.fovScale * 16d;

                    boardOrigin    = ScaledPos;
                    boardOrigin.X *= Instance.fovScale * Instance.aspectRatio;
                    boardOrigin.Y *= Instance.fovScale;

                    cameraMatrix = MyAPIGateway.Session.Camera.WorldMatrix;
                    boardPos     = Vector3D.Transform(new Vector3D(boardOrigin.X, boardOrigin.Y, -0.1), cameraMatrix);

                    rotquad      = Quaternion.CreateFromAxisAngle(cameraMatrix.Forward, 0f);
                    cameraMatrix = MatrixD.Transform(cameraMatrix, rotquad);

                    MyTransparentGeometry.AddBillboardOriented
                    (
                        material,
                        color,
                        boardPos,
                        cameraMatrix.Left,
                        cameraMatrix.Up,
                        (float)boardSize.X,
                        (float)boardSize.Y,
                        Vector2.Zero,
                        BlendTypeEnum.LDR
                    );
                }
            }
Exemple #22
0
        private void DrawDroneNotice()
        {
            var      s = _session;
            Vector3D offset;
            Vector2  localOffset;

            float      scale;
            float      screenScale;
            float      fontScale;
            MyStringId textureName;

            var hudOpacity = MathHelper.Clamp(_session.UIHudOpacity, 0.25f, 1f);
            var color      = new Vector4(1, 1, 1, hudOpacity);

            _alertHudInfo.GetTextureInfo(s, out textureName, out scale, out screenScale, out fontScale, out offset, out localOffset);

            MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, screenScale, BlendTypeEnum.PostPP);
            string  textLine1;
            string  textLine2;
            Vector2 textOffset1;
            Vector2 textOffset2;
            Vector4 text1Color;
            Vector4 text2Color;

            if (s.Tick20 && DroneText(localOffset, scale, out textLine1, out textLine2, out textOffset1, out textOffset2, out text1Color, out text2Color))
            {
                var fontSize    = (float)Math.Round(24 * fontScale, 1);
                var fontHeight  = 0.75f;
                var fontAge     = 18;
                var fontJustify = Hud.Justify.None;
                var fontType    = Hud.FontType.Shadow;
                var elementId   = 123456;

                s.HudUi.AddText(text: textLine1, x: textOffset1.X, y: textOffset1.Y, elementId: elementId, ttl: fontAge, color: text1Color, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
                s.HudUi.AddText(text: textLine2, x: textOffset2.X, y: textOffset2.Y, elementId: elementId + 1, ttl: fontAge, color: text2Color, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
            }
        }
        private void DrawTarget()
        {
            var s     = _session;
            var focus = s.TrackingAi.Construct.Data.Repo.FocusData;

            for (int i = 0; i < s.TrackingAi.TargetState.Length; i++)
            {
                if (focus.Target[i] <= 0)
                {
                    continue;
                }
                var lockMode = focus.Locked[i];

                var targetState  = s.TrackingAi.TargetState[i];
                var displayCount = 0;
                foreach (var icon in _targetIcons.Keys)
                {
                    int iconLevel;
                    if (!IconStatus(icon, targetState, out iconLevel))
                    {
                        continue;
                    }

                    Vector3D   offset;
                    Vector2    localOffset;
                    float      scale;
                    MyStringId textureName;
                    var        iconInfo = _targetIcons[icon][iconLevel];
                    iconInfo.GetTextureInfo(i, displayCount, s, out textureName, out scale, out offset, out localOffset);

                    var color = Color.White;
                    switch (lockMode)
                    {
                    case FocusData.LockModes.None:
                        color = Color.White;
                        break;

                    case FocusData.LockModes.Locked:
                        color = s.Count < 60 ? Color.White : new Color(255, 255, 255, 64);
                        break;

                    case FocusData.LockModes.ExclusiveLock:
                        color = s.SCount < 30 ? Color.White : new Color(255, 255, 255, 64);
                        break;
                    }

                    var skipSize = !s.Settings.ClientConfig.ShowHudTargetSizes && icon.Equals("size");

                    if (!skipSize)
                    {
                        MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                    }

                    if (focus.ActiveId == i && displayCount == 0)
                    {
                        if (!skipSize)
                        {
                            var focusTexture = focus.ActiveId == 0 ? _focus : _focusSecondary;
                            MyTransparentGeometry.AddBillboardOriented(focusTexture, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                        }
                        else
                        {
                            var     focusColor = focus.ActiveId == 0 ? Color.Red : Color.LightBlue;
                            MyQuadD quad;
                            var     up   = (Vector3)s.CameraMatrix.Up;
                            var     left = (Vector3)s.CameraMatrix.Left;

                            MyUtils.GetBillboardQuadOriented(out quad, ref offset, 0.002f, 0.002f, ref left, ref up);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, FocusTextureMap.P0, FocusTextureMap.P1, FocusTextureMap.P3, FocusTextureMap.Material, 0, offset, focusColor, BlendTypeEnum.PostPP);
                            MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, FocusTextureMap.P0, FocusTextureMap.P2, FocusTextureMap.P3, FocusTextureMap.Material, 0, offset, focusColor, BlendTypeEnum.PostPP);
                        }
                    }

                    displayCount++;
                }

                MyEntity target;
                if (i == focus.ActiveId && MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target))
                {
                    var targetSphere = target.PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos    = s.Camera.WorldToScreen(ref targetCenter);
                    var screenScale  = 0.1 * s.ScaleFov;

                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y  = -1;
                    }

                    var dotpos = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));

                    dotpos.X *= (float)(screenScale * _session.AspectRatio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);

                    if (s.Tick20)
                    {
                        s.HudUi.AddText(text: $"RANGE: {targetState.RealDistance:#.0}  -  SIZE: {targetState.SizeExtended}", x: i == 0 ? 0f : -0.345f, y: 0.83f, element: Hud.ElementNames.Element0, ttl: 18, color: i == 0 ? Color.OrangeRed : Color.MediumOrchid, justify: Hud.Justify.Center, fontType: Hud.FontType.Shadow, fontSize: 5, heightScale: 0.75f);
                    }
                }
            }
        }
Exemple #24
0
        private void DrawTarget()
        {
            var s           = _session;
            var focus       = s.TrackingAi.Construct.Data.Repo.FocusData;
            var detailedHud = !_session.Settings.ClientConfig.MinimalHud;

            for (int i = 0; i < s.TrackingAi.TargetState.Length; i++)
            {
                if (focus.Target[i] <= 0)
                {
                    continue;
                }
                var lockMode = focus.Locked[i];

                var targetState = s.TrackingAi.TargetState[i];
                var isActive    = i == focus.ActiveId;
                var primary     = i == 0;
                var shielded    = detailedHud && targetState.ShieldHealth >= 0;

                Dictionary <string, HudInfo> collection;
                if (detailedHud)
                {
                    collection = primary ? _primaryTargetHuds : _secondaryTargetHuds;
                }
                else
                {
                    collection = primary ? _primaryMinimalHuds : _secondaryMinimalHuds;
                }

                foreach (var hud in collection.Keys)
                {
                    if (isActive && (hud == InactiveShield || hud == InactiveNoShield))
                    {
                        continue;
                    }

                    if (!isActive && (hud == ActiveShield || hud == ActiveNoShield))
                    {
                        continue;
                    }

                    if (shielded && (hud == ActiveNoShield || hud == InactiveNoShield))
                    {
                        continue;
                    }
                    if (!shielded && (hud == ActiveShield || hud == InactiveShield))
                    {
                        continue;
                    }

                    Vector3D offset;
                    Vector2  localOffset;

                    float      scale;
                    float      screenScale;
                    float      fontScale;
                    MyStringId textureName;
                    var        hudInfo = collection[hud];
                    hudInfo.GetTextureInfo(s, out textureName, out scale, out screenScale, out fontScale, out offset, out localOffset);

                    var color = Color.White;
                    switch (lockMode)
                    {
                    case FocusData.LockModes.None:
                        color = Color.White;
                        break;

                    case FocusData.LockModes.Locked:
                        color = s.Count < 60 ? Color.White : new Color(255, 255, 255, 64);
                        break;

                    case FocusData.LockModes.ExclusiveLock:
                        color = s.SCount < 30 ? Color.White : new Color(255, 255, 255, 64);
                        break;
                    }

                    var hudOpacity = MathHelper.Clamp(_session.UIHudOpacity, 0.25f, 1f);
                    color = new Vector4(1, 1, 1, hudOpacity);
                    MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, screenScale, BlendTypeEnum.PostPP);
                    var quickUpdate = _session.UiInput.FirstPersonView && _session.HudUi.NeedsUpdate && _session.ControlledEntity is IMyGunBaseUser;
                    if (s.Tick20 || quickUpdate)
                    {
                        for (int j = 0; j < 11; j++)
                        {
                            string  text;
                            Vector2 textOffset;
                            if (TargetTextStatus(j, targetState, scale, localOffset, shielded, detailedHud, out text, out textOffset))
                            {
                                var textColor   = Color.White;
                                var fontSize    = (float)Math.Round(21 * fontScale, 1);
                                var fontHeight  = 0.75f;
                                var fontAge     = !quickUpdate ? 18 : 0;
                                var fontJustify = Hud.Justify.None;
                                var fontType    = Hud.FontType.Shadow;
                                var elementId   = MathFuncs.UniqueId(i, j);

                                s.HudUi.AddText(text: text, x: textOffset.X, y: textOffset.Y, elementId: elementId, ttl: fontAge, color: textColor, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
                            }
                        }
                    }
                }

                MyEntity target;
                if (isActive && MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target))
                {
                    var targetSphere = target.PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos    = s.Camera.WorldToScreen(ref targetCenter);

                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y  = -1;
                    }

                    var dotpos      = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));
                    var screenScale = 0.1 * s.ScaleFov;
                    dotpos.X *= (float)(screenScale * _session.AspectRatio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);
                }
            }
        }
Exemple #25
0
        void DrawSkinSelector(MatrixD camMatrix, Vector3D worldPos, float scaleFOV, float bgAlpha)
        {
            PlayerInfo      localInfo  = Main.Palette.LocalInfo;
            List <SkinInfo> shownSkins = Main.Palette.SkinsForHUD;

            if (localInfo == null || shownSkins == null || !localInfo.ApplySkin || !Main.Palette.HasAnySkin)
            {
                return;
            }

            float        iconSize               = 0.0024f * scaleFOV;
            float        selectedIconSize       = 0.003f * scaleFOV;
            MyStringHash selectedSkinId         = localInfo.SelectedSkin;
            double       iconSpacingAdd         = (selectedIconSize - iconSize); // 0.0012 * scaleFOV;
            double       iconSpacingWidth       = (iconSize * 2) + iconSpacingAdd;
            float        iconBgSpacingAddWidth  = 0.0004f * scaleFOV;
            float        iconBgSpacingAddHeight = 0.0006f * scaleFOV;
            //float iconBgSpacingAddWidth = 0.0006f * scaleFOV;
            //float iconBgSpacingAddHeight = 0.0008f * scaleFOV;

            Vector3D pos = worldPos;

            if (localInfo.ApplyColor)
            {
                pos += camMatrix.Up * (0.0075f * scaleFOV);
            }

            DrawSkinNameText(localInfo.SelectedSkinInfo);

            const int    MAX_VIEW_SKINS        = 7; // must be an odd number.
            const int    MAX_VIEW_SKINS_HALF   = ((MAX_VIEW_SKINS - 1) / 2);
            const double MAX_VIEW_SKINS_HALF_D = (MAX_VIEW_SKINS / 2d);
            //const double MAX_VIEW_SKINS_HALF_D_BG = ((MAX_VIEW_SKINS - 4) / 2d);

            int showSkinsCount = shownSkins.Count;

            if (showSkinsCount >= MAX_VIEW_SKINS) // scrolling skin bar
            {
                //var bgPos = pos + camMatrix.Right * ((iconSpacingWidth * 0.5) - (iconSpacingWidth * 0.5));
                //MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_BACKGROUND, PALETTE_COLOR_BG * bgAlpha, bgPos, camMatrix.Left, camMatrix.Up, (float)(iconSpacingWidth * MAX_VIEW_SKINS_HALF_D_BG) + iconBgSpacingAddWidth, iconSize + iconBgSpacingAddHeight, Vector2.Zero, UI_BG_BLENDTYPE);

                pos += camMatrix.Left * ((iconSpacingWidth * MAX_VIEW_SKINS_HALF_D) - (iconSpacingWidth * 0.5));

                int skinIndex = 0;

                for (int i = 0; i < showSkinsCount; ++i)
                {
                    SkinInfo skin = shownSkins[i];
                    if (skin.SubtypeId == selectedSkinId)
                    {
                        skinIndex = i;
                        break;
                    }
                }

                const float MIN_ALPHA         = 0.5f; // alpha of the skin icon on the edge of the scrollable bar
                float       alphaSubtractStep = ((1f - MIN_ALPHA) / MAX_VIEW_SKINS_HALF);

                int index = skinIndex - MAX_VIEW_SKINS_HALF;

                for (int a = -MAX_VIEW_SKINS_HALF; a <= MAX_VIEW_SKINS_HALF; ++a)
                {
                    if (index < 0)
                    {
                        index = showSkinsCount + index;
                    }
                    if (index >= showSkinsCount)
                    {
                        index %= showSkinsCount;
                    }

                    SkinInfo skin = shownSkins[index];

                    float alpha = 1f - (Math.Abs(a) * alphaSubtractStep);

                    if (selectedSkinId == skin.SubtypeId)
                    {
                        MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_COLOR, Color.White, pos, camMatrix.Left, camMatrix.Up, selectedIconSize, selectedIconSize, Vector2.Zero, GUI_FG_BLENDTYPE);
                    }

                    MyTransparentGeometry.AddBillboardOriented(skin.Icon, Color.White * alpha, pos, camMatrix.Left, camMatrix.Up, iconSize, iconSize, Vector2.Zero, GUI_FG_BLENDTYPE);

                    pos += camMatrix.Right * iconSpacingWidth;

                    index++;
                }
            }
            else // static skin bar with moving selection
            {
                double halfOwnedSkins = showSkinsCount * 0.5;

                //MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_BACKGROUND, PALETTE_COLOR_BG * bgAlpha, pos, camMatrix.Left, camMatrix.Up, (float)(iconSpacingWidth * halfOwnedSkins) + iconBgSpacingAddWidth, iconSize + iconBgSpacingAddHeight, Vector2.Zero, UI_BG_BLENDTYPE);

                pos += camMatrix.Left * ((iconSpacingWidth * halfOwnedSkins) - (iconSpacingWidth * 0.5));

                foreach (SkinInfo skin in shownSkins)
                {
                    if (selectedSkinId == skin.SubtypeId)
                    {
                        MyTransparentGeometry.AddBillboardOriented(MATERIAL_PALETTE_COLOR, Color.White, pos, camMatrix.Left, camMatrix.Up, selectedIconSize, selectedIconSize, Vector2.Zero, GUI_FG_BLENDTYPE);
                    }

                    MyTransparentGeometry.AddBillboardOriented(skin.Icon, Color.White, pos, camMatrix.Left, camMatrix.Up, iconSize, iconSize, Vector2.Zero, GUI_FG_BLENDTYPE);

                    pos += camMatrix.Right * iconSpacingWidth;
                }
            }
        }
        private void DrawTargetAlternate()
        {
            var s     = _session;
            var focus = s.TrackingAi.Construct.Data.Repo.FocusData;

            for (int i = 0; i < s.TrackingAi.TargetState.Length; i++)
            {
                if (focus.Target[i] <= 0)
                {
                    continue;
                }
                var lockMode = focus.Locked[i];

                var targetState  = s.TrackingAi.TargetState[i];
                var displayCount = 0;
                foreach (var hud in _targetHuds.Keys)
                {
                    var shielded = targetState.ShieldHealth >= 0;
                    if (shielded && hud != ShieldHudStr || !shielded && hud == ShieldHudStr)
                    {
                        continue;
                    }

                    Vector3D offset;
                    Vector2  localOffset;

                    float      scale;
                    MyStringId textureName;
                    var        hudInfo = _targetHuds[hud][0];
                    hudInfo.GetTextureInfo(i, displayCount, s, out textureName, out scale, out offset, out localOffset);

                    var color = Color.White;
                    switch (lockMode)
                    {
                    case FocusData.LockModes.None:
                        color = Color.White;
                        break;

                    case FocusData.LockModes.Locked:
                        color = s.Count < 60 ? Color.White : new Color(255, 255, 255, 64);
                        break;

                    case FocusData.LockModes.ExclusiveLock:
                        color = s.SCount < 30 ? Color.White : new Color(255, 255, 255, 64);
                        break;
                    }

                    MyTransparentGeometry.AddBillboardOriented(textureName, color, offset, s.CameraMatrix.Left, s.CameraMatrix.Up, scale, BlendTypeEnum.PostPP);
                    if (s.Tick20)
                    {
                        var slots = shielded ? 9 : 6;
                        for (int j = 0; j < slots; j++)
                        {
                            string  text;
                            Vector2 textOffset;
                            if (TextStatus(j, targetState, localOffset, out text, out textOffset))
                            {
                                var textColor   = i == 0 ? Color.OrangeRed : Color.MediumOrchid;
                                var fontSize    = 5;
                                var fontHeight  = 0.75f;
                                var fontAge     = 18;
                                var fontJustify = Hud.Justify.Center;
                                var fontType    = Hud.FontType.Shadow;
                                var elementKey  = (Hud.ElementNames)j;

                                s.HudUi.AddText(text: text, x: textOffset.X, y: textOffset.Y, element: elementKey, ttl: fontAge, color: textColor, justify: fontJustify, fontType: fontType, fontSize: fontSize, heightScale: fontHeight);
                            }
                        }
                    }
                    displayCount++;
                }

                MyEntity target;
                if (i == focus.ActiveId && MyEntities.TryGetEntityById(focus.Target[focus.ActiveId], out target))
                {
                    var targetSphere = target.PositionComp.WorldVolume;
                    var targetCenter = targetSphere.Center;
                    var screenPos    = s.Camera.WorldToScreen(ref targetCenter);
                    var screenScale  = 0.1 * s.ScaleFov;

                    if (Vector3D.Transform(targetCenter, s.Camera.ViewMatrix).Z > 0)
                    {
                        screenPos.X *= -1;
                        screenPos.Y  = -1;
                    }

                    var dotpos = new Vector2D(MathHelper.Clamp(screenPos.X, -0.98, 0.98), MathHelper.Clamp(screenPos.Y, -0.98, 0.98));

                    dotpos.X *= (float)(screenScale * _session.AspectRatio);
                    dotpos.Y *= (float)screenScale;
                    screenPos = Vector3D.Transform(new Vector3D(dotpos.X, dotpos.Y, -0.1), s.CameraMatrix);
                    MyTransparentGeometry.AddBillboardOriented(_active, Color.White, screenPos, s.CameraMatrix.Left, s.CameraMatrix.Up, (float)screenScale * 0.075f, BlendTypeEnum.PostPP);
                }
            }

            //MyTransparentGeometry.AddBillboardOriented(_hudWithShield, Color.White, offset, _session.CameraMatrix.Left, _session.CameraMatrix.Up, 0.002, BlendTypeEnum.PostPP);
        }
        public override void Draw()
        {
            try
            {
                int count = drawInfo.Count;
                if (count == 0)
                {
                    return;
                }

                var camMatrix = MyAPIGateway.Session.Camera.WorldMatrix;

                for (int i = count - 1; i >= 0; i--)
                {
                    var data     = drawInfo[i];
                    var ent      = data.Entity;
                    var settings = data.Settings;

                    if (ent.MarkedForClose)
                    {
                        drawInfo.RemoveAtFast(i);
                        continue;
                    }

                    var gunMatrix = ent.WorldMatrix;

                    var fwDot = gunMatrix.Forward.Dot(camMatrix.Forward);
                    if (fwDot <= 0)
                    {
                        continue; // looking more than 90deg away from the direction of the gun.
                    }
                    if (Vector3D.DistanceSquared(camMatrix.Translation, gunMatrix.Translation) > MAX_VIEW_DIST_SQ)
                    {
                        continue;                           // too far away to be seen
                    }
                    var dummyMatrix = settings.DummyMatrix; // scaled exactly like the dummy from the model

                    var reticleProjectedPosition = Vector3D.Transform(dummyMatrix.Translation, gunMatrix) + gunMatrix.Forward * PROJECTED_DISTANCE;

                    //if(IsLocalPlayerAimingThisGun(data.Entity))
                    //{
                    //    var centerScreenPos = camMatrix.Translation + camMatrix.Forward * Vector3D.Distance(camMatrix.Translation, reticlePosition);
                    //    MyTransparentGeometry.AddBillboardOriented(data.Settings.ReticleMaterial, data.Settings.ReticleColor, centerScreenPos, gunMatrix.Left, gunMatrix.Up, data.Settings.ReticleSize, blendType: RETICLE_BLEND_TYPE);
                    //    continue;
                    //}

                    var sightPosition = Vector3D.Transform(dummyMatrix.Translation, gunMatrix);

                    var fwOffsetDot = gunMatrix.Forward.Dot(sightPosition - camMatrix.Translation);
                    if (fwOffsetDot < 0)
                    {
                        continue; // camera is ahead of sight, don't draw reticle
                    }
                    if (settings.Type == SightType.Rectangle)
                    {
                        var    camToReticleDir = Vector3D.Normalize(reticleProjectedPosition - camMatrix.Translation);
                        double angleH          = Math.Acos(MathHelper.Clamp(Vector3D.Dot(gunMatrix.Left, camToReticleDir), -1, 1)) - (Math.PI / 2); // subtracting 90deg
                        double angleV          = Math.Acos(MathHelper.Clamp(Vector3D.Dot(gunMatrix.Up, camToReticleDir), -1, 1)) - (Math.PI / 2);

                        // simplifies math later on
                        angleH = Math.Abs(angleH);
                        angleV = Math.Abs(angleV);

                        if (angleH < settings.MaxAngleH && angleV < settings.MaxAngleV)
                        {
                            var alphaH = GetAlphaForAngle(settings.FadeStartRatio, angleH, settings.MaxAngleH);
                            var alphaV = GetAlphaForAngle(settings.FadeStartRatio, angleV, settings.MaxAngleV);

                            var camToSightDistance = Vector3D.Distance(sightPosition, camMatrix.Translation) + RETICLE_FRONT_OFFSET;
                            var reticlePosition    = camMatrix.Translation + (camToReticleDir * camToSightDistance);

                            MyTransparentGeometry.AddBillboardOriented(settings.ReticleMaterial, settings.ReticleColor * (alphaH * alphaV), reticlePosition, gunMatrix.Left, gunMatrix.Up, settings.ReticleSize, blendType: RETICLE_BLEND_TYPE);
                        }
                    }
                    else if (settings.Type == SightType.Circle)
                    {
                        var    camToReticleDir = Vector3D.Normalize(reticleProjectedPosition - camMatrix.Translation);
                        double angle           = Math.Acos(MathHelper.Clamp(Vector3D.Dot(gunMatrix.Forward, camToReticleDir), -1, 1));

                        if (angle < settings.MaxAngleH)
                        {
                            var alpha = GetAlphaForAngle(settings.FadeStartRatio, angle, settings.MaxAngleH);

                            var camToSightDistance = Vector3D.Distance(sightPosition, camMatrix.Translation) + RETICLE_FRONT_OFFSET;
                            var reticlePosition    = camMatrix.Translation + (camToReticleDir * camToSightDistance);

                            MyTransparentGeometry.AddBillboardOriented(settings.ReticleMaterial, settings.ReticleColor * alpha, reticlePosition, gunMatrix.Left, gunMatrix.Up, settings.ReticleSize, blendType: RETICLE_BLEND_TYPE);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemple #28
0
        internal void DrawTextures()
        {
            _aspectratio       = _session.Camera.ViewportSize.Y / _session.Camera.ViewportSize.X;
            _cameraWorldMatrix = _session.Camera.WorldMatrix;

            #region WeaponHudDisplay
            //inlined becuase there can be many and too many method calls
            if (WeaponsToDisplay.Count > 0)
            {
                CurrWeaponDisplayPos = new Vector2((_session.Camera.ViewportSize.X * .25f) * _metersInPixel, (_session.Camera.ViewportSize.Y * .125f) * _metersInPixel);

                var ticksSinceUpdate = _session.Tick - _lastHudUpdateTick;

                var reset = false;
                if (ticksSinceUpdate >= _minUpdateTicks)
                {
                    _weapontoDraw      = SortDisplayedWeapons(WeaponsToDisplay);
                    _lastHudUpdateTick = _session.Tick;
                }
                else if (ticksSinceUpdate + 1 >= _minUpdateTicks)
                {
                    reset = true;
                }

                #region Background draw
                TextureDrawData backgroundTextureTop;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureTop))
                {
                    backgroundTextureTop = new TextureDrawData();
                }

                TextureDrawData backgroundTextureCenter;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureCenter))
                {
                    backgroundTextureCenter = new TextureDrawData();
                }

                TextureDrawData backgroundTextureBottom;
                if (!_textureDrawPool.TryDequeue(out backgroundTextureBottom))
                {
                    backgroundTextureBottom = new TextureDrawData();
                }


                var bgWidth     = (_currentLargestName * _metersInPixel) + _textOffset;
                var bgStartPosX = CurrWeaponDisplayPos.X - (bgWidth + _padding * 1.5f);

                var bgBorderHeight = bgWidth * .166f;
                var bgCenterHeight = _weapontoDraw.Count > 3 ? ((_weapontoDraw.Count - 2) * _infoPanelOffset) : _infoPanelOffset * 2;

                var bgStartPoxY = CurrWeaponDisplayPos.Y - (bgCenterHeight + _padding);

                backgroundTextureCenter.Material = _infoBackground[1].Material;
                backgroundTextureCenter.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureCenter.Position = new Vector3D(bgStartPosX, bgStartPoxY, -.1f);
                backgroundTextureCenter.Width    = bgWidth;
                backgroundTextureCenter.Height   = bgCenterHeight;
                backgroundTextureCenter.P0       = _infoBackground[1].P0;
                backgroundTextureCenter.P1       = _infoBackground[1].P1;
                backgroundTextureCenter.P2       = _infoBackground[1].P2;
                backgroundTextureCenter.P3       = _infoBackground[1].P3;

                _textureAddList.Add(backgroundTextureCenter);

                backgroundTextureTop.Material = _infoBackground[0].Material;
                backgroundTextureTop.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureTop.Position = new Vector3D(bgStartPosX, bgStartPoxY + bgBorderHeight + bgCenterHeight, -.1f);
                backgroundTextureTop.Width    = bgWidth;
                backgroundTextureTop.Height   = bgBorderHeight;
                backgroundTextureTop.P0       = _infoBackground[0].P0;
                backgroundTextureTop.P1       = _infoBackground[0].P1;
                backgroundTextureTop.P2       = _infoBackground[0].P2;
                backgroundTextureTop.P3       = _infoBackground[0].P3;

                _textureAddList.Add(backgroundTextureTop);

                backgroundTextureBottom.Material = _infoBackground[2].Material;
                backgroundTextureBottom.Color    = _bgColor * (_session.Session.Config.HUDBkOpacity * 1.8f);
                backgroundTextureBottom.Position = new Vector3D(bgStartPosX, bgStartPoxY - (bgBorderHeight + bgCenterHeight), -.1f);
                backgroundTextureBottom.Width    = bgWidth;
                backgroundTextureBottom.Height   = bgBorderHeight;
                backgroundTextureBottom.P0       = _infoBackground[2].P0;
                backgroundTextureBottom.P1       = _infoBackground[2].P1;
                backgroundTextureBottom.P2       = _infoBackground[2].P2;
                backgroundTextureBottom.P3       = _infoBackground[2].P3;

                _textureAddList.Add(backgroundTextureBottom);
                #endregion

                if (reset)
                {
                    _currentLargestName = 0;
                }

                for (int i = 0; i < _weapontoDraw.Count; i++)
                {
                    TextDrawRequest textInfo;
                    TextureDrawData reloadTexture;
                    TextureDrawData heatTexture;

                    var weapon     = _weapontoDraw[i].HighestValueWeapon;
                    var name       = weapon.System.WeaponName + ": ";
                    var textOffset = name.Length * _WeaponHudFontHeight;
                    textOffset += _textOffset;

                    if (weapon.State.Sync.Reloading && weapon.State.Sync.Reloading && weapon.Comp.Session.Tick - weapon.LastLoadedTick > 30)
                    {
                        if (!_textureDrawPool.TryDequeue(out reloadTexture))
                        {
                            reloadTexture = new TextureDrawData();
                        }

                        reloadTexture.Material = _reloadingTexture.Material;
                        reloadTexture.Color    = Color.Red * _session.UiOpacity;
                        reloadTexture.Position = new Vector3D(CurrWeaponDisplayPos.X - _reloadWidthOffset, CurrWeaponDisplayPos.Y + _reloadHeightOffset, -.1f);
                        reloadTexture.Width    = _reloadWidth;
                        reloadTexture.Height   = _reloadHeight;
                        reloadTexture.P0       = _reloadingTexture.P0;
                        reloadTexture.P1       = _reloadingTexture.P1;
                        reloadTexture.P2       = _reloadingTexture.P2;
                        reloadTexture.P3       = _reloadingTexture.P3;

                        _textureAddList.Add(reloadTexture);
                    }

                    if (!_textDrawPool.TryDequeue(out textInfo))
                    {
                        textInfo = new TextDrawRequest();
                    }

                    textInfo.Text     = name;
                    textInfo.Color    = Color.White * _session.UiOpacity;
                    textInfo.X        = CurrWeaponDisplayPos.X - textOffset;
                    textInfo.Y        = CurrWeaponDisplayPos.Y;
                    textInfo.FontSize = _WeaponHudFontSize;
                    _textAddList.Add(textInfo);


                    if (weapon.HeatPerc > 0)
                    {
                        if (!_textureDrawPool.TryDequeue(out heatTexture))
                        {
                            heatTexture = new TextureDrawData();
                        }
                        int heatBarIndex;
                        if (weapon.State.Sync.Overheated)
                        {
                            heatBarIndex = 10;
                        }
                        else
                        {
                            heatBarIndex = (int)(weapon.HeatPerc * 10);
                        }

                        heatTexture.Material = _heatBarTexture[heatBarIndex].Material;
                        heatTexture.Color    = Color.Transparent;
                        heatTexture.Position = new Vector3D(CurrWeaponDisplayPos.X - (_heatWidth * 1.5f), CurrWeaponDisplayPos.Y - _heatHeightOffset, -.1f);
                        heatTexture.Width    = _heatWidth;
                        heatTexture.Height   = _heatHeight;
                        heatTexture.P0       = _heatBarTexture[heatBarIndex].P0;
                        heatTexture.P1       = _heatBarTexture[heatBarIndex].P1;
                        heatTexture.P2       = _heatBarTexture[heatBarIndex].P2;
                        heatTexture.P3       = _heatBarTexture[heatBarIndex].P3;

                        _textureAddList.Add(heatTexture);
                    }

                    if (_weapontoDraw[i].WeaponStack > 1)
                    {
                        if (!_textDrawPool.TryDequeue(out textInfo))
                        {
                            textInfo = new TextDrawRequest();
                        }

                        textInfo.Text     = $"(x{_weapontoDraw[i].WeaponStack})";
                        textInfo.Color    = Color.LightSteelBlue * _session.UiOpacity;
                        textInfo.X        = CurrWeaponDisplayPos.X - (textOffset + ((textInfo.Text.Length * _metersInPixel) * 1.1f) + _padding);
                        textInfo.Y        = CurrWeaponDisplayPos.Y;
                        textInfo.FontSize = _WeaponHudFontSize * .75f;
                        _textAddList.Add(textInfo);
                    }

                    CurrWeaponDisplayPos.Y -= _infoPanelOffset + (_padding * .5f);

                    if (reset)
                    {
                        _weaponStackedInfoPool.Enqueue(_weapontoDraw[i]);
                    }
                }

                if (reset)
                {
                    _weapontoDraw.Clear();
                    _weaponInfoListPool.Enqueue(_weapontoDraw);
                }
            }
            #endregion

            #region UV Offset based draws
            for (int i = 0; i < _textAddList.Count; i++)
            {
                var textAdd  = _textAddList[i];
                var position = new Vector3D(textAdd.X, textAdd.Y, -.1);
                position = Vector3D.Transform(position, _cameraWorldMatrix);

                var height  = textAdd.FontSize * _metersInPixel;
                var width   = height * _aspectratio;
                var textPos = position;

                for (int j = 0; j < textAdd.Text.Length; j++)
                {
                    var             cm = _characterMap[textAdd.Text[j]];
                    TextureDrawData tdd;

                    if (!_textureDrawPool.TryDequeue(out tdd))
                    {
                        tdd = new TextureDrawData();
                    }

                    tdd.Material = cm.Material;
                    tdd.Color    = textAdd.Color;
                    tdd.Position = textPos;
                    tdd.Up       = _cameraWorldMatrix.Up;
                    tdd.Left     = _cameraWorldMatrix.Left;
                    tdd.Width    = width;
                    tdd.Height   = height;
                    tdd.P0       = cm.P0;
                    tdd.P1       = cm.P1;
                    tdd.P2       = cm.P2;
                    tdd.P3       = cm.P3;

                    _uvDrawList.Add(tdd);

                    textPos -= (_cameraWorldMatrix.Left * height);
                }

                _textDrawPool.Enqueue(textAdd);
            }

            for (int i = 0; i < _textureAddList.Count; i++)
            {
                var tdd = _textureAddList[i];

                tdd.Position = Vector3D.Transform(tdd.Position, _cameraWorldMatrix);
                tdd.Up       = _cameraWorldMatrix.Up;
                tdd.Left     = _cameraWorldMatrix.Left;
                _uvDrawList.Add(tdd);
            }

            for (int i = 0; i < _uvDrawList.Count; i++)
            {
                var textureToDraw = _uvDrawList[i];

                MyQuadD quad;
                MyUtils.GetBillboardQuadOriented(out quad, ref textureToDraw.Position, textureToDraw.Width, textureToDraw.Height, ref textureToDraw.Left, ref textureToDraw.Up);

                if (textureToDraw.Color != Color.Transparent)
                {
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Color, textureToDraw.Blend);
                }
                else
                {
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point1, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P1, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                    MyTransparentGeometry.AddTriangleBillboard(quad.Point0, quad.Point3, quad.Point2, Vector3.Zero, Vector3.Zero, Vector3.Zero, textureToDraw.P0, textureToDraw.P2, textureToDraw.P3, textureToDraw.Material, 0, textureToDraw.Position, textureToDraw.Blend);
                }

                _textureDrawPool.Enqueue(textureToDraw);
            }
            #endregion

            #region Simple based draws
            for (int i = 0; i < _simpleDrawList.Count; i++)
            {
                var textureToDraw = _simpleDrawList[i];
                var scale         = 0.075 * Math.Tan(_session.Camera.FovWithZoom * textureToDraw.Height);

                textureToDraw.Position = Vector3D.Transform(textureToDraw.Position, _cameraWorldMatrix);
                scale = 1 * scale;

                MyTransparentGeometry.AddBillboardOriented(textureToDraw.Material, textureToDraw.Color, textureToDraw.Position, _cameraWorldMatrix.Left, _cameraWorldMatrix.Up, (float)scale, textureToDraw.Blend);

                _textureDrawPool.Enqueue(textureToDraw);
            }
            #endregion

            WeaponsToDisplay.Clear();
            _textAddList.Clear();
            _textureAddList.Clear();
            _uvDrawList.Clear();
            _simpleDrawList.Clear();
            TexturesToAdd = 0;
        }
        public void CalculateRotationHints(MatrixD drawMatrix, BoundingBoxD worldBox, bool draw, bool fixedAxes = false, bool hideForwardAndUpArrows = false)
        {
            drawMatrix.Translation = Vector3D.Zero;
            MatrixD drawInverse = MatrixD.Invert(drawMatrix);

            drawInverse *= drawMatrix.GetOrientation();
            drawInverse *= MySector.MainCamera.ViewMatrixAtZero;

            MatrixD camWorld = MatrixD.Invert(drawInverse);

            m_viewProjection.ViewAtZero             = MatrixD.CreateLookAt(Vector3D.Zero, camWorld.Forward, camWorld.Up);
            m_viewProjection.ViewAtZero.Translation = new Vector3D(0, 0, -6);
            m_viewProjection.View              = drawInverse;
            m_viewProjection.View.Translation += new Vector3D(0, 0, -10);
            m_viewProjection.CameraPosition    = camWorld.Translation;

            Vector2 screenSize = MyGuiManager.GetScreenSizeFromNormalizedSize(Vector2.One);
            float   previewRatio = 2.5f;
            int     hintsWidth = (int)(screenSize.X / previewRatio), hintsHeight = (int)(screenSize.Y / previewRatio), hintsXOffset = 0, hintsYOffset = 0;

            m_viewProjection.Viewport = new MyViewport(
                (int)MySector.MainCamera.Viewport.Width - hintsWidth - hintsXOffset,
                hintsYOffset,
                hintsWidth,
                hintsHeight);

            m_viewProjection.DepthRead  = false;
            m_viewProjection.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)hintsHeight / hintsWidth, 0.1f, 10);



            worldBox = new BoundingBoxD(-new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large) * 0.5f), new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large)) * 0.5f);


            //m_rotationHintsViewProjection.Projection = MySector.MainCamera.ProjectionMatrix;



            int projectionId = 0;

            VRageRender.MyRenderProxy.AddBillboardViewProjection(projectionId, m_viewProjection);

            //MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix,
            //                ref worldBox, ref Vector4.One, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, null, null, false, 0);
            if (draw)
            {
                var white = Color.White;
                MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix,
                                                      ref worldBox, ref white, MySimpleObjectRasterizer.Solid, 1, 0.04f, "SquareFullColor", null, false, projectionId, 100);
            }

            MyOrientedBoundingBoxD rotateHintsBox = new MyOrientedBoundingBoxD(Vector3D.Transform(worldBox.Center, drawMatrix), worldBox.HalfExtents, Quaternion.CreateFromRotationMatrix(drawMatrix));

            //VRageRender.MyRenderProxy.DebugDrawOBB(rotateHintsBox, Vector3.One, 1, false, false);


            rotateHintsBox.GetCorners(m_cubeVertices, 0);

            //for (int vi = 0; vi < 8; vi++)
            //{
            //    VRageRender.MyRenderProxy.DebugDrawText3D(m_cubeVertices[vi], vi.ToString(), Color.White, 0.7f, false);
            //}

            //for (int vi = 0; vi < 4; vi++)
            //{
            //    VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartXVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndXVertices[vi]]) * 0.5f, vi.ToString(), Color.Red, 0.7f, false);
            //    VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartYVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndYVertices[vi]]) * 0.5f, vi.ToString(), Color.Green, 0.7f, false);
            //    VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartZVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndZVertices[vi]]) * 0.5f, vi.ToString(), Color.Blue, 0.7f, false);
            //}

            int closestXAxis, closestXAxis2;

            GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartXVertices, MyOrientedBoundingBox.EndXVertices, out closestXAxis, out closestXAxis2);
            Vector3D startXVertex  = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis]];
            Vector3D endXVertex    = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis]];
            Vector3D startXVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis2]];
            Vector3D endXVertex2   = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis2]];

            int closestYAxis, closestYAxis2;

            GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartYVertices, MyOrientedBoundingBox.EndYVertices, out closestYAxis, out closestYAxis2);
            Vector3D startYVertex  = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis]];
            Vector3D endYVertex    = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis]];
            Vector3D startYVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis2]];
            Vector3D endYVertex2   = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis2]];

            int closestZAxis, closestZAxis2;

            GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartZVertices, MyOrientedBoundingBox.EndZVertices, out closestZAxis, out closestZAxis2);
            Vector3D startZVertex  = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis]];
            Vector3D endZVertex    = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis]];
            Vector3D startZVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis2]];
            Vector3D endZVertex2   = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis2]];

            m_cubeEdges.Clear();
            m_cubeEdges.Add(new BoxEdge()
            {
                Axis = 0, Edge = new LineD(startXVertex, endXVertex)
            });
            m_cubeEdges.Add(new BoxEdge()
            {
                Axis = 1, Edge = new LineD(startYVertex, endYVertex)
            });
            m_cubeEdges.Add(new BoxEdge()
            {
                Axis = 2, Edge = new LineD(startZVertex, endZVertex)
            });

            if (!fixedAxes)
            {
                int rotDirection;

                RotationRightAxis      = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Right, out rotDirection);
                RotationRightDirection = rotDirection;

                RotationUpAxis      = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Up, out rotDirection);
                RotationUpDirection = rotDirection;

                RotationForwardAxis      = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Forward, out rotDirection);
                RotationForwardDirection = rotDirection;
            }

            string rightControlName1 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();
            string rightControlName2 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();
            string upControlName1    = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();
            string upControlName2    = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();
            string forwControlName1  = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();
            string forwControlName2  = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString();

            if (MyInput.Static.IsJoystickConnected())
            {
                rightControlName1 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).ToString();
                rightControlName2 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).ToString();
                upControlName1    = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).ToString();
                upControlName2    = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).ToString();
                forwControlName1  = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).ToString();
                forwControlName2  = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).ToString();
            }

            Vector3D rightStart = Vector3D.Zero;
            Vector3D rightEnd = Vector3D.Zero;
            Vector3D upStart = Vector3D.Zero;
            Vector3D upEnd = Vector3D.Zero;
            Vector3D forwStart = Vector3D.Zero;
            Vector3D forwEnd = Vector3D.Zero;
            Vector3D rightStart2 = Vector3D.Zero;
            Vector3D rightEnd2 = Vector3D.Zero;
            Vector3D upStart2 = Vector3D.Zero;
            Vector3D upEnd2 = Vector3D.Zero;
            Vector3D forwStart2 = Vector3D.Zero;
            Vector3D forwEnd2 = Vector3D.Zero;
            int      rightAxis = -1, upAxis = -1, forwAxis = -1;
            int      closestRightEdge = -1, closestUpEdge = -1, closestForwEdge = -1;
            int      closestRightEdge2 = -1, closestUpEdge2 = -1, closestForwEdge2 = -1;

            if (RotationRightAxis == 0)
            {
                rightStart        = startXVertex;
                rightEnd          = endXVertex;
                rightStart2       = startXVertex2;
                rightEnd2         = endXVertex2;
                rightAxis         = 0;
                closestRightEdge  = closestXAxis;
                closestRightEdge2 = closestXAxis2;
            }
            else
            if (RotationRightAxis == 1)
            {
                rightStart        = startYVertex;
                rightEnd          = endYVertex;
                rightStart2       = startYVertex2;
                rightEnd2         = endYVertex2;
                rightAxis         = 1;
                closestRightEdge  = closestYAxis;
                closestRightEdge2 = closestYAxis2;
            }
            else
            if (RotationRightAxis == 2)
            {
                rightStart        = startZVertex;
                rightEnd          = endZVertex;
                rightStart2       = startZVertex2;
                rightEnd2         = endZVertex2;
                rightAxis         = 2;
                closestRightEdge  = closestZAxis;
                closestRightEdge2 = closestZAxis2;
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Not defined axis");
            }

            if (RotationUpAxis == 0)
            {
                upStart        = startXVertex;
                upEnd          = endXVertex;
                upStart2       = startXVertex2;
                upEnd2         = endXVertex2;
                upAxis         = 0;
                closestUpEdge  = closestXAxis;
                closestUpEdge2 = closestXAxis2;
            }
            else
            if (RotationUpAxis == 1)
            {
                upStart        = startYVertex;
                upEnd          = endYVertex;
                upStart2       = startYVertex2;
                upEnd2         = endYVertex2;
                upAxis         = 1;
                closestUpEdge  = closestYAxis;
                closestUpEdge2 = closestYAxis2;
            }
            else
            if (RotationUpAxis == 2)
            {
                upStart        = startZVertex;
                upEnd          = endZVertex;
                upStart2       = startZVertex2;
                upEnd2         = endZVertex2;
                upAxis         = 2;
                closestUpEdge  = closestZAxis;
                closestUpEdge2 = closestZAxis2;
            }

            if (RotationForwardAxis == 0)
            {
                forwStart        = startXVertex;
                forwEnd          = endXVertex;
                forwStart2       = startXVertex2;
                forwEnd2         = endXVertex2;
                forwAxis         = 0;
                closestForwEdge  = closestXAxis;
                closestForwEdge2 = closestXAxis2;
            }
            else
            if (RotationForwardAxis == 1)
            {
                forwStart        = startYVertex;
                forwEnd          = endYVertex;
                forwStart2       = startYVertex2;
                forwEnd2         = endYVertex2;
                forwAxis         = 1;
                closestForwEdge  = closestYAxis;
                closestForwEdge2 = closestYAxis2;
            }
            else
            if (RotationForwardAxis == 2)
            {
                forwStart        = startZVertex;
                forwEnd          = endZVertex;
                forwStart2       = startZVertex2;
                forwEnd2         = endZVertex2;
                forwAxis         = 2;
                closestForwEdge  = closestZAxis;
                closestForwEdge2 = closestZAxis2;
            }

            float textScale = 0.7f;

            //Closest axis
            //VRageRender.MyRenderProxy.DebugDrawLine3D(rightStart, rightEnd, Color.Red, Color.Red, false);
            //VRageRender.MyRenderProxy.DebugDrawLine3D(upStart, upEnd, Color.Green, Color.Green, false);
            //VRageRender.MyRenderProxy.DebugDrawLine3D(forwStart, forwEnd, Color.Blue, Color.Blue, false);


            if (draw)
            {
                //if all axis are visible, all are shown on edges
                //if 1 axis is not visible, other 2 must be shown on faces
                //if 2 are not visible, they are shown on faces and the one is shown on face center
                //Vector3 camVector = Vector3.Normalize(rotateHintsBox.Center - MySector.MainCamera.Position);
                Vector3D camVector      = MySector.MainCamera.ForwardVector;
                Vector3D rightDirection = Vector3.Normalize(rightEnd - rightStart);
                Vector3D upDirection    = Vector3.Normalize(upEnd - upStart);
                Vector3D forwDirection  = Vector3.Normalize(forwEnd - forwStart);
                float    dotRight       = Math.Abs(Vector3.Dot(camVector, rightDirection));
                float    dotUp          = Math.Abs(Vector3.Dot(camVector, upDirection));
                float    dotForw        = Math.Abs(Vector3.Dot(camVector, forwDirection));

                bool drawRightOnFace = false, drawUpOnFace = false, drawForwOnFace = false;
                bool drawRightOnFaceCenter = false, drawUpOnFaceCenter = false, drawForwOnFaceCenter = false;

                float dotAngle = 0.4f;

                if (dotRight < dotAngle)
                {
                    if (dotUp < dotAngle)
                    {
                        drawForwOnFaceCenter = true;
                        drawRightOnFace      = true;
                        drawUpOnFace         = true;

                        System.Diagnostics.Debug.Assert(dotForw >= dotAngle);
                    }
                    else if (dotForw < dotAngle)
                    {
                        drawUpOnFaceCenter = true;
                        drawRightOnFace    = true;
                        drawForwOnFace     = true;

                        System.Diagnostics.Debug.Assert(dotUp >= dotAngle);
                    }
                    else
                    {
                        drawUpOnFace   = true;
                        drawForwOnFace = true;
                    }
                }
                else
                if (dotUp < dotAngle)
                {
                    if (dotRight < dotAngle)
                    {
                        drawForwOnFaceCenter = true;
                        drawRightOnFace      = true;
                        drawUpOnFace         = true;

                        System.Diagnostics.Debug.Assert(dotForw >= dotAngle);
                    }
                    else if (dotForw < dotAngle)
                    {
                        drawRightOnFaceCenter = true;
                        drawUpOnFace          = true;
                        drawForwOnFace        = true;

                        System.Diagnostics.Debug.Assert(dotRight >= dotAngle);
                    }
                    else
                    {
                        drawRightOnFace = true;
                        drawForwOnFace  = true;
                    }
                }
                else
                if (dotForw < dotAngle)
                {
                    if (dotRight < dotAngle)
                    {
                        drawUpOnFaceCenter = true;
                        drawRightOnFace    = true;
                        drawForwOnFace     = true;

                        System.Diagnostics.Debug.Assert(dotUp >= dotAngle);
                    }
                    else if (dotUp < dotAngle)
                    {
                        drawUpOnFaceCenter = true;
                        drawRightOnFace    = true;
                        drawForwOnFace     = true;

                        System.Diagnostics.Debug.Assert(dotRight >= dotAngle);
                    }
                    else
                    {
                        drawUpOnFace    = true;
                        drawRightOnFace = true;
                    }
                }

                //Draw according to cube visual appearance

                if (!(hideForwardAndUpArrows && RotationRightAxis != 1))
                {
                    if (drawRightOnFaceCenter)
                    {
                        //                VRageRender.MyRenderProxy.DebugDrawSphere((forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f, 0.2f, Vector3.Right, 1.0f, false, false);
                        Vector3D faceCenter = (forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f;

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowLeftGreen",
                            Vector4.One,
                            faceCenter - RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f,
                            -RotationForwardDirection * forwDirection,
                            -RotationUpDirection * upDirection,
                            0.2f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRightGreen",
                            Vector4.One,
                            faceCenter + RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f,
                            RotationForwardDirection * forwDirection,
                            RotationUpDirection * upDirection,
                            0.2f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                    else
                    if (drawRightOnFace)
                    {
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(rightStart2, rightEnd2, Color.Red, Color.Red, false);

                        Vector3 normalRightBack, normalRightForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge2, out normalRightForw);
                        Vector3D rightCenter          = (rightStart + rightEnd) * 0.5f;
                        Vector3D rightNormalForwWorld = Vector3D.TransformNormal(normalRightForw, drawMatrix);

                        MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge2, closestRightEdge, out normalRightBack);
                        Vector3D rightCenter2         = (rightStart2 + rightEnd2) * 0.5f;
                        Vector3D rightNormalBackWorld = Vector3D.TransformNormal(normalRightBack, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalForwWorld, Color.Red, Color.Red, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter2, rightCenter2 + rightNormalBackWorld, Color.Red, Color.Red, false);

                        int  normalEdge = -1;
                        bool opposite   = false;
                        if (closestRightEdge == 0 && closestRightEdge2 == 3)
                        {
                            normalEdge = closestRightEdge + 1;
                        }
                        else
                        if ((closestRightEdge < closestRightEdge2) || (closestRightEdge == 3 && closestRightEdge2 == 0))
                        {
                            normalEdge = closestRightEdge - 1;
                            opposite   = true;
                        }
                        else
                        {
                            normalEdge = closestRightEdge + 1;
                        }

                        if (RotationRightDirection < 0)
                        {
                            opposite = !opposite;
                        }

                        Vector3 rightOffset;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, normalEdge, out rightOffset);
                        Vector3D rightOffsetWorld = Vector3D.TransformNormal(rightOffset, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.6f - rightOffsetWorld * 0.01f, opposite ? rightControlName2 : rightControlName1, Color.White, textScale, false);
                        //VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter2 + rightNormalBackWorld * 0.6f - rightOffsetWorld * 0.01f, opposite ? rightControlName1 : rightControlName2, Color.White, textScale, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowGreen",
                            Vector4.One,
                            rightCenter + rightNormalForwWorld * 0.4f - rightOffsetWorld * 0.01f,
                            rightNormalBackWorld,
                            rightDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowGreen",
                            Vector4.One,
                            rightCenter2 + rightNormalBackWorld * 0.4f - rightOffsetWorld * 0.01f,
                            rightNormalForwWorld,
                            rightDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.3f - rightOffsetWorld * 0.01f, opposite ? rightControlName1 : rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter2 + rightNormalBackWorld * 0.3f - rightOffsetWorld * 0.01f, opposite ? rightControlName2 : rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                    else     //draw on edge
                    {
                        Vector3 normalRightBack, normalRightForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge + 1, out normalRightForw);
                        MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge - 1, out normalRightBack);
                        Vector3D rightCenter          = (rightStart + rightEnd) * 0.5f;
                        Vector3D rightNormalForwWorld = Vector3D.TransformNormal(normalRightForw, drawMatrix);
                        Vector3D rightNormalBackWorld = Vector3D.TransformNormal(normalRightBack, drawMatrix);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalForwWorld, Color.Red, Color.Red, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalBackWorld, Color.Red, Color.Red, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowGreen",
                            Vector4.One,
                            rightCenter + rightNormalForwWorld * 0.3f - rightNormalBackWorld * 0.01f,
                            rightNormalForwWorld,
                            rightDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowGreen",
                            Vector4.One,
                            rightCenter + rightNormalBackWorld * 0.3f - rightNormalForwWorld * 0.01f,
                            rightNormalBackWorld,
                            rightDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.3f - rightNormalBackWorld * 0.01f, RotationRightDirection < 0 ? rightControlName1 : rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalBackWorld * 0.3f - rightNormalForwWorld * 0.01f, RotationRightDirection < 0 ? rightControlName2 : rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                }

                if (!(hideForwardAndUpArrows && RotationUpAxis != 1))
                {
                    if (drawUpOnFaceCenter)
                    {
                        //VRageRender.MyRenderProxy.DebugDrawSphere((forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f, 0.2f, Vector3.Up, 1.0f, false, false);

                        Vector3D faceCenter = (forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f;

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowLeftRed",
                            Vector4.One,
                            faceCenter - RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f,
                            -RotationRightDirection * rightDirection,
                            -RotationForwardDirection * forwDirection,
                            0.2f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRightRed",
                            Vector4.One,
                            faceCenter + RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f,
                            RotationRightDirection * rightDirection,
                            RotationForwardDirection * forwDirection,
                            0.2f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                    else
                    if (drawUpOnFace)
                    {
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(upStart2, upEnd2, Color.Green, Color.Green, false);

                        Vector3 normalUpBack, normalUpForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge2, out normalUpForw);
                        Vector3D upCenter          = (upStart + upEnd) * 0.5f;
                        Vector3  upNormalForwWorld = Vector3.TransformNormal(normalUpForw, drawMatrix);

                        MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge2, closestUpEdge, out normalUpBack);
                        Vector3D upCenter2         = (upStart2 + upEnd2) * 0.5f;
                        Vector3  upNormalBackWorld = Vector3.TransformNormal(normalUpBack, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalForwWorld, Color.Green, Color.Green, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter2, upCenter2 + upNormalBackWorld, Color.Green, Color.Green, false);

                        int  normalEdge = -1;
                        bool opposite   = false;
                        if (closestUpEdge == 0 && closestUpEdge2 == 3)
                        {
                            normalEdge = closestUpEdge + 1;
                        }
                        else
                        if ((closestUpEdge < closestUpEdge2) || (closestUpEdge == 3 && closestUpEdge2 == 0))
                        {
                            normalEdge = closestUpEdge - 1;
                            opposite   = true;
                        }
                        else
                        {
                            normalEdge = closestUpEdge + 1;
                        }

                        if (RotationUpDirection < 0)
                        {
                            opposite = !opposite;
                        }

                        Vector3 upOffset;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, normalEdge, out upOffset);
                        Vector3 upOffsetWorld = Vector3.TransformNormal(upOffset, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.6f - upOffsetWorld * 0.01f, opposite ? upControlName1 : upControlName2, Color.White, textScale, false);
                        //VRageRender.MyRenderProxy.DebugDrawText3D(upCenter2 + upNormalBackWorld * 0.6f - upOffsetWorld * 0.01f, opposite ? upControlName2 : upControlName1, Color.White, textScale, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRed",
                            Vector4.One,
                            upCenter + upNormalForwWorld * 0.4f - upOffsetWorld * 0.01f,
                            upNormalBackWorld,
                            upDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRed",
                            Vector4.One,
                            upCenter2 + upNormalBackWorld * 0.4f - upOffsetWorld * 0.01f,
                            upNormalForwWorld,
                            upDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.3f - upOffsetWorld * 0.01f, opposite ? upControlName2 : upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(upCenter2 + upNormalBackWorld * 0.3f - upOffsetWorld * 0.01f, opposite ? upControlName1 : upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                    else     //draw on edge
                    {
                        Vector3 normalUpBack, normalUpForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge + 1, out normalUpForw);
                        MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge - 1, out normalUpBack);
                        Vector3D upCenter          = (upStart + upEnd) * 0.5f;
                        Vector3  upNormalForwWorld = Vector3.TransformNormal(normalUpForw, drawMatrix);
                        Vector3  upNormalBackWorld = Vector3.TransformNormal(normalUpBack, drawMatrix);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalForwWorld, Color.Green, Color.Green, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalBackWorld, Color.Green, Color.Green, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRed",
                            Vector4.One,
                            upCenter + upNormalForwWorld * 0.3f - upNormalBackWorld * 0.01f,
                            upNormalForwWorld,
                            upDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRed",
                            Vector4.One,
                            upCenter + upNormalBackWorld * 0.3f - upNormalForwWorld * 0.01f,
                            upNormalBackWorld,
                            upDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.6f - upNormalBackWorld * 0.01f, RotationUpDirection > 0 ? upControlName1 : upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalBackWorld * 0.6f - upNormalForwWorld * 0.01f, RotationUpDirection > 0 ? upControlName2 : upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                }

                if (!(hideForwardAndUpArrows && RotationForwardAxis != 1))
                {
                    if (drawForwOnFaceCenter)
                    {
                        //VRageRender.MyRenderProxy.DebugDrawSphere((rightStart + rightEnd + rightStart2 + rightEnd2) * 0.25f, 0.2f, Vector3.Backward, 1.0f, false, false);

                        Vector3D faceCenter = (rightStart + rightEnd + rightStart2 + rightEnd2) * 0.25f;

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowLeftBlue",
                            Vector4.One,
                            faceCenter + RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f,
                            RotationUpDirection * upDirection,
                            -RotationRightDirection * rightDirection,
                            0.2f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowRightBlue",
                            Vector4.One,
                            faceCenter - RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f,
                            -RotationUpDirection * upDirection,
                            RotationRightDirection * rightDirection,
                            0.2f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, projectionId);
                    }
                    else
                    if (drawForwOnFace)
                    {
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(forwStart2, forwEnd2, Color.Blue, Color.Blue, false);

                        Vector3 normalForwBack, normalForwForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge2, out normalForwForw);
                        Vector3D forwCenter          = (forwStart + forwEnd) * 0.5f;
                        Vector3  forwNormalForwWorld = Vector3.TransformNormal(normalForwForw, drawMatrix);

                        MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge2, closestForwEdge, out normalForwBack);
                        Vector3D forwCenter2         = (forwStart2 + forwEnd2) * 0.5f;
                        Vector3  forwNormalBackWorld = Vector3.TransformNormal(normalForwBack, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalForwWorld, Color.Blue, Color.Blue, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter2, forwCenter2 + forwNormalBackWorld, Color.Blue, Color.Blue, false);

                        int  normalEdge = -1;
                        bool opposite   = false;
                        if (closestForwEdge == 0 && closestForwEdge2 == 3)
                        {
                            normalEdge = closestForwEdge + 1;
                        }
                        else
                        if ((closestForwEdge < closestForwEdge2) || (closestForwEdge == 3 && closestForwEdge2 == 0))
                        {
                            normalEdge = closestForwEdge - 1;
                            opposite   = true;
                        }
                        else
                        {
                            normalEdge = closestForwEdge + 1;
                        }

                        if (RotationForwardDirection < 0)
                        {
                            opposite = !opposite;
                        }

                        Vector3 forwOffset;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, normalEdge, out forwOffset);
                        Vector3 forwOffsetWorld = Vector3.TransformNormal(forwOffset, drawMatrix);

                        //VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.6f - forwOffsetWorld * 0.01f, opposite ? forwControlName2 : forwControlName1, Color.White, textScale, false);
                        //VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter2 + forwNormalBackWorld * 0.6f - forwOffsetWorld * 0.01f, opposite ? forwControlName1 : forwControlName2, Color.White, textScale, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowBlue",
                            Vector4.One,
                            forwCenter + forwNormalForwWorld * 0.4f - forwOffsetWorld * 0.01f,
                            forwNormalBackWorld,
                            forwDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowBlue",
                            Vector4.One,
                            forwCenter2 + forwNormalBackWorld * 0.4f - forwOffsetWorld * 0.01f,
                            forwNormalForwWorld,
                            forwDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.3f - forwOffsetWorld * 0.01f, opposite ? forwControlName1 : forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter2 + forwNormalBackWorld * 0.3f - forwOffsetWorld * 0.01f, opposite ? forwControlName2 : forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                    else     //draw on edge
                    {
                        Vector3 normalForwBack, normalForwForw;
                        MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge + 1, out normalForwForw);
                        MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge - 1, out normalForwBack);
                        Vector3D forwCenter          = (forwStart + forwEnd) * 0.5f;
                        Vector3  forwNormalForwWorld = Vector3.TransformNormal(normalForwForw, drawMatrix);
                        Vector3  forwNormalBackWorld = Vector3.TransformNormal(normalForwBack, drawMatrix);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalForwWorld, Color.Blue, Color.Blue, false);
                        //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalBackWorld, Color.Blue, Color.Blue, false);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowBlue",
                            Vector4.One,
                            forwCenter + forwNormalForwWorld * 0.3f - forwNormalBackWorld * 0.01f,
                            forwNormalForwWorld,
                            forwDirection,
                            0.5f,
                            110, false, projectionId);

                        MyTransparentGeometry.AddBillboardOriented(
                            "ArrowBlue",
                            Vector4.One,
                            forwCenter + forwNormalBackWorld * 0.3f - forwNormalForwWorld * 0.01f,
                            forwNormalBackWorld,
                            forwDirection,
                            0.5f,
                            110, false, projectionId);

                        VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.3f - forwNormalBackWorld * 0.01f, RotationForwardDirection < 0 ? forwControlName1 : forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                        VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalBackWorld * 0.3f - forwNormalForwWorld * 0.01f, RotationForwardDirection < 0 ? forwControlName2 : forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId);
                    }
                }
            }
        }
        public override void Draw()
        {
            base.Draw();
            if (MyTrashRemoval.PreviewEnabled && MySession.Static.HasAdminRights)
            {
                DrawTrashAdminView();
            }

            bool visible = false;

            for (int i = 0; i < RenderObjectIDs.Length; i++)
            {
                if (RenderObjectIDs[i] == MyRenderProxy.RENDER_ID_UNASSIGNED)
                {
                    break;
                }
                if (MyRenderProxy.VisibleObjectsRead.Contains(this.RenderObjectIDs[i]))
                {
                    visible = true;
                    break;
                }
            }
            if (visible)
            {
                foreach (var block in m_grid.BlocksForDraw)
                {
                    if (MyRenderProxy.VisibleObjectsRead.Contains(block.Render.RenderObjectIDs[0]))
                    {
                        block.Render.Draw();
                    }
                }
            }
            if (MyCubeGrid.ShowCenterOfMass && !IsStatic && Container.Entity.Physics != null && Container.Entity.Physics.HasRigidBody)
            {
                var  matrix = Container.Entity.Physics.GetWorldMatrix();
                var  center = Container.Entity.Physics.CenterOfMassWorld;
                var  cam    = MySector.MainCamera.Position;
                var  dist   = Vector3.Distance(cam, center);
                bool draw   = false;
                if (dist < 30)
                {
                    draw = true;
                }
                else if (dist < 200)
                {
                    draw = true;
                    MyPhysics.CastRay(cam, center, m_tmpHitList, MyPhysics.CollisionLayers.DynamicDoubledCollisionLayer);
                    foreach (var hit in m_tmpHitList)
                    {
                        if (hit.HkHitInfo.GetHitEntity() != this)
                        {
                            draw = false;
                            break;
                        }
                    }
                    m_tmpHitList.Clear();
                }
                if (draw)
                {
                    float size      = MathHelper.Lerp(1, 9, dist / 200);
                    var   mat       = "WeaponLaserIgnoreDepth";
                    var   color     = Color.Yellow.ToVector4();
                    var   thickness = 0.02f * size;
                    MySimpleObjectDraw.DrawLine(center - matrix.Up * 0.5f * size, center + matrix.Up * 0.5f * size, mat, ref color, thickness);
                    MySimpleObjectDraw.DrawLine(center - matrix.Forward * 0.5f * size, center + matrix.Forward * 0.5f * size, mat, ref color, thickness);
                    MySimpleObjectDraw.DrawLine(center - matrix.Right * 0.5f * size, center + matrix.Right * 0.5f * size, mat, ref color, thickness);
                    MyTransparentGeometry.AddBillboardOriented("RedDotIgnoreDepth", Color.White.ToVector4(), center, MySector.MainCamera.LeftVector, MySector.MainCamera.UpVector, 0.1f * size, priority: 1);
                }
            }
            if (MyCubeGrid.ShowGridPivot)
            {
                var  matrix = Container.Entity.WorldMatrix;
                var  pos    = matrix.Translation;
                var  cam    = MySector.MainCamera.Position;
                var  dist   = Vector3.Distance(cam, pos);
                bool draw   = false;
                if (dist < 30)
                {
                    draw = true;
                }
                else if (dist < 200)
                {
                    draw = true;
                    MyPhysics.CastRay(cam, pos, m_tmpHitList, MyPhysics.CollisionLayers.DynamicDoubledCollisionLayer);
                    foreach (var hit in m_tmpHitList)
                    {
                        if (hit.HkHitInfo.GetHitEntity() != this)
                        {
                            draw = false;
                            break;
                        }
                    }
                    m_tmpHitList.Clear();
                }
                if (draw)
                {
                    float size      = MathHelper.Lerp(1, 9, dist / 200);
                    var   mat       = "WeaponLaserIgnoreDepth";
                    var   thickness = 0.02f * size;
                    var   color     = Color.Green.ToVector4();
                    MySimpleObjectDraw.DrawLine(pos, pos + matrix.Up * 0.5f * size, mat, ref color, thickness);
                    color = Color.Blue.ToVector4();
                    MySimpleObjectDraw.DrawLine(pos, pos + matrix.Forward * 0.5f * size, mat, ref color, thickness);
                    color = Color.Red.ToVector4();
                    MySimpleObjectDraw.DrawLine(pos, pos + matrix.Right * 0.5f * size, mat, ref color, thickness);
                    MyTransparentGeometry.AddBillboardOriented("RedDotIgnoreDepth", Color.White.ToVector4(), pos, MySector.MainCamera.LeftVector, MySector.MainCamera.UpVector, 0.1f * size, priority: 1);
                    MyRenderProxy.DebugDrawAxis(matrix, 0.5f, false);//DX 11 desnt support depthRead false
                }
            }

            if (MyCubeGrid.ShowStructuralIntegrity)
            {
                if (m_grid.StructuralIntegrity == null)
                {
                    if (MyFakes.ENABLE_STRUCTURAL_INTEGRITY)
                    {
                        m_grid.CreateStructuralIntegrity();

                        if (m_grid.StructuralIntegrity != null)
                        {
                            m_grid.StructuralIntegrity.EnabledOnlyForDraw = true;
                        }
                    }
                }
                else
                {
                    m_grid.StructuralIntegrity.Draw();
                }
            }
            else
            if (m_grid.StructuralIntegrity != null && m_grid.StructuralIntegrity.EnabledOnlyForDraw)
            {
                m_grid.CloseStructuralIntegrity();
            }

            if (MyFakes.ENABLE_ATMOSPHERIC_ENTRYEFFECT)
            {
                ProfilerShort.Begin("DrawAtmosphericEntryEffect");
                DrawAtmosphericEntryEffect();
                ProfilerShort.End();
            }
        }