示例#1
0
        private Vector2 GetScreenPosition(MySolarSystemMapCamera camera, Vector3 worldPosition)
        {
            Vector3 target           = SharpDXHelper.ToXNA(MyCamera.Viewport.Project(SharpDXHelper.ToSharpDX(worldPosition), SharpDXHelper.ToSharpDX(camera.GetProjectionMatrix()), SharpDXHelper.ToSharpDX(camera.GetViewMatrixAtZero()), SharpDXHelper.ToSharpDX(Matrix.Identity)));
            Vector2 projected2Dpoint = new Vector2(target.X, target.Y);

            return(MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(projected2Dpoint));
        }
示例#2
0
        public void Update(MySolarSystemMapCamera camera)
        {
            m_isMouseOverPrevious = m_isMouseOver;
            m_isMouseOver         = false;

            UpdateWorldPosition(camera);

            Vector3 objToCamera = m_worldPosition;
            float   dist        = objToCamera.Length();

            Visible = IsVisible(dist);

            if (Vector3.Dot(camera.Forward, objToCamera) >= 0 && Visible)
            {
                UpdateRenderedSizeAndOffsetPosition();
                // we must use offset, because we need mark to be upper to other icons
                //m_worldPosition += camera.Up * m_actualRenderedSize * 4 * m_offsetIndex;
                m_worldPosition += new Vector3(0f, 1f, 0f) * m_actualRenderedSize * 4 * m_offsetIndex;

                m_screenPosition = GetScreenPosition(camera, m_worldPosition);
                Vector2 topLeft     = GetScreenPosition(camera, m_worldPosition + camera.Left * m_actualRenderedSize + camera.Up * m_actualRenderedSize);
                Vector2 bottomRight = GetScreenPosition(camera, m_worldPosition - camera.Left * m_actualRenderedSize - camera.Up * m_actualRenderedSize);


                m_isMouseOver = MyGuiManager.MouseCursorPosition.X >= topLeft.X && MyGuiManager.MouseCursorPosition.X <= bottomRight.X &&
                                MyGuiManager.MouseCursorPosition.Y >= topLeft.Y && MyGuiManager.MouseCursorPosition.Y <= bottomRight.Y;
            }

            if (m_isMouseOverPrevious != m_isMouseOver)
            {
                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
            }
        }
示例#3
0
        private void UpdateWorldPosition(MySolarSystemMapCamera camera)
        {
            MyMwcVector3Int sectorOffset;

            sectorOffset.X = Sector.X - camera.TargetSector.X;
            sectorOffset.Y = Sector.Y - camera.TargetSector.Y;
            sectorOffset.Z = Sector.Z - camera.TargetSector.Z;

            m_worldPosition = MySolarMapRenderer.MillionKmToGameUnits(MySolarSystemUtils.SectorsToMillionKm(sectorOffset)) +
                              /*new Vector3(0f, RADIUS * m_offsetIndex, 0f) + */ camera.CameraToTarget - camera.Target;
        }
        public MyGuiScreenSolarSystemMap(MyGuiScreenBase parent, MyMwcSectorIdentifier currentSector)
            : base(new Vector2(0.5f, 0.5f), null, Vector2.One)
        {
            m_parent = parent;
            m_enableBackgroundFade = false;
            DrawMouseCursor = true;
            m_currentSector = currentSector;
            m_closeOnEsc = true;

            Static = this;

            MySolarSystemGenerator generator = new MySolarSystemGenerator(UNIVERSE_SEED);
            generator.Generate(1024);

            m_data = generator.SolarSystemData;
            m_solarMapRender = new MySolarMapRenderer();
            m_solarMapRender.PlayerSector = currentSector.Position;

            //MyMinerGame.SwitchPause();
            m_particlesEnabled = TransparentGeometry.Particles.MyParticlesManager.Enabled;
            TransparentGeometry.Particles.MyParticlesManager.Enabled = false;

            //AddCaption(MyTextsWrapperEnum.SolarSystemMap);

            MySolarSystemMapNavigationMark playerNavigationMark =
                new MySolarSystemMapNavigationMark(
                    currentSector.Position,
                    "",
                    null,
                    MyHudConstants.SOLAR_MAP_PLAYER_MARKER_COLOR,
                    MyTransparentMaterialEnum.SolarMapPlayer)
                    {
                        VerticalLineColor = MyHudConstants.SOLAR_MAP_PLAYER_MARKER_COLOR.ToVector4(),
                        DirectionalTexture = MyHudTexturesEnum.DirectionIndicator_green,
                        Offset = new Vector3(0, 0.0f, 0),
                        Text = MyClientServer.LoggedPlayer.GetDisplayName().ToString(),
                        Importance = 50
                    };
            m_data.NavigationMarks.Add(playerNavigationMark);

            if (MyGuiScreenGamePlay.Static.IsEditorStoryActive() || MyGuiScreenGamePlay.Static.GetPreviousGameType() == MyGuiScreenGamePlayType.EDITOR_STORY)
            {
                // Loads all marks, we want it for editor
                LoadMarks(false);
            }
            else
            {
                // Load only active marks
                MyMissions.AddSolarMapMarks(m_data);
            }

            if (MyMissions.ActiveMission != null)
            {
                MyMissions.ActiveMission.AddSolarMapMarks(m_data);
            }

            m_travelButton = new MyGuiControlButton(this, new Vector2(0.0f, 0.40f),
                new Vector2(650f / 1600f, 120f / 1200f),
                MyGuiConstants.BUTTON_BACKGROUND_COLOR,
                MyGuiManager.GetTravelButtonTexture(),
                MyGuiManager.GetTravelButtonTexture(),
                MyGuiManager.GetTravelButtonTexture(),
                MyTextsWrapperEnum.Travel,
                MyGuiConstants.BACK_BUTTON_TEXT_COLOR,
                MyGuiConstants.BACK_BUTTON_TEXT_SCALE,
                MyGuiControlButtonTextAlignment.CENTERED,
                OnTravelClick,
                false,
                MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
                true,
                false);
            m_travelButton.TextOffset = new Vector2(0, -0.0030f);
            m_travelButton.Visible = false;
            Controls.Add(m_travelButton);

            // target sector 0, 0, 0
            // distance is 1.7 sectors from camera
            Vector3 sector;

            var mostImportantMark = m_data.NavigationMarks.GetMostImportant();
            if (mostImportantMark != null) {
                sector = new Vector3(mostImportantMark.Sector.X, mostImportantMark.Sector.Y, mostImportantMark.Sector.Z);
            } else {
                sector = new Vector3(currentSector.Position.X, currentSector.Position.Y, currentSector.Position.Z);
            }

            sector.Y = 0;

            m_camera = new MySolarSystemMapCamera(sector * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS, 10000000.0f * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS);
            m_camera.MinDistanceToTarget = 1.7f * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS;
            m_camera.MaxDistanceToTarget = 1.2f * MySolarSystemUtils.MillionKmToSectors(MyBgrCubeConsts.NEPTUNE_POSITION.Length()) * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS;
            m_camera.MaxSector = MySolarSystemUtils.MillionKmToSectors(MyBgrCubeConsts.NEPTUNE_POSITION.Length());

            MyGuiManager.FullscreenHudEnabled = true;
        }
        public void Draw(MySolarSystemMapCamera camera, MySolarSystemMapData solarData)
        {
            MyTransparentGeometry.ClearBillboards();
            
            m_currentCamera = camera;
            m_currentSolarMapData = solarData;
            m_setup.ViewMatrix = camera.GetViewMatrixAtZero();
            //m_setup.ViewMatrix *= Matrix.CreateTranslation(camera.Position);
            m_setup.CameraPosition = camera.Position;
            float nearClip = 0.1f * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS;
            float farClip = 100000000 * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS;
            m_setup.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MyCamera.FieldOfView, MyCamera.ForwardAspectRatio, nearClip, farClip);
            //m_setup.ProjectionMatrix = camera.GetProjectionMatrix();

            MyTransparentGeometry.EnableColorize = true;
            MyTransparentGeometry.ColorizeColor = new Color(0.8f, 0.8f, 0.8f, 0.0f);
            MyTransparentGeometry.ColorizePlaneDistance = m_currentCamera.Position.Y + m_currentCamera.PositionSector.Y * MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS;
            MyTransparentGeometry.ColorizePlaneNormal = Vector3.UnitY;
            MyRender.RegisterRenderModule(MyRenderModuleEnum.SolarMapGrid, "Solar map grid", DrawGrid, MyRenderStage.AlphaBlendPreHDR);
            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);

            m_texts.ClearAllAllocated();

            AddBillboards(m_currentSolarMapData.Entities);
            AddAreasBorders(m_currentSolarMapData.AreasBorderLines);
            AddAreaTexts(m_currentSolarMapData.Areas);
            { //Add available missions
                AddNavigationMarks(m_currentSolarMapData.NavigationMarks);
            }

            if (MyFakes.DRAW_FACTION_AREAS_IN_SOLAR_MAP)
            {
                DrawFactionsDebug();
                DrawEditedFactionDebug();
            }

            MyHudText text = m_texts.Allocate();
            if (text != null)
            {
                text.Start(MyGuiManager.GetFontMinerWarsWhite(), new Vector2(
                    MyGuiManager.GetSafeFullscreenRectangle().X + MyGuiManager.GetSafeFullscreenRectangle().Width,
                    MyGuiManager.GetSafeFullscreenRectangle().Y + MyGuiManager.GetSafeFullscreenRectangle().Height),
                    Color.White, 1.0f, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
                text.Append(m_currentCamera.TargetSector.ToString());
            }

            Vector3 pos = new Vector3(m_currentCamera.TargetSector.X, m_currentCamera.TargetSector.Y, m_currentCamera.TargetSector.Z);
            int dist = (int)Math.Ceiling(SECTOR_RENDER_HALFSIZE);
            for (int x = (int)pos.X - dist; x <= (int)pos.X + dist; x++)
            {
                int y = 0;
                //for (int y = (int)pos.Y - dist; y <= (int)pos.Y + dist; y++)
                {
                    for (int z = (int)pos.Z - dist; z <= (int)pos.Z + dist; z++)
                    {
                        var sectorPos = new MyMwcVector3Int(x, y, z);
                        //float minSize = (x == pos.X && y == pos.Y && z == pos.Z) ? 1.5f : 3;
                        //float minSize = 1.5f;                        
                        int maxEntityCount = (x == pos.X && y == pos.Y && z == pos.Z) ? 150 : 100;                        

                        //MySolarSystemMapSectorData sectorData;
                        //if (!m_currentSolarMapData.SectorData.TryGetValue(sectorPos, out sectorData))
                        //{                            
                        //    var g = new MySectorGenerator(MyGuiScreenSolarSystemMap.UNIVERSE_SEED);
                        //    sectorData = g.GenerateSectorEntities(m_currentSolarMapData, sectorPos, 0, maxEntityCount);
                        //    m_currentSolarMapData.SectorData[sectorPos] = sectorData;
                        //}
                        //AddBillboards(sectorData.Entities);                        
                    }
                }
            }
            
            MyRender.Draw();
            DrawTexts();
            //DrawSolarDebug();

            MyRender.PopRenderSetupAndRevert(m_backup);
            MyRender.UnregisterRenderModule(MyRenderModuleEnum.SolarMapGrid);
            //MyRender.UnregisterRenderModule(SOLAR_DEBUG_DRAW);
            MyRender.UnregisterRenderModule(MyRenderModuleEnum.SolarObjects);
            MyTransparentGeometry.EnableColorize = false;
        }
 static Vector3 EntityPosition(MySolarSystemMapEntity entity, MySolarSystemMapCamera camera)
 {
     return EntityPosition(entity.Sector, entity.PositionInSector, camera);            
 }
        static Vector3 EntityPosition(MyMwcVector3Int sector, Vector3 positionInSector, MySolarSystemMapCamera camera)
        {
            MyMwcVector3Int sectorOffset;
            sectorOffset.X = sector.X - camera.TargetSector.X;
            sectorOffset.Y = sector.Y - camera.TargetSector.Y;
            sectorOffset.Z = sector.Z - camera.TargetSector.Z;

            return MillionKmToGameUnits(MySolarSystemUtils.SectorsToMillionKm(sectorOffset)) + KmToGameUnits(positionInSector) + camera.CameraToTarget - camera.Target;
        }