Esempio n. 1
0
        ///<summary>更新D3D相机, isAni是否以动画方式更新相机,duraion动画时长毫秒, isImmediateRefreshEarth是否立即刷目标位置地图</summary>
        public void updateD3DCamera(bool isAni = false, int duration = 500, bool isImmediateRefreshEarth = true)
        {
            STRUCT_Camera para = new STRUCT_Camera()
            {
                far = Far, near = Near, fieldofview = FieldOfView
            };

            para.lookat    = new VECTOR3D(cameraLookat.X, cameraLookat.Y, cameraLookat.Z);
            para.pos       = new VECTOR3D(cameraPosition.X, cameraPosition.Y, cameraPosition.Z);
            para.up        = new VECTOR3D(cameraUp.X, cameraUp.Y, cameraUp.Z);
            para.direction = new VECTOR3D(cameraDirection.X, cameraDirection.Y, cameraDirection.Z);

            IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(para));

            Marshal.StructureToPtr(para, ipPara, false);

            D3DManager.ChangeCameraPara(earth.earthkey, ipPara, isAni, duration);
            Marshal.FreeCoTaskMem(ipPara);



            if (duration > 0 && _isAutoUpdateMapModel && operateMode == EOperateMode.地图模式)
            {
                if (isImmediateRefreshEarth)
                {
                    earth.earthManager.refreshEarth();
                }
                tmr.Interval = TimeSpan.FromMilliseconds(duration);
                tmr.Start();
            }
        }
Esempio n. 2
0
        public void updateEarthPara()
        {
            //传实例参数
            IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(earthpara));

            Marshal.StructureToPtr(earthpara, ipPara, false);
            D3DManager.ChangeProperty(earth.earthkey, (int)EModelType.地图, (int)EPropertyType.参数, 0, 0, ipPara, 0, IntPtr.Zero, 0);
            Marshal.FreeCoTaskMem(ipPara);
            //传map ip地址
            IntPtr ipLabel = Marshal.StringToCoTaskMemUni(Config.MapIP); //根据瓦片读取模式传IP或path

            D3DManager.ChangeProperty(earth.earthkey, (int)EModelType.地图, (int)EPropertyType.地址, 0, 0, ipLabel, 0, IntPtr.Zero, 0);
            Marshal.FreeCoTaskMem(ipLabel);

            //传路径2 overlay
            if (earthpara.tileReadMode == ETileReadMode.自定义文件瓦片 || earthpara.tileReadMode == ETileReadMode.自定义Web瓦片)
            {
                ipLabel = Marshal.StringToCoTaskMemUni(Config.MapPath); //路径
                D3DManager.ChangeProperty(earth.earthkey, (int)EModelType.地图, (int)EPropertyType.路径, 0, 0, ipLabel, 0, IntPtr.Zero, 0);
                Marshal.FreeCoTaskMem(ipLabel);
                ipLabel = Marshal.StringToCoTaskMemUni(Config.MapPath2); //路径2, overlay
                D3DManager.ChangeProperty(earth.earthkey, (int)EModelType.地图, (int)EPropertyType.路径2, 0, 0, ipLabel, 0, IntPtr.Zero, 0);
                Marshal.FreeCoTaskMem(ipLabel);
            }
        }
Esempio n. 3
0
        /////<summary>光源集合数组,序号0-5</summary>
        //public CLight[] lights;

        //public Color AmbientLight { get; set; }

        ///<summary>提交环境光</summary>
        public void applyAmbientLight()
        {
            if (lightset == null)
            {
                return;
            }
            D3DManager.ChangeAmbientLight(earth.earthkey, Helpler.ColorToUInt(lightset.AmbientLight));
        }
Esempio n. 4
0
        ///<summary>提交光源</summary>
        public void applyLight()
        {
            IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(lightSturPara));

            Marshal.StructureToPtr(lightSturPara, ipPara, false);

            D3DManager.ChangeLightPara(parent.earth.earthkey, lightnum, ipPara);
            Marshal.FreeCoTaskMem(ipPara);
        }
Esempio n. 5
0
        ///<summary>后台扫描和预计算</summary>
        void bworker_DoWork(object sender, DoWorkEventArgs e)
        {
            //earth.camera.cameraFrustum = new BoundingFrustum(earth.camera.view * Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4 * 1.2f, (float)earth.global.ScreenWidth / earth.global.ScreenHeight, earth.camera.Near, earth.camera.Far));
            earth.camera.cameraFrustum    = new BoundingFrustum(earth.camera.view * earth.camera.projection);
            earth.global.maxlayer         = 0;
            earth.global.maxlayertileinfo = "";

            scan(datas);

            int result = D3DManager.BeginTransfer(earth.earthkey);

            if (result != 0)
            {
                update(datas);
                D3DManager.EndTransfer(earth.earthkey);
            }
        }
Esempio n. 6
0
        ///<summary>更新D3D相机, isAni是否以动画方式更新相机,duraion动画时长毫秒</summary>
        public void updateD3DCamera(bool isAni = false, int duration = 500)
        {
            STRUCT_Camera para = new STRUCT_Camera()
            {
                far = Far, near = Near, fieldofview = FieldOfView
            };

            para.lookat    = new VECTOR3D(cameraLookat.X, cameraLookat.Y, cameraLookat.Z);
            para.pos       = new VECTOR3D(cameraPosition.X, cameraPosition.Y, cameraPosition.Z);
            para.up        = new VECTOR3D(cameraUp.X, cameraUp.Y, cameraUp.Z);
            para.direction = new VECTOR3D(cameraDirection.X, cameraDirection.Y, cameraDirection.Z);

            IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(para));

            Marshal.StructureToPtr(para, ipPara, false);

            D3DManager.ChangeCameraPara(earth.earthkey, ipPara, isAni, duration);
            Marshal.FreeCoTaskMem(ipPara);
        }
Esempio n. 7
0
        ///<summary>根据相机位置重计算缺省光源方向,并提交缺省光源</summary>
        public void applyLights()
        {
            if (lightset == null)
            {
                return;
            }
            applyAmbientLight();
            foreach (var item in lightset.lights)
            {
                IntPtr ipPara = Marshal.AllocCoTaskMem(Marshal.SizeOf(item.lightSturPara));
                Marshal.StructureToPtr(item.lightSturPara, ipPara, false);

                D3DManager.ChangeLightPara(earth.earthkey, item.num, ipPara);
                Marshal.FreeCoTaskMem(ipPara);
            }


            //if (earth.earthManager.earthpara.SceneMode == ESceneMode.局部平面)
            //{
            //    Vector3D vecGround = new Vector3D(0,0,-1);
            //    Vector3D vecY = new Vector3D(0, 1, 0);
            //    Vector3D vecX = new Vector3D(1, 0, 0);
            //    //右侧上光源正常效果
            //    Vector3D vecDir;
            //    RotateTransform3D rotate;
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecY, -60));
            //    vecDir = rotate.Transform(vecGround);
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecX, 60));
            //    vecDir = rotate.Transform(vecDir);

            //    //vecDir.Negate();
            //    vecDir.Normalize();
            //    lights[0].Direction = vecDir;
            //    lights[0].applyLight();

            //    //右侧上光源通透效果
            //    lights[1].Direction = vecDir;
            //    lights[1].applyLight();

            //    //正前方光源

            //    lights[2].Direction =vecY;
            //    lights[2].applyLight();

            //    lights[2].applyLight();
            //}
            //else
            //{
            //    Vector3D vecGround = new Vector3D(earth.camera.cameraPosition.X, earth.camera.cameraPosition.Y, earth.camera.cameraPosition.Z);
            //    vecGround = vecGround * (vecGround.Length / Para.Radius);
            //    Vector3D vecY = new Vector3D(0, 1, 0);
            //    Vector3D vecAxis = Vector3D.CrossProduct(vecGround, vecY);
            //    vecAxis.Normalize();
            //    //右侧上光源正常效果
            //    Vector3D vecDir;
            //    RotateTransform3D rotate;
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60));
            //    vecDir = rotate.Transform(vecGround);
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60));
            //    vecDir = rotate.Transform(vecDir);
            //    vecDir.Negate();
            //    vecDir.Normalize();
            //    lights[0].Direction = vecDir;
            //    lights[0].applyLight();

            //    //右侧上光源通透效果
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60));
            //    vecDir = rotate.Transform(vecGround);
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60));
            //    vecDir = rotate.Transform(vecDir);
            //    vecDir.Negate();
            //    vecDir.Normalize();
            //    lights[1].Direction = vecDir;
            //    lights[1].applyLight();

            //    //正前方光源
            //    rotate = new RotateTransform3D(new AxisAngleRotation3D(vecAxis, -60));
            //    vecDir = rotate.Transform(vecGround);
            //    //rotate = new RotateTransform3D(new AxisAngleRotation3D(vecGround, 60));
            //    //vecDir = rotate.Transform(vecDir);
            //    vecDir.Negate();
            //    vecDir.Normalize();
            //    lights[2].Direction = vecDir;
            //    lights[2].applyLight();
            //}
        }
Esempio n. 8
0
        ///<summary>返回场景中3D点在场景平面的坐标</summary>
        public System.Windows.Point transformD3DToScreen(VECTOR3D point3d)
        {
            POINT p = D3DManager.TransformD3DToScreen(earth.earthkey, point3d);

            return(new System.Windows.Point(p.x, p.y));
        }
Esempio n. 9
0
        /// <summary>
        /// 遍历进行操作
        /// </summary>
        /// <param name="node"></param>
        private void update(EarthData node)  //遍历进行更新操作
        {
            while (node.subCurve.Count(p => !p.handled) > 0)
            {
                update(node.subCurve.First(p => !p.handled));
            }


            switch (node.operate)
            {
            case EOperate.节点模型删除:
                //mapTiles.Remove(node.id);
                //Earth.DelMapTile(node.layer,node.idxx,node.idxy);
                node.parent.subCurve.Remove(node);
                node.parent = null;
                break;

            case EOperate.节点删除:
                node.parent.subCurve.Remove(node);
                node.parent = null;
                break;

            case EOperate.模型删除:
                //mapTiles.Remove(node.id);
                //Earth.DelMapTile(node.layer,node.idxx,node.idxy);
                node.curStatus = node.oprStatus;
                break;

            case EOperate.模型加入:
                //mapTiles.Add(node.id, updateTiles[node.id]);
            {
                if (node.mustModelStatus == EMeshStatus.维)
                {
                    int    count  = node.terrainHeigList.Count;
                    IntPtr ipHigh = Marshal.AllocCoTaskMem(Marshal.SizeOf(node.terrainHeigList[0]) * count);          //传递点序列结构数组指针
                    for (int i = 0; i < count; i++)
                    {
                        Marshal.StructureToPtr(node.terrainHeigList[i], (IntPtr)(ipHigh.ToInt32() + i * Marshal.SizeOf(node.terrainHeigList[i])), false);
                    }
                    D3DManager.AddMapTile(earth.earthkey, node.hashcode, node.layer, node.idxx, node.idxy, node.mustModelStatus == EMeshStatus.维, node.terrainSliceCount, ipHigh);          // 当isshowterrain为true且terrainspan与原值不同,将会重建地形mesh
                    Marshal.FreeCoTaskMem(ipHigh);
                }
                else
                {
                    D3DManager.AddMapTile(earth.earthkey, node.hashcode, node.layer, node.idxx, node.idxy, false, 0, IntPtr.Zero);          //isShowTerrain为false时,不会更改地形相关数据,仅为开关控制
                }
            }
                node.curStatus = node.oprStatus;
                break;

            case EOperate.模型更新:
            {
                if (node.mustModelStatus == EMeshStatus.维)
                {
                    int    count  = node.terrainHeigList.Count;
                    IntPtr ipHigh = Marshal.AllocCoTaskMem(Marshal.SizeOf(node.terrainHeigList[0]) * count);          //传递点序列结构数组指针
                    for (int i = 0; i < count; i++)
                    {
                        Marshal.StructureToPtr(node.terrainHeigList[i], (IntPtr)(ipHigh.ToInt32() + i * Marshal.SizeOf(node.terrainHeigList[i])), false);
                    }
                    D3DManager.AddMapTile(earth.earthkey, node.hashcode, node.layer, node.idxx, node.idxy, node.mustModelStatus == EMeshStatus.维, node.terrainSliceCount, ipHigh);          // 当isshowterrain为true且terrainspan与原值不同,将会重建地形mesh
                    Marshal.FreeCoTaskMem(ipHigh);
                }
                else
                {
                    D3DManager.AddMapTile(earth.earthkey, node.hashcode, node.layer, node.idxx, node.idxy, false, 0, IntPtr.Zero);          //isShowTerrain为false时,不会更改地形相关数据,仅为开关控制
                }
            }

                //D3DManager.AddMapTile(earth.earthkey, node.hashcode, node.layer, node.idxx, node.idxy);


                //models.Remove(node.model);
                //node.updateModel();
                //models.Add(node.model);
                //node.curStatus = node.oprStatus;
                break;

            case EOperate.none:
                node.curStatus = node.oprStatus;
                break;
            }
            node.operate = EOperate.none;
            node.handled = true;
        }