Exemple #1
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            if (_geoFactory == null)
            {
                _geoFactory = new GeometryFactory();
            }
            if (_gc == null)
            {
                _gc = new GeometryConvertor();
            }

            // 初始化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;
            }

            #region 创建地面模型
            Array imgNames = null;
            try
            {
                string           osgPath = (strMediaPath + @"\mdb+osg\Ground\00650100agc4001.osg");
                IResourceFactory resFac  = new ResourceFactory();
                IPropertySet     imgs    = new PropertySet();
                resFac.CreateModelAndImageFromFile(osgPath, out imgs, out ModelSrc, out MatrixSrc);
                this.axRenderControl1.ObjectManager.AddModel("test", ModelSrc);

                string[] keys = imgs.GetAllKeys();
                foreach (string imgName in keys)
                {
                    IImage img = imgs.GetProperty(imgName) as IImage;
                    this.axRenderControl1.ObjectManager.AddImage(imgName, img);
                }

                ModelPointSrc = _geoFactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                ModelPointSrc.ModelEnvelope = ModelSrc.Envelope;
                ModelPointSrc.FromMatrix(MatrixSrc);
                ModelPointSrc.ModelName = "test";

                RenderModelPointSrc = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(ModelPointSrc, null, rootId);
                this.axRenderControl1.Camera.FlyToObject(RenderModelPointSrc.Guid, gviActionCode.gviActionFlyTo);
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
            #endregion

            _geoEditor    = this.axRenderControl1.ObjectEditor;
            _multiPolygon = _geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;

            {
                this.helpProvider1.SetShowHelp(this.axRenderControl1, true);
                this.helpProvider1.SetHelpString(this.axRenderControl1, "");
                this.helpProvider1.HelpNamespace = "GeometryConvert3.html";
            }
        }