private void MainForm_Load(object sender, System.EventArgs e) { init(); #region 指定每帧刷新事件 axRenderControl1.RcFrame += new _IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); _rcFrame = new _IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); #endregion 指定每帧刷新事件 }
private void MainForm_Load(object sender, System.EventArgs e) { // 初始化RenderControl控件 IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", gviRenderSystem.gviRenderOpenGL); this.axRenderControl1.Initialize(true, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 设置天空盒 if (System.IO.Directory.Exists(strMediaPath)) { string tmpSkyboxPath = strMediaPath + @"\skybox"; ISkyBox skybox = this.axRenderControl1.ObjectManager.GetSkyBox(0); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBack, tmpSkyboxPath + "\\1_BK.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageBottom, tmpSkyboxPath + "\\1_DN.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageFront, tmpSkyboxPath + "\\1_FR.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageLeft, tmpSkyboxPath + "\\1_LF.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageRight, tmpSkyboxPath + "\\1_RT.jpg"); skybox.SetImagePath(gviSkyboxImageIndex.gviSkyboxImageTop, tmpSkyboxPath + "\\1_UP.jpg"); } else { MessageBox.Show("请不要随意更改SDK目录名"); return; } // 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); if (!hasfly) { IFieldInfoCollection fieldinfos = fc.GetFields(); IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); IGeometryDef geometryDef = fieldinfo.GeometryDef; IEnvelope env = geometryDef.Envelope; if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) { continue; } angle.Set(0, -20, 0); this.axRenderControl1.Camera.LookAt(env.Center, 1000, angle); } hasfly = true; } } { this.helpProvider1.SetShowHelp(this.axRenderControl1, true); this.helpProvider1.SetHelpString(this.axRenderControl1, ""); this.helpProvider1.HelpNamespace = "CameraTour.html"; } // 注册播放事件 this.axRenderControl1.RcCameraTourWaypointChanged += new _IRenderControlEvents_RcCameraTourWaypointChangedEventHandler(axRenderControl1_RcCameraTourWaypointChanged); this.axRenderControl1.RcCameraFlyFinished += new _IRenderControlEvents_RcCameraFlyFinishedEventHandler(axRenderControl1_RcCameraFlyFinished); // 注册输出视频事件 this.axRenderControl1.RcVideoExportBegin += new _IRenderControlEvents_RcVideoExportBeginEventHandler(axRenderControl1_RcVideoExportBegin); this.axRenderControl1.RcVideoExporting += new _IRenderControlEvents_RcVideoExportingEventHandler(axRenderControl1_RcVideoExporting); this.axRenderControl1.RcVideoExportEnd += new _IRenderControlEvents_RcVideoExportEndEventHandler(axRenderControl1_RcVideoExportEnd); // 指定每帧刷新事件 this.axRenderControl1.RcFrame += new _IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); _rcFrame = new _IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); }
private void init() { // 设置RenderControl控件为球 string tmpTedPath = (strMediaPath + @"\terrain\SingaporeGlobeTerrain.ted"); wkt = this.axRenderControl1.GetTerrainCrsWKT(tmpTedPath, ""); IPropertySet ps = new PropertySet(); ps.SetProperty("RenderSystem", "OpenGL"); this.axRenderControl1.Initialize2(wkt, ps); this.axRenderControl1.Camera.FlyTime = 1; rootId = this.axRenderControl1.ObjectManager.GetProjectTree().RootID; // 注册地形 this.axRenderControl1.Terrain.RegisterTerrain(tmpTedPath, ""); this.axRenderControl1.Terrain.FlyTo(gviTerrainActionCode.gviFlyToTerrain); this.axRenderControl1.RcFrame += new Gvitech.CityMaker.Controls._IRenderControlEvents_RcFrameEventHandler(axRenderControl1_RcFrame); this.OnFrame = new _IRenderControlEvents_RcFrameEventHandler(OnFrameUpdateUI); #region 加载FDB场景 try { IConnectionInfo ci = new ConnectionInfo(); ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; string tmpFDBPath = (strMediaPath + @"\SDKDEMO.FDB"); ci.Database = tmpFDBPath; IDataSourceFactory dsFactory = new DataSourceFactory(); IDataSource ds = dsFactory.OpenDataSource(ci); string[] setnames = (string[])ds.GetFeatureDatasetNames(); if (setnames.Length == 0) { return; } IFeatureDataSet dataset = ds.OpenFeatureDataset(setnames[0]); string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable); if (fcnames.Length == 0) { return; } fcMap = new Hashtable(fcnames.Length); foreach (string name in fcnames) { IFeatureClass fc = dataset.OpenFeatureClass(name); // 找到空间列字段 List <string> geoNames = new List <string>(); IFieldInfoCollection fieldinfos = fc.GetFields(); for (int i = 0; i < fieldinfos.Count; i++) { IFieldInfo fieldinfo = fieldinfos.Get(i); if (null == fieldinfo) { continue; } IGeometryDef geometryDef = fieldinfo.GeometryDef; if (null == geometryDef) { continue; } geoNames.Add(fieldinfo.Name); } fcMap.Add(fc, geoNames); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); return; } // CreateFeautureLayer //bool hasfly = false; foreach (IFeatureClass fc in fcMap.Keys) { List <string> geoNames = (List <string>)fcMap[fc]; foreach (string geoName in geoNames) { if (!geoName.Equals("Geometry")) { continue; } IFeatureLayer featureLayer = this.axRenderControl1.ObjectManager.CreateFeatureLayer( fc, geoName, null, null, rootId); //if (!hasfly) //{ // IFieldInfoCollection fieldinfos = fc.GetFields(); // IFieldInfo fieldinfo = fieldinfos.Get(fieldinfos.IndexOf(geoName)); // IGeometryDef geometryDef = fieldinfo.GeometryDef; // IEnvelope env = geometryDef.Envelope; // if (env == null || (env.MaxX == 0.0 && env.MaxY == 0.0 && env.MaxZ == 0.0 && // env.MinX == 0.0 && env.MinY == 0.0 && env.MinZ == 0.0)) // continue; // angle.Set(0, -20, 0); // point = new GeometryFactory().CreatePoint(gviVertexAttribute.gviVertexAttributeZ); // point.SpatialCRS = fc.FeatureDataSet.SpatialReference; // point.SetCoords(env.Center.X, env.Center.Y, env.Center.Z, 0, 0); // this.axRenderControl1.Camera.LookAt2(point, 500, angle); //} //hasfly = true; } } #endregion }