protected override void Dispose(bool disposing) { if (disposing) { GlobeLayer.Dispose(); MapLayer.Dispose(); } base.Dispose(disposing); }
public override void Initialize() { MapLayer = new MapLayer(Game, Config); //ElevationLayer = new ElevationLayer(Game, Config); OpenStreetMapSource = new OpenStreetMapSource(Game, MapLayer); //GeoObjectsLayer = new GeoObjectsLayer(Game, Config); GlobeLayer = new GlobeLayer(Game, Config); WikiMapiaSource = new WikiMapiaSource(Game, MapLayer); }
public GlobeLayer AddNewLayer() { GameObject newGO = Instantiate(layerPrefab); GlobeLayer rtn = newGO.GetComponent <GlobeLayer>(); layers.Add(rtn); rtn.transform.SetParent(transform, false); rtn.Initialize(textureMapWidth, textureMapWidth / 2); if (activeLayer == null) { SelectLayer(rtn); } OnSyncLayers(); return(rtn); }
public void SelectLayer(GlobeLayer newLayer) { activeLayer = newLayer; OnSyncLayers(); }
private void Form1_Load(object sender, EventArgs e) { try { // 加载ArcGIS地图 string fileName = ConfigurationManager.AppSettings["3DDFile"]; this.globe3DControl1.Load3DDFile(fileName); string contentRoot = ConfigurationManager.AppSettings["ContentRoot"]; // 初始化三维渲染 this.globe3DControl1.Initialize3D(0.001, 2.5, true, true, contentRoot); this.globe3DControl1.ShowSun = false; this.globe3DControl1.ShowMoon = false; // Fix me: 这里需要手动初始化一下DetectRange的硬件资源 // 能否放在一个统一的扩展初始化函数中? DetectRange.InitGeometries(globe3DControl1.World.World.ContentManager); // 制作雷达范围的测试数据 // 360个方向,5个高度层? // TODO: 先通过完整的圆球来测试,然后再测试有随机遮蔽的情况 #region P-雷达范围 // 改为通过添加实体的方式来测试? m_RadarLayer = globe3DControl1.World.AddLayer("radarLayer"); Entity3D radarEntity = m_RadarLayer.AddEntity("radar01"); // radarEntity.Visible = false; radarEntity.Color = Vector4.One; GeographicCoordinateTransform transformCmp = new GeographicCoordinateTransform(); transformCmp.AlwaysFaceGeoCenter = true; transformCmp.LocalPose.Scale = new Vector3d(100, 100, 100); transformCmp.Longitude = 120; transformCmp.Latitude = 30; transformCmp.Height = 0; radarEntity.AddComponent(transformCmp); DetectRangeComponent detectRange = new DetectRangeComponent(); // DetectRange detectRange = new DetectRange(); // 创建一个变换矩阵 // 缩小后放在北极? Matrix4d matScale = Matrix4d.Scale(0.0001); Matrix4d matTran = Matrix4d.CreateTranslation(0, 1, 0); detectRange.UseSimpleNormal = true; // detectRange.Transform = matScale * matTran; detectRange.Color = new Vector4(0.8f, 1, 0.8f, 0.9f); detectRange.ScanColor = new Vector4(1.0f, 0.6f, 0.2f, 0.5f); // TODO: 创建随机的360度的范围的遮蔽数据 // 通过Perlin噪声来模拟 double[] occlusion = new double[360]; PerlinNoise noise = new PerlinNoise(99); for (int i = 0; i < 360; i++) { double val = (noise.Noise(2 * i / 180.0, 2 * i / 180.0, -0.5)) * 0.7 + (noise.Noise(4 * i / 180.0, 4 * i / 180.0, 0)) * 0.2 + (noise.Noise(8 * i / 180.0, 8 * i / 180.0, 0.5)) * 0.1; val = Math.Max(val * 3, 0); occlusion[i] = val * 6000 + 800; } detectRange.Ranges.Add(CreateHorizRange(300, 1000, occlusion)); detectRange.Ranges.Add(CreateHorizRange(600, 2500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(800, 3500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(1500, 4500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2000, 4400, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2500, 4000, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2300, 800, occlusion)); detectRange.RefreshGeometry(); radarEntity.AddComponent(detectRange); m_DetectRange = detectRange; #endregion // 创建雷达范围自定义图元 // 添加到场景中 // globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(detectRange); #region 扫描范围锥体 bool useSenceVolumePrim = false; if (useSenceVolumePrim) { // 直接用自定义图元测试 RectSenseVolume senceVolume = new RectSenseVolume(); senceVolume.Initialize(globe3DControl1.World.ContentManager); // 属性:变换矩阵 Matrix4d matRot = Matrix4d.CreateRotationX(Math.PI * 0.5); senceVolume.Transform = matRot * Matrix4d.CreateTranslation(0, -5.6, 0); senceVolume.HorizHalfAngle = 5.5; senceVolume.VertiHalfAngle = 10.5; senceVolume.Color = Vector4.One; globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(senceVolume); } else { // 用实体和组件测试 m_SatelliteLayer = globe3DControl1.World.AddLayer("satelliteLayer"); Entity3D satelliteEntity = m_SatelliteLayer.AddEntity("satellite01"); GeographicCoordinateTransform satTran = new GeographicCoordinateTransform(); satTran.AlwaysFaceGeoCenter = true; satTran.Longitude = 120; satTran.Latitude = 0; satTran.Height = 35800e3; satelliteEntity.AddComponent(satTran); Vector3d satellitePos = Globe3DCoordHelper.GraphicToCentric(satTran.Longitude, satTran.Latitude, satTran.Height); // 注意:卫星模型的视觉放大需要通过再加一个卫星模型子实体来实现,否则会影响传感器子实体 #region 大视场传感器 Entity3D sensorEntity = m_SatelliteLayer.AddEntity("sensor01"); sensorEntity.Parent = satelliteEntity; SRTTransformComponent sensorTran = new SRTTransformComponent(); // sensorTran.RotationX = 10; sensorEntity.AddComponent(sensorTran); CustomController.SensorAutoScanController sensorCtrl = new CustomController.SensorAutoScanController(); sensorEntity.AddComponent(sensorCtrl); RectSenseVolumeComponent sensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager); sensorRange.HorizHalfAngle = 5.5; sensorRange.VertiHalfAngle = 10.5; sensorRange.Pickable = false; sensorRange.Color = new Vector4(1, 0.4f, 0, 0.2f);// Vector4.One; sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane() { CurrAngle = 0, Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Vertical, Visible = true, Color = new Vector4(1, 0.2f, 0, 0.25f) }); //sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane() //{ // CurrAngle = 0, // Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Horizontal, // Visible = true, // Color = new Vector4(0, 1, 0, 0.4f) //}); sensorRange.InvalidateScanPlanes(); sensorEntity.AddComponent(sensorRange); #endregion #region 小视场传感器 Entity3D smallSensorEntity = m_SatelliteLayer.AddEntity("sensor02"); smallSensorEntity.Parent = satelliteEntity; CustomController.SensorGridScanController sensorGridCtrl = new CustomController.SensorGridScanController(); sensorGridCtrl.MinHorizAngle = 2; sensorGridCtrl.MaxHorizAngle = 4; sensorGridCtrl.MinVertiAngle = 2; sensorGridCtrl.MaxVertiAngle = 4; sensorGridCtrl.NumHorizGrids = 2; sensorGridCtrl.NumVertiGrids = 2; sensorGridCtrl.MoveInterval = 0.75; sensorGridCtrl.StayInterval = 0.25; sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 0)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 1)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 1)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 0)); smallSensorEntity.AddComponent(sensorGridCtrl); SRTTransformComponent smallSensorTran = new SRTTransformComponent(); smallSensorEntity.AddComponent(smallSensorTran); RectSenseVolumeComponent smallSensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager); smallSensorRange.HorizHalfAngle = 0.5; smallSensorRange.VertiHalfAngle = 0.5; smallSensorRange.Pickable = false; smallSensorRange.Color = new Vector4(0, 1, 0, 0.4f); smallSensorEntity.AddComponent(smallSensorRange); #endregion ////////////////////////////////////// uint precision = 30; double theta = 6.5; double range = 11; List<Vector3d> points = RadarIntersect((Vector3d)satellitePos, theta, range, precision); m_PackedMarkStyle = new PackedBillboardMaterialStyle(globe3DControl1.World.ContentManager); m_PackedMarkStyle.Texture = globe3DControl1.World.ContentManager.LoadTexture(@".\Resources\Textures\PackedIcons.png"); using (FileStream fs = new FileStream(@".\Resources\Textures\PackedIcons.xml", FileMode.Open, FileAccess.Read)) { XmlSerializer xs = new XmlSerializer(typeof(List<PackedImage>)); m_PackedMarkStyle.PackedImages = xs.Deserialize(fs) as List<PackedImage>; fs.Close(); // 如果加载失败怎么办 if (m_PackedMarkStyle.PackedImages == null) { throw new InvalidDataException("Failed loading packed image definition"); } } for (int i = 0; i < points.Count; i++) { Vector3d p = points[i]; Vector3d pos = Globe3DCoordHelper.CentricToGraphic(p.X, p.Y,p.Z); Entity3D markEntity = m_SatelliteLayer.AddEntity(i.ToString()); GeographicCoordinateTransform geoTf = new GeographicCoordinateTransform(); geoTf.Longitude = pos.X; geoTf.Latitude = pos.Y; geoTf.Height = pos.Z; markEntity.AddComponent(geoTf); BillboardComponent bgIcon = new BillboardComponent(); bgIcon.Pickable = true; bgIcon.Color = Vector4.One; bgIcon.Visible = true; bgIcon.Width = 20; bgIcon.Height = 20; // Fix me: 本billboard的偏移量在哪里进行比较好? bgIcon.Offset = new Vector2d(0, 0); bgIcon.MaterialStyle = m_PackedMarkStyle; // Fix me: 通过名称获得packed image index的操作在哪里进行比较好? bgIcon.PackID = m_PackedMarkStyle.GetPackIndexByName("bg.fw.png"); // 所有的组成部分使用统一的组ID bgIcon.GroupID = markEntity.ID; // 背景最先绘制 bgIcon.RenderOrder = 0; markEntity.AddComponent(bgIcon); } } #endregion // 摄像机操作 // 设置摄像机跟随预警机实体 globe3DControl1.CameraController.ObserveMode = Controls.GIS3D.Core.EntityComponent.Controller.GlobeCameraControllerComponent.CameraObserveMode.Free; // 修改摄像机的oriantationmode为surface globe3DControl1.CameraController.OrientationMode = GlobeCameraControllerComponent.CameraOrientationMode.NorthPole; globe3DControl1.CameraController.MinDistanceMeter = 200;// 30000; globe3DControl1.CameraController.CurViewDistance = 11400000; //this.globe3DControl1.World.GlobeCameraController.LowRange = 200000; this.globe3DControl1.World.GlobeCameraController.LowRange = 20000; this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 0.2; //this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 4; this.globe3DControl1.World.GlobeCameraController.AutoRotate = false; m_Simulator = new GlobeSimulator(); m_Simulator.Updated += new GlobeSimulator.UpdateEventHandler(m_Simulator_Updated); m_Simulator.StartSimulation(); m_SimTimer.Interval = 40; m_SimTimer.Tick += new EventHandler(m_SimTimer_Tick); m_SimTimer.Start(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); Debug.WriteLine(ex.ToString()); throw; } }
public void DrawInRenderTarget(GameTime gameTime, DepthStencil2D ds, RenderTarget2D target, Viewport viewport) { GlobeLayer.DrawInRenderTarget(gameTime, ds, target, viewport); }
public override void Draw(GameTime gameTime, StereoEye stereoEye) { GlobeLayer.Draw(gameTime); }
public override void Update(GameTime gameTime) { MapLayer.Update(gameTime); GlobeLayer.Update(gameTime); }
private void Form1_Load(object sender, EventArgs e) { try { // 加载ArcGIS地图 string fileName = ConfigurationManager.AppSettings["3DDFile"]; this.globe3DControl1.Load3DDFile(fileName); string contentRoot = ConfigurationManager.AppSettings["ContentRoot"]; // 初始化三维渲染 this.globe3DControl1.Initialize3D(0.001, 2.5, true, true, contentRoot); this.globe3DControl1.ShowSun = false; this.globe3DControl1.ShowMoon = false; // Fix me: 这里需要手动初始化一下DetectRange的硬件资源 // 能否放在一个统一的扩展初始化函数中? DetectRange.InitGeometries(globe3DControl1.World.World.ContentManager); // 制作雷达范围的测试数据 // 360个方向,5个高度层? // TODO: 先通过完整的圆球来测试,然后再测试有随机遮蔽的情况 #region P-雷达范围 // 改为通过添加实体的方式来测试? m_RadarLayer = globe3DControl1.World.AddLayer("radarLayer"); Entity3D radarEntity = m_RadarLayer.AddEntity("radar01"); // radarEntity.Visible = false; radarEntity.Color = Vector4.One; GeographicCoordinateTransform transformCmp = new GeographicCoordinateTransform(); transformCmp.AlwaysFaceGeoCenter = true; transformCmp.LocalPose.Scale = new Vector3d(100, 100, 100); transformCmp.Longitude = 120; transformCmp.Latitude = 30; transformCmp.Height = 0; radarEntity.AddComponent(transformCmp); DetectRangeComponent detectRange = new DetectRangeComponent(); // DetectRange detectRange = new DetectRange(); // 创建一个变换矩阵 // 缩小后放在北极? Matrix4d matScale = Matrix4d.Scale(0.0001); Matrix4d matTran = Matrix4d.CreateTranslation(0, 1, 0); detectRange.UseSimpleNormal = true; // detectRange.Transform = matScale * matTran; detectRange.Color = new Vector4(0.8f, 1, 0.8f, 0.9f); detectRange.ScanColor = new Vector4(1.0f, 0.6f, 0.2f, 0.5f); // TODO: 创建随机的360度的范围的遮蔽数据 // 通过Perlin噪声来模拟 double[] occlusion = new double[360]; PerlinNoise noise = new PerlinNoise(99); for (int i = 0; i < 360; i++) { double val = (noise.Noise(2 * i / 180.0, 2 * i / 180.0, -0.5)) * 0.7 + (noise.Noise(4 * i / 180.0, 4 * i / 180.0, 0)) * 0.2 + (noise.Noise(8 * i / 180.0, 8 * i / 180.0, 0.5)) * 0.1; val = Math.Max(val * 3, 0); occlusion[i] = val * 6000 + 800; } detectRange.Ranges.Add(CreateHorizRange(300, 1000, occlusion)); detectRange.Ranges.Add(CreateHorizRange(600, 2500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(800, 3500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(1500, 4500, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2000, 4400, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2500, 4000, occlusion)); detectRange.Ranges.Add(CreateHorizRange(2300, 800, occlusion)); detectRange.RefreshGeometry(); radarEntity.AddComponent(detectRange); m_DetectRange = detectRange; #endregion // 创建雷达范围自定义图元 // 添加到场景中 // globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(detectRange); #region 扫描范围锥体 bool useSenceVolumePrim = false; if (useSenceVolumePrim) { // 直接用自定义图元测试 RectSenseVolume senceVolume = new RectSenseVolume(); senceVolume.Initialize(globe3DControl1.World.ContentManager); // 属性:变换矩阵 Matrix4d matRot = Matrix4d.CreateRotationX(Math.PI * 0.5); senceVolume.Transform = matRot * Matrix4d.CreateTranslation(0, -5.6, 0); senceVolume.HorizHalfAngle = 5.5; senceVolume.VertiHalfAngle = 10.5; senceVolume.Color = Vector4.One; globe3DControl1.World.World.RenderScene.CustomRenderPrimitives.Add(senceVolume); } else { // 用实体和组件测试 m_SatelliteLayer = globe3DControl1.World.AddLayer("satelliteLayer"); Entity3D satelliteEntity = m_SatelliteLayer.AddEntity("satellite01"); GeographicCoordinateTransform satTran = new GeographicCoordinateTransform(); satTran.AlwaysFaceGeoCenter = true; satTran.Longitude = 120; satTran.Latitude = 0; satTran.Height = 35800e3; satelliteEntity.AddComponent(satTran); Vector3d satellitePos = Globe3DCoordHelper.GraphicToCentric(satTran.Longitude, satTran.Latitude, satTran.Height); // 注意:卫星模型的视觉放大需要通过再加一个卫星模型子实体来实现,否则会影响传感器子实体 #region 大视场传感器 Entity3D sensorEntity = m_SatelliteLayer.AddEntity("sensor01"); sensorEntity.Parent = satelliteEntity; SRTTransformComponent sensorTran = new SRTTransformComponent(); // sensorTran.RotationX = 10; sensorEntity.AddComponent(sensorTran); CustomController.SensorAutoScanController sensorCtrl = new CustomController.SensorAutoScanController(); sensorEntity.AddComponent(sensorCtrl); RectSenseVolumeComponent sensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager); sensorRange.HorizHalfAngle = 5.5; sensorRange.VertiHalfAngle = 10.5; sensorRange.Pickable = false; sensorRange.Color = new Vector4(1, 0.4f, 0, 0.2f);// Vector4.One; sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane() { CurrAngle = 0, Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Vertical, Visible = true, Color = new Vector4(1, 0.2f, 0, 0.25f) }); //sensorRange.ScanPlanes.Add(new RectSenseVolume.ScanPlane() //{ // CurrAngle = 0, // Orientation = RectSenseVolume.ScanPlane.ScanOrientations.Horizontal, // Visible = true, // Color = new Vector4(0, 1, 0, 0.4f) //}); sensorRange.InvalidateScanPlanes(); sensorEntity.AddComponent(sensorRange); #endregion #region 小视场传感器 Entity3D smallSensorEntity = m_SatelliteLayer.AddEntity("sensor02"); smallSensorEntity.Parent = satelliteEntity; CustomController.SensorGridScanController sensorGridCtrl = new CustomController.SensorGridScanController(); sensorGridCtrl.MinHorizAngle = 2; sensorGridCtrl.MaxHorizAngle = 4; sensorGridCtrl.MinVertiAngle = 2; sensorGridCtrl.MaxVertiAngle = 4; sensorGridCtrl.NumHorizGrids = 2; sensorGridCtrl.NumVertiGrids = 2; sensorGridCtrl.MoveInterval = 0.75; sensorGridCtrl.StayInterval = 0.25; sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 0)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(0, 1)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 1)); sensorGridCtrl.ScanSequence.Add(new System.Drawing.Point(1, 0)); smallSensorEntity.AddComponent(sensorGridCtrl); SRTTransformComponent smallSensorTran = new SRTTransformComponent(); smallSensorEntity.AddComponent(smallSensorTran); RectSenseVolumeComponent smallSensorRange = new RectSenseVolumeComponent(globe3DControl1.World.ContentManager); smallSensorRange.HorizHalfAngle = 0.5; smallSensorRange.VertiHalfAngle = 0.5; smallSensorRange.Pickable = false; smallSensorRange.Color = new Vector4(0, 1, 0, 0.4f); smallSensorEntity.AddComponent(smallSensorRange); #endregion ////////////////////////////////////// uint precision = 30; double theta = 6.5; double range = 11; List <Vector3d> points = RadarIntersect((Vector3d)satellitePos, theta, range, precision); m_PackedMarkStyle = new PackedBillboardMaterialStyle(globe3DControl1.World.ContentManager); m_PackedMarkStyle.Texture = globe3DControl1.World.ContentManager.LoadTexture(@".\Resources\Textures\PackedIcons.png"); using (FileStream fs = new FileStream(@".\Resources\Textures\PackedIcons.xml", FileMode.Open, FileAccess.Read)) { XmlSerializer xs = new XmlSerializer(typeof(List <PackedImage>)); m_PackedMarkStyle.PackedImages = xs.Deserialize(fs) as List <PackedImage>; fs.Close(); // 如果加载失败怎么办 if (m_PackedMarkStyle.PackedImages == null) { throw new InvalidDataException("Failed loading packed image definition"); } } for (int i = 0; i < points.Count; i++) { Vector3d p = points[i]; Vector3d pos = Globe3DCoordHelper.CentricToGraphic(p.X, p.Y, p.Z); Entity3D markEntity = m_SatelliteLayer.AddEntity(i.ToString()); GeographicCoordinateTransform geoTf = new GeographicCoordinateTransform(); geoTf.Longitude = pos.X; geoTf.Latitude = pos.Y; geoTf.Height = pos.Z; markEntity.AddComponent(geoTf); BillboardComponent bgIcon = new BillboardComponent(); bgIcon.Pickable = true; bgIcon.Color = Vector4.One; bgIcon.Visible = true; bgIcon.Width = 20; bgIcon.Height = 20; // Fix me: 本billboard的偏移量在哪里进行比较好? bgIcon.Offset = new Vector2d(0, 0); bgIcon.MaterialStyle = m_PackedMarkStyle; // Fix me: 通过名称获得packed image index的操作在哪里进行比较好? bgIcon.PackID = m_PackedMarkStyle.GetPackIndexByName("bg.fw.png"); // 所有的组成部分使用统一的组ID bgIcon.GroupID = markEntity.ID; // 背景最先绘制 bgIcon.RenderOrder = 0; markEntity.AddComponent(bgIcon); } } #endregion // 摄像机操作 // 设置摄像机跟随预警机实体 globe3DControl1.CameraController.ObserveMode = Controls.GIS3D.Core.EntityComponent.Controller.GlobeCameraControllerComponent.CameraObserveMode.Free; // 修改摄像机的oriantationmode为surface globe3DControl1.CameraController.OrientationMode = GlobeCameraControllerComponent.CameraOrientationMode.NorthPole; globe3DControl1.CameraController.MinDistanceMeter = 200;// 30000; globe3DControl1.CameraController.CurViewDistance = 11400000; //this.globe3DControl1.World.GlobeCameraController.LowRange = 200000; this.globe3DControl1.World.GlobeCameraController.LowRange = 20000; this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 0.2; //this.globe3DControl1.World.GlobeCameraController.LowRangeLeanFactor = 4; this.globe3DControl1.World.GlobeCameraController.AutoRotate = false; m_Simulator = new GlobeSimulator(); m_Simulator.Updated += new GlobeSimulator.UpdateEventHandler(m_Simulator_Updated); m_Simulator.StartSimulation(); m_SimTimer.Interval = 40; m_SimTimer.Tick += new EventHandler(m_SimTimer_Tick); m_SimTimer.Start(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Debug.WriteLine(ex.ToString()); throw; } }