Skyline二次开发--(1)动态对象自定义路径漫游

开发版本:6.5.1

开发语言:C# .net

补充知识:绘制动态对象主要是对鼠标的左右键事件进行注册和响应,左键单击绘制漫游路径,右键结束绘制并激活对象进行漫游。事件注册代码如下:

m_SGworld65.OnLButtonDown += new _ISGWorld65Events_OnLButtonDownEventHandler(m_SGworld65_OnLButtonDown);
m_SGworld65.OnRButtonDown += new _ISGWorld65Events_OnRButtonDownEventHandler(m_SGworld65_OnRButtonDown);

点击创建自定义动态对象漫游时,首先选择指定的三维对象,支持xpc、3ds、dae等主流三维模型格式。

1    m_SGworld65.Window.SetInputMode(MouseInputMode.MI_COM_CLIENT);
2    pITerrainDynamicObject65 = m_SGworld65.Creator.CreateDynamicObject(0, DynamicMotionStyle.MOTION_GROUND_VEHICLE, DynamicObjectType.DYNAMIC_3D_MODEL, Application.StartupPath + "\\chuouTrain.xpc", 1.0, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, "", "动态对象");
3    pITerrainDynamicObject65.Position.Distance = 50;
4 Buffer3d.m_CurRenderType == RenderType.RT_Polyline


接下来处理鼠标左键单击事件,代码如下:

 1 bool m_SGworld65_OnLButtonDown(int Flags, int X, int Y)
 2         {
 3             if (Buffer3d.m_CurRenderType == RenderType.RT_Polyline)
 4             {
 5                 IWorldPointInfo65 pIWorldPointInfo65 = m_SGworld65.Window.PixelToWorld(X, Y, WorldPointType.WPT_ALL);
 6                 if (pITerrainPolyline65 == null)
 7                 {
 8                     double[] cVerticesArray = null;
 9                     cVerticesArray = new double[] {
10                         pIWorldPointInfo65.Position.X,  pIWorldPointInfo65.Position.Y,   0,
11                         pIWorldPointInfo65.Position.X,  pIWorldPointInfo65.Position.Y,   0,                        
12                     };
13 
14                     ILineString pILineString = m_SGworld65.Creator.GeometryCreator.CreateLineStringGeometry(cVerticesArray);
15                     pITerrainPolyline65 = sgworld.Creator.CreatePolyline(pILineString);
16                     pITerrainPolyline65.Geometry.StartEdit();
17                 }
18                 else
19                 {                    
20                     ILineString pILineString = pITerrainPolyline65.Geometry as ILineString;
21                     pILineString.Points.AddPoint(pIWorldPointInfo65.Position.X, pIWorldPointInfo65.Position.Y, 0);
22                 }
23             }
24             return false;
25         }


然后是鼠标右键结束绘制polyline对象时处理代码如下:

 1  bool m_SGworld65_OnRButtonDown(int Flags, int X, int Y)
 2         {
 3             if (pITerrainPolyline65 != null)
 4             {
 5                 pITerrainPolyline65.Geometry.EndEdit();
7                 {
 8                     ILineString pILineString = pITerrainPolyline65.Geometry as ILineString;
 9                     for (var i = 1; i < pILineString.Points.Count; i++)
10                     {
11                         IPoint pIPoint = pILineString.Points[i] as IPoint;
12                         var RouteWaypoint = m_SGworld65.Creator.CreateRouteWaypoint(pIPoint.X, pIPoint.Y, 0, 10, 0, 0, 0, 0, 0, "-1");
13                         pITerrainDynamicObject65.Waypoints.AddWaypoint(RouteWaypoint);
14                     }
15                 }
16                 pITerrainPolyline65 = null;
17 m_SGworld65.Window.SetInputMode(MouseInputMode.MI_FREE_FLIGHT); 18 pITerrainDynamic.CircularRoute = false; 19 pITerrainDynamicObject65.RestartRoute(0); 20 m_SGworld65.Navigate.FlyTo(pITerrainDynamicObject65.ID, ActionCode.AC_JUMP); 21 return true; 22 } 23 else 24 { 25 return false; 26 } 27 }


此时插入的三维对象就可以沿着绘制的多段线进行动态漫游!

 

你可能感兴趣的:(Skyline二次开发--(1)动态对象自定义路径漫游)