首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

Microsoft Robotics Studio 模擬真實世界 (5):模擬教程與紋理球體實體

     編輯:關於C語言

模擬教程切入點

MSRS 安裝目錄 \samples\simulation 提供對應選單的教程專案,SimulationTutorial1 即為「基本模擬環境」的程式碼基礎。

Start 方法:初始化模擬世界

protected override void Start()
{
    base.Start();
    SetupCamera();      // 設定攝影機視點
    PopulateWorld();    // 填充實體物件
}

AddTexturedSphere:插入帶紋理球體 (地球儀)

圖 6:插入地球儀

void AddTexturedSphere(Vector3 position)
{
    SingleShapeEntity entity = new SingleShapeEntity(
        new SphereShape(
            new SphereShapeProperties(10, new Pose(), 1), // 10kg、預設半徑
            position);
    entity.State.Assets.Mesh = "earth.obj"; // .obj 格式網格
    entity.SphereShape.SphereState.Material = new MaterialProperties("sphereMaterial", 0.5f, 0.4f, 0.5f);
    entity.State.Name = "detailed sphere";
    SimulationEngine.GlobalInstancePort.Insert(entity);
}

關鍵說明

  • SingleShapeEntity 適合單一幾何形狀 (球體、盒體等) 的實體建立。
  • 網格檔案需為 .obj 別名物件格式,由 3D 工具匯出。
  • 最後必須呼叫 SimulationEngine.GlobalInstancePort.Insert(entity) 將實體加入模擬。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved