[Robotics Studio] Pursuit Camera -- Day28

  • 5414
  • 0
  • 2009-02-17

[Robotics Studio] Pursuit Camera -- Day28

之前在玩迷宮機器人的時候, 常常要一邊移動機器人, 一邊移動攝影機 (Camera) 畫面, 很是累人...

尤其是建造了那麼複雜的迷宮之後, 移動攝影機就更是累人了...

在解決問題之前, 先看看 Robotics Developer Studio 原本就提供的範例, 這樣我們就知道有甚麼好的解決辦法了.

打開 VPL (Visual Programming Lanaguage), 點選 File, Open, 找到 RDS 安裝目錄下的 samples\VplExamples\DriveSimFourByFour 下面, 打開這個專案:

image

你應該會看到:

image

執行它, 你會看到一個操控面板讓你操控車子:

image

但更重要的是, 你可以在 VSE (Visual Simulation Environment) 當中找到 Camera - PursuitCamera

image

切換到 PursuitCamera, 然後移動車子...看到了嗎, 這就是我們想要的,

image

我不是指翻車啦, 是攝影機會追著車子跑...這種攝影機就是我們玩遊戲常看的攝影機, 這樣才像樣嘛...

ok, 打完收工, 那個 4x4 的車子已經領便當了...

甚麼? 你說問題還沒解決?

這就是我看那個 MsrsUserGuideExpress.chm 討厭的地方, 問題都沒解決就結束了..

最後只有這段話 :

"The Pursuit Camera consists of two components: a simulation entity and a service. You do not need to start the service to use the camera in the Simulator, but your application must programmatically add a Pursuit Camera entity.

...

By default, the camera entity name is PursuitCamera"

意思就是叫你自己生一個 PursuitCamera Entity 就好了...
還誤導我一句, 有個預設名稱叫做 PursuitCamera ...
(事實上我最後只能這樣解釋: 他是說這個範例裡面的 PursuitCamera 預設值...)

好吧, 讓我告訴各位我是怎麼做的:

1. 在建造迷宮以及機器人那個專案當中, 參考 PursuitCamera.Y2008.M04.dll (在 RDS 安裝目錄的 bin 下面)

2. using 加上 using pursuitcamera = Microsoft.Robotics.Entities.PursuitCamera;

3. 產生機器人以後, 改一下函式, 把機器人的名稱傳回來, 然後加上下面的 code :

string robotname = AddPioneer3DX(new Vector3(1.5f, 0.1f, 0f), -90);

pursuitcamera.PursuitCameraEntity pcamera = new pursuitcamera.PursuitCameraEntity(robotname);
pcamera.State.Name = "PursuitCameraEntity";

SimulationEngine.GlobalInstancePort.Insert(pcamera);

 

這個 code 就是產生一個 PursuitCameraEntity (給他機器人的名稱, 它就會開始追蹤該機器人),
討厭的地方就是它根本沒有預設名稱啊, 所以你要給一個名稱, 不然會沒辦法加入  VSE 當中的...

那麼, 加了這樣的 code , 我們的 VSE 也就出現一個 PursuitCameraEntity 囉.

image

點選 PursuitCameraEntity , 你的攝影機就會跟著機器人跑囉:

image

這樣就不算太混了吧?!