YouTube | Facebook | X(Twitter) | RSS

3D マーカー エレメントの作成と移動

2016/9/1 (木)

C#
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/// <summary>
/// 初期化
/// </summary>
/// <param name="Scene">Scene</param>
private void Initialize(IScene Scene)
{
    //ポイントエレメントを描画するレイヤの作成とシーンへの追加
    IGraphicsContainer3D pGraphicsContainer3D = new GraphicsLayer3DClass();
    ILayer pLayer = (ILayer)pGraphicsContainer3D;
    pLayer.Name = "MyPoint";
    Scene.AddLayer((ILayer)pGraphicsContainer3D, false);
  
    IElement pElement = MakePointElement("Test");
  
    pGraphicsContainer3D.AddElement(pElement);
  
    axSceneControl.SceneGraph.RefreshViewers();
  
    g_point_element_container_3d = pGraphicsContainer3D;
}
  
/// <summary>
/// 3D マーカー エレメントの作成
/// </summary>
/// <param name="Name">エレメント名</param>
/// <returns>MarkerElement</returns>
private IElement MakePointElement(string Name)
{
    IElement pElement = new MarkerElementClass();
  
    //3Dマーカーシンボル
    IMarker3DSymbol pMarker3DSymbol = new Marker3DSymbolClass();
    pMarker3DSymbol.CreateFromFile(@".\rx-78-2.dae");   //3D用ファイルの指定
    pMarker3DSymbol.UseMaterialDraping = true;
  
    IMarker3DPlacement pMarker3DPlacement = (IMarker3DPlacement)pMarker3DSymbol;
    pMarker3DPlacement.Size = 1;
    pMarker3DPlacement.SetRotationAngles(0, 0, 0);   //Pitch, Roll, Yaw
  
    IMarkerElement marker_element = (IMarkerElement)pElement;
    marker_element.Symbol = (IMarkerSymbol)pMarker3DSymbol;
  
    IElementProperties pElementProperties = (IElementProperties)pElement;
    pElementProperties.Name = Name;
  
    //  ジオメトリの設定
    IPoint pPoint = new PointClass();
    IZAware pZAware = (IZAware)pPoint;
    pZAware.ZAware = true;
      
    pElement.Geometry = pPoint;
  
    return pElement;
}
  
/// <summary>
/// 指定したポイントにポイント エレメントを移動
/// </summary>
/// <param name="SceneGraph">SceneGraph</param>
/// <param name="GraphicsContainer">GraphicsContainer</param>
/// <param name="Name">エレメント名</param>
/// <param name="Point">Point</param>
/// <returns>bool</returns>
private bool MoveElement(ISceneGraph SceneGraph, IGraphicsContainer GraphicsContainer, string Name, IPoint Point, double X,double Y, double Z)
{
    //エレメントの取得
    GraphicsContainer.Reset();
    IElement pElement = GraphicsContainer.Next();
  
    while (pElement != null)
    {
        IElementProperties pElementProperties = (IElementProperties)pElement;
        if (pElementProperties.Name == Name)
        {
            break;
        }
  
        pElement = GraphicsContainer.Next();
    }
  
    if (pElement == null)
    {
        return false;
    }
  
  
    IPoint pPoint = (IPoint)pElement.Geometry;
    pPoint.X = Point.X;
    pPoint.Y = Point.Y;
  
    IZAware pZAware = (IZAware)pPoint;
    if (pZAware.ZAware == true)
    {
        pPoint.Z = Point.Z;
    }
  
    IMarkerElement pMarkerElement = (IMarkerElement)pElement;
    IMarker3DPlacement pMarker3DPlacement = (IMarker3DPlacement)pMarkerElement.Symbol;
    pMarker3DPlacement.SetRotationAngles(X, Y, Z);
  
    pMarkerElement.Symbol = (IMarkerSymbol)pMarker3DPlacement;
  
    pElement.Geometry = pPoint;
  
    //更新を通知
    GraphicsContainer.UpdateElement(pElement);
  
    //  再描画
    SceneGraph.Invalidate((object)GraphicsContainer, true, true);
    SceneGraph.RefreshViewers();
  
    return true;
}
  
//  タイマーイベントハンドラ
private void timer1_Tick(object sender, EventArgs e)
{
    //int seed = Environment.TickCount;
    //Random rnd = new Random(seed);
    //int randomNumber = rnd.Next(1, 4);
  
    //switch (randomNumber)
    //{
    //    case 1:
    //        seed = Environment.TickCount;
    //        bool blnX = new Random(seed).Next(100) % 2 == 0;
    //        if (blnX == true)
    //        {
    //            g_now_x += 0.1;
    //        }
    //        else
    //        {
    //            g_now_x -= 0.1;
    //        }
  
    //        break;
  
    //    case 2:
    //        seed = Environment.TickCount;
    //        bool blnY = new Random(seed).Next(100) % 2 == 0;
    //        if (blnY == true)
    //        {
    //            g_now_y += 0.1;
    //        }
    //        else
    //        {
    //            g_now_y -= 0.1;
    //        }
    //        break;
  
    //    case 3:
    //        seed = Environment.TickCount;
    //        bool blnZ = new Random(seed).Next(100) % 2 == 0;
    //        if (blnZ == true)
    //        {
    //            g_now_z += 0.1;
    //        }
    //        else
    //        {
    //            g_now_z -= 0.1;
    //        }
  
    //        break;
    //    default:
    //        break;
    //}
  
  
  
  
    if (g_now_x > 10) { g_now_x = 10; }
    if (g_now_y > 10) { g_now_y = 10; }
    if (g_now_z > 10) { g_now_z = 10; }
    if (g_now_x < -10) { g_now_x = -10; }
    if (g_now_y < -10) { g_now_y = -10; }
    if (g_now_z < -10) { g_now_z = -10; }
  
    g_now_x -= 0.1;                         //  X軸に沿って移動
    if (g_now_x < 0.0)
    {                    //  X座標値が正になったら
        g_now_z += 0.1;                     //  Z座標値も増加させる
        g_now_y -= 0.1;
    }
  
    IPoint pPoint = new PointClass();
    pPoint.X = g_now_x;
    pPoint.Y = g_now_y;
    pPoint.Z = g_now_z;
  
    IZAware pZAware = (IZAware)pPoint;
    pZAware.ZAware = true;
  
  
    MoveElement(axSceneControl.SceneGraph, (IGraphicsContainer)g_point_element_container_3d, "Test", pPoint,0,0,0);
}
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,

S