示例#1
0
        public static void DrawHighlightBox(MatrixD matrix, float scale, float lineWidth, MyStringId material, Color colorFace, Color colorWire, BlendTypeEnum blendType)
        {
            // optimized box draw compared to MySimpleObjectDraw.DrawTransparentBox; also allows consistent edge thickness
            MyQuadD     quad;
            Vector3D    p;
            MatrixD     m;
            var         halfScale     = (scale * 0.5f);
            float       lineLength    = scale;
            const float ROTATE_90_RAD = (90f / 180f * MathHelper.Pi); // 90deg in radians

            p = matrix.Translation + matrix.Forward * halfScale;
            if (IsFaceVisible(p, matrix.Forward))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            p = matrix.Translation + matrix.Backward * halfScale;
            if (IsFaceVisible(p, matrix.Backward))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref matrix);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            p = matrix.Translation + matrix.Left * halfScale;
            m = matrix * MatrixD.CreateFromAxisAngle(matrix.Up, ROTATE_90_RAD);
            if (IsFaceVisible(p, matrix.Left))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            p = matrix.Translation + matrix.Right * halfScale;
            if (IsFaceVisible(p, matrix.Right))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            m = matrix * MatrixD.CreateFromAxisAngle(matrix.Left, ROTATE_90_RAD);
            p = matrix.Translation + matrix.Up * halfScale;
            if (IsFaceVisible(p, matrix.Up))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            p = matrix.Translation + matrix.Down * halfScale;
            if (IsFaceVisible(p, matrix.Down))
            {
                MyUtils.GenerateQuad(out quad, ref p, halfScale, halfScale, ref m);
                MyTransparentGeometry.AddQuad(material, ref quad, colorFace, ref p, blendType: blendType);
            }

            var upHalf      = (matrix.Up * halfScale);
            var rightHalf   = (matrix.Right * halfScale);
            var forwardHalf = (matrix.Forward * halfScale);

            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + -rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -upHalf + rightHalf + matrix.Forward * halfScale, matrix.Backward, lineLength, lineWidth, blendType: blendType);

            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + rightHalf + matrix.Up * halfScale, matrix.Down, lineLength, lineWidth, blendType: blendType);

            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + -upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType);
            MyTransparentGeometry.AddLineBillboard(material, colorWire, matrix.Translation + -forwardHalf + upHalf + matrix.Right * halfScale, matrix.Left, lineLength, lineWidth, blendType: blendType);
        }
示例#2
0
            public BillBoardHUDMessage(MyStringId Material, Vector2D Origin, Color BillBoardColor, Vector2D?Offset = null, int TimeToLive = -1, double Scale = 1d, float Width = 1f, float Height = 1f, float Rotation = 0, bool HideHud = true, bool Shadowing = true, BlendTypeEnum Blend = BlendTypeEnum.SDR)
            {
                instance.RegisterCheck();
                BackingObject = instance.CreateMessage(MessageTypes.BillBoardHUDMessage);

                if (BackingObject != null)
                {
                    this.TimeToLive = TimeToLive;
                    this.Origin     = Origin;
                    this.Options    = Options.None;
                    if (HideHud)
                    {
                        this.Options |= Options.HideHud;
                    }
                    if (Shadowing)
                    {
                        this.Options |= Options.Shadowing;
                    }
                    this.BillBoardColor = BillBoardColor;
                    this.Scale          = Scale;
                    this.Material       = Material;
                    this.Rotation       = Rotation;
                    this.Blend          = Blend;
                    if (Offset.HasValue)
                    {
                        this.Offset = Offset.Value;
                    }
                    else
                    {
                        this.Offset = Vector2D.Zero;
                    }
                    this.Width  = Width;
                    this.Height = Height;
                }
            }
示例#3
0
 public SpaceMessage(StringBuilder Message, Vector3D WorldPosition, Vector3D Up, Vector3D Left, double Scale = 1, Vector2D?Offset = null, int TimeToLive = -1, TextOrientation TxtOrientation = TextOrientation.ltr, BlendTypeEnum Blend = BlendTypeEnum.Standard)
 {
     instance.RegisterCheck();
     BackingObject = instance.CreateMessage(MessageTypes.SpaceMessage);
     if (BackingObject != null)
     {
         this.TimeToLive     = TimeToLive;
         this.Scale          = Scale;
         this.WorldPosition  = WorldPosition;
         this.Up             = Up;
         this.Left           = Left;
         this.TxtOrientation = TxtOrientation;
         this.Message        = Message;
         this.Blend          = Blend;
         if (Offset.HasValue)
         {
             this.Offset = Offset.Value;
         }
         else
         {
             this.Offset = Vector2D.Zero;
         }
     }
 }
示例#4
0
 public HUDMessage(StringBuilder Message, Vector2D Origin, Vector2D?Offset = null, int TimeToLive = -1, double Scale = 1.0d, bool HideHud = true, bool Shadowing = false, Color?ShadowColor = null, BlendTypeEnum Blend = BlendTypeEnum.SDR)
 {
     instance.RegisterCheck();
     BackingObject = instance.CreateMessage(MessageTypes.HUDMessage);
     if (BackingObject != null)
     {
         this.TimeToLive = TimeToLive;
         this.Origin     = Origin;
         this.Options    = Options.None;
         if (HideHud)
         {
             Options |= Options.HideHud;
         }
         if (Shadowing)
         {
             Options |= Options.Shadowing;
         }
         var blackshadow = Color.Black;
         if (ShadowColor.HasValue)
         {
             ShadowColor = ShadowColor.Value;
         }
         this.Scale   = Scale;
         this.Message = Message;
         this.Blend   = Blend;
         if (Offset.HasValue)
         {
             this.Offset = Offset.Value;
         }
         else
         {
             this.Offset = Vector2D.Zero;
         }
     }
 }
示例#5
0
 public EntityMessage(StringBuilder Message, IMyEntity Entity, Vector3D LocalPosition, Vector3D Forward, Vector3D Up, int TimeToLive = -1, double Scale = 1, TextOrientation Orientation = TextOrientation.ltr, Vector2D?Offset = null, Vector2D?Max = null, BlendTypeEnum Blend = BlendTypeEnum.Standard)
 {
     instance.RegisterCheck();
     BackingObject = instance.CreateMessage(MessageTypes.EntityMessage);
     if (BackingObject != null)
     {
         if (Max.HasValue)
         {
             this.Max = Max.Value;
         }
         this.Message       = Message;
         this.Entity        = Entity;
         this.LocalPosition = LocalPosition;
         this.Forward       = Forward;
         this.Up            = Up;
         this.TimeToLive    = TimeToLive;
         this.Scale         = Scale;
         this.Visible       = true;
         this.Orientation   = Orientation;
         this.Blend         = Blend;
         if (Offset.HasValue)
         {
             this.Offset = Offset.Value;
         }
         else
         {
             this.Offset = Vector2D.Zero;
         }
     }
 }
示例#6
0
        private static void DrawTransparentCone(Vector3D apexPosition, Vector3 directionVector, Vector3 baseVector, Color color, int wireDivideRatio, MyStringId material, int customViewProjectionMatrix = -1, BlendType blendType = BlendType.Standard)
        {
            Vector3 axis = directionVector;

            axis.Normalize();
            float num = (float)(MathHelperD.TwoPi / (double)wireDivideRatio);

            for (int i = 0; i < wireDivideRatio; i++)
            {
                float    angle  = (float)i * num;
                float    angle2 = (float)(i + 1) * num;
                Vector3D point  = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, angle));
                Vector3D point2 = apexPosition + directionVector + Vector3.Transform(baseVector, Matrix.CreateFromAxisAngle(axis, angle2));
                MyQuadD  myQuadD;
                myQuadD.Point0 = point;
                myQuadD.Point1 = point2;
                myQuadD.Point2 = apexPosition;
                myQuadD.Point3 = apexPosition;
                MyTransparentGeometry.AddQuad(material, ref myQuadD, color, ref Vector3D.Zero, -1, blendType, null);
            }
        }
示例#7
0
 // HACK copied to add blendType.
 private static void DrawTransparentCone(ref MatrixD worldMatrix, float radius, float height, ref Color color, int wireDivideRatio, MyStringId faceMaterial, int customViewProjectionMatrix = -1, BlendType blendType = BlendType.Standard)
 {
     DrawTransparentCone(worldMatrix.Translation, worldMatrix.Forward * height, worldMatrix.Up * radius, color, wireDivideRatio, faceMaterial, customViewProjectionMatrix, blendType);
 }
示例#8
0
        public static void DrawTransparentCylinder(ref MatrixD worldMatrix,
                                                   float radiusBase, float radiusTop, float length, int wireDivideRatio,
                                                   Vector4 faceColor, Vector4 lineColor,
                                                   MyStringId?faceMaterial     = null, MyStringId?lineMaterial = null, float lineThickness = 0.01f,
                                                   BlendTypeEnum lineBlendType = BlendTypeEnum.Standard, BlendTypeEnum faceBlendType = BlendTypeEnum.Standard,
                                                   bool capEnds = true)
        {
            Vector3D dir          = worldMatrix.Forward;
            Vector3D centerBottom = worldMatrix.Translation;
            Vector3D centerTop    = worldMatrix.Translation + dir * length;

            Vector3D currBottom = Vector3D.Zero;
            Vector3D currTop    = Vector3D.Zero;

            Vector3D prevBottom = Vector3D.Zero;
            Vector3D prevTop    = Vector3D.Zero;

            float stepDeg = 360f / wireDivideRatio;

            for (int i = 0; i <= wireDivideRatio; i++)
            {
                float angle = MathHelper.ToRadians(i * stepDeg);

                currBottom.X = radiusBase * Math.Cos(angle);
                currBottom.Y = radiusBase * Math.Sin(angle);
                currBottom.Z = 0;
                currBottom   = Vector3D.Transform(currBottom, worldMatrix);

                currTop.X = radiusTop * Math.Cos(angle);
                currTop.Y = radiusTop * Math.Sin(angle);
                currTop.Z = -length;
                currTop   = Vector3D.Transform(currTop, worldMatrix);

                if (lineMaterial.HasValue)
                {
                    MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, currBottom, (currTop - currBottom), 1f, lineThickness, lineBlendType);
                }

                if (i > 0)
                {
                    if (lineMaterial.HasValue)
                    {
                        MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevBottom, (currBottom - prevBottom), 1f, lineThickness, lineBlendType);
                        MyTransparentGeometry.AddLineBillboard(lineMaterial.Value, lineColor, prevTop, (currTop - prevTop), 1f, lineThickness, lineBlendType);
                    }

                    if (faceMaterial.HasValue)
                    {
                        var quad = new MyQuadD()
                        {
                            Point0 = prevTop,
                            Point1 = currTop,
                            Point2 = currBottom,
                            Point3 = prevBottom
                        };
                        MyTransparentGeometry.AddQuad(faceMaterial.Value, ref quad, faceColor, ref currTop, blendType: faceBlendType);

                        if (capEnds)
                        {
                            var color = faceColor.ToLinearRGB(); // HACK keeping color consistent with AddQuad() and AddLineBillboard()

                            MyTransparentGeometry.AddTriangleBillboard(centerTop, currTop, prevTop, dir, dir, dir,
                                                                       Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currTop, color, faceBlendType);

                            MyTransparentGeometry.AddTriangleBillboard(centerBottom, currBottom, prevBottom, -dir, -dir, -dir,
                                                                       Vector2.Zero, Vector2.Zero, Vector2.Zero, faceMaterial.Value, 0, currBottom, color, faceBlendType);
                        }
                    }
                }

                prevBottom = currBottom;
                prevTop    = currTop;
            }
        }