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

/// <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);
}