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

Microsoft Robotics Studio 模擬真實世界 (10):建立天空與地面環境

     編輯:關於C語言

環境建構:AddSky 與 AddGround

在 MSRS 模擬中,AddSky 與 AddGround 方法負責為 Boe-Bot 機器人構建周圍世界。以下為核心實作細節。

AddSky:天空穹頂與方向光源

建立 SkyDomeEntity 並插入模擬引擎,同時加入一個代表太陽的方向光源:

void AddSky()
{
    // 使用靜態貼圖建立天空穹頂,供逐像素光照使用
    SkyDomeEntity sky = new SkyDomeEntity("skydome.dds", "sky_diff.dds");
    SimulationEngine.GlobalInstancePort.Insert(sky);

    // 新增方向光模擬陽光
    LightSourceEntity sun = new LightSourceEntity();
    sun.State.Name = "Sun";
    sun.Type = LightSourceEntityType.Directional;
    sun.Color = new Vector4(0.8f, 0.8f, 0.8f, 1);
    sun.Direction = new Vector3(0.5f, -0.75f, 0.5f);
    SimulationEngine.GlobalInstancePort.Insert(sun);
}

圖 10:添加天空與光源

AddGround:高度場地形

使用 HeightFieldEntity 在零海拔處建立廣大地面,套用隨 MSRS 提供的紋理:

void AddGround()
{
    HeightFieldEntity ground = new HeightFieldEntity(
        "simple ground",           // 名稱
        "03RamIESc.dds",           // 紋理圖像
        new MaterialProperties(
            "ground",
            0.2f,                  // 反彈係數
            0.5f,                  // 動態摩擦
            0.5f                   // 靜態摩擦
        )
    );
    SimulationEngine.GlobalInstancePort.Insert(ground);
}

AddBoeBot:放置機器人實體

接受 Vector3 位置參數,建立 Boe-Bot 實體並啟動其模擬驅動服務:

void AddBoeBot(Vector3 pos)
{
    BoeBot boeBot = new BoeBot(pos);
    boeBot.State.Name = "SimulatedBoeBot";

    // 啟動模擬驅動服務作為實體夥伴
    CreateService(
        drive.Contract.Identifier,
        Microsoft.Robotics.Simulation.Partners.CreateEntityPartner(
            "https://localhost/" + boeBot.State.Name)
    );
    SimulationEngine.GlobalInstancePort.Insert(boeBot);
}
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved