示例#1
0
        public static void Draw()
        {
            if (m_isGridActive && m_isGridVisible)
            {
                float billboardDelta = m_gridStepInMeters * 10;

                Vector3 selectedObjectPosition = new Vector3(0, 0, 0);
                Vector3 selectedObjectSize     = MinerWars.CommonLIB.AppCode.Utils.MyMwcSectorConstants.SECTOR_SIZE_VECTOR3;

                if (MyEditorGizmo.SelectedEntities.Count > 0)
                {
                    MyEntity selectedPhysObject = MyEditorGizmo.SelectedEntities.ElementAt(0);
                    selectedObjectPosition = selectedPhysObject.GetPosition();
                    selectedObjectSize     = selectedPhysObject.WorldAABB.Size();
                }

                Vector3 gridStartPosition;
                Vector3 billboardPositionDelta;
                Vector3 orientationA;
                Vector3 orientationB;
                float   sizeA;
                float   sizeB;

                if (m_gridOrientation == GridOrientation.ORIENTATION_XY)
                {
                    orientationA           = Vector3.Right;
                    orientationB           = Vector3.Up;
                    sizeA                  = selectedObjectSize.X;
                    sizeB                  = selectedObjectSize.Y;
                    gridStartPosition      = selectedObjectPosition - new Vector3(sizeA / 2, sizeB / 2, 0);
                    billboardPositionDelta = new Vector3(billboardDelta, billboardDelta, 0);
                }
                else if (m_gridOrientation == GridOrientation.ORIENTATION_XZ)
                {
                    orientationA           = -Vector3.Forward;
                    orientationB           = Vector3.Right;
                    sizeA                  = selectedObjectSize.X;
                    sizeB                  = selectedObjectSize.Z;
                    gridStartPosition      = selectedObjectPosition - new Vector3(sizeA / 2, 0, sizeB / 2);
                    billboardPositionDelta = new Vector3(billboardDelta, 0, billboardDelta);
                }
                else
                {
                    orientationA           = Vector3.Up;
                    orientationB           = -Vector3.Forward;
                    sizeA                  = selectedObjectSize.Y;
                    sizeB                  = selectedObjectSize.Z;
                    gridStartPosition      = selectedObjectPosition - new Vector3(0, sizeA / 2, sizeB / 2);
                    billboardPositionDelta = new Vector3(0, billboardDelta, billboardDelta);
                }


                for (float gridADirection = 0; gridADirection < sizeA; gridADirection += billboardDelta)
                {
                    Vector3 startPosition = gridStartPosition + orientationA * gridADirection;
                    Vector3 endPosition   = gridStartPosition + orientationA * gridADirection + orientationB * sizeB;

                    MyTransparentGeometry.AddLineBillboard2(MyTransparentMaterialEnum.ProjectileTrailLine, m_gridColor,
                                                            startPosition, endPosition, 1);
                }

                for (float gridBDirection = 0; gridBDirection < sizeB; gridBDirection += billboardDelta)
                {
                    Vector3 startPosition = gridStartPosition + orientationB * gridBDirection;
                    Vector3 endPosition   = gridStartPosition + orientationB * gridBDirection + orientationA * sizeA;

                    MyTransparentGeometry.AddLineBillboard2(MyTransparentMaterialEnum.ProjectileTrailLine, m_gridColor,
                                                            startPosition, endPosition, 1);
                }
            }
        }