Example #1
0
        public override bool DebugDraw()
        {
            bool boxMode = false;

            Vector3 pos;

            if (GetAddPosition(out pos))
            {
                var result = Intersect();
                if (result.HasValue && result.Value.Entity is MyMysteriousCube)
                {
                    if (!boxMode)
                    {
                        float mult = 0.01f;
                        var   bb   = m_modelLod0.BoundingBox.Translate(pos);
                        bb.Max += m_modelLod0.BoundingBoxSize * mult;
                        bb.Min -= m_modelLod0.BoundingBoxSize * mult;
                        var bb2 = m_modelLod0.BoundingBox.Translate(result.Value.Entity.WorldMatrix.Translation);
                        bb2.Max += m_modelLod0.BoundingBoxSize * mult;
                        bb2.Min -= m_modelLod0.BoundingBoxSize * mult;

                        if (bb.Intersects(bb2))
                        {
                            bb2.Min = Vector3.Clamp(bb2.Min, bb.Min, bb.Max);
                            bb2.Max = Vector3.Clamp(bb2.Max, bb.Min, bb.Max);
                            Vector4 color = Color.Green.ToVector4();
                            color.W = 0.5f;
                            MyStateObjects.DepthStencil_TestFarObject_DepthReadOnly.Apply();
                            MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();
                            MyDebugDraw.DrawAABBSolidLowRes(bb2, color, 1.0f);
                        }
                    }
                    else
                    {
                        var bb = result.Value.Entity.WorldAABB;
                        bb.Inflate(0.1f);
                        Vector4 color = Color.Red.ToVector4();
                        MyStateObjects.DepthStencil_TestFarObject.Apply();
                        MyDebugDraw.DrawAABBLowRes(ref bb, ref color, 1.0f);
                    }
                }

                if (boxMode)
                {
                    BoundingBox bb = m_modelLod0.BoundingBox;
                    bb = bb.Translate(pos);
                    bb.Inflate(0.1f);
                    Vector4 color = Color.Green.ToVector4();
                    color.W = 0.5f;
                    MyStateObjects.DepthStencil_StencilReadOnly.Apply();
                    MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();
                    MyDebugDraw.DrawAABBSolidLowRes(bb, color, 1.0f);
                }
            }

            return(base.DebugDraw());
        }