2010-04-05 74 views
3

我的遊戲世界中的每個人都有附加傳感器形狀的燈具。當我進行光線投射時,它會擊中這些燈具,但我只想用至少一個不是傳感器的形狀擊中燈具。這可能嗎?Box2dx:指定要在光線投射中忽略的燈具?

我正在使用Box2dx - C#端口。

此外,回調是做什麼的?

 world.PhysicsWorld.RayCast((f, p, n, fr) => 
     { 
      fixture = f; 
      position = p; 
      return fr; 
     }, point1, point2); 

這是我打來的raycast函數。該文件說,回調可用於指定形狀的數量回去,但我不知道該怎麼做:

/// Ray-cast the world for all fixtures in the path of the ray. Your callback 
    /// controls whether you get the closest point, any point, or n-points. 
    /// The ray-cast ignores shapes that contain the starting point. 
    /// @param callback a user implemented callback class. 
    /// @param point1 the ray starting point 
    /// @param point2 the ray ending point 
    public void RayCast(Func<Fixture, Vector2, Vector2, float, float> callback, Vector2 point1, Vector2 point2) 
    { 
     RayCastInput input = new RayCastInput(); 
     input.maxFraction = 1.0f; 
     input.p1 = point1; 
     input.p2 = point2; 

     _rayCastCallback = callback; 
     _contactManager._broadPhase.RayCast(_rayCastCallbackWrapper, ref input); 
     _rayCastCallback = null; 
    } 

回答

1

因爲沒有其他人已經回答了我給你我可以推測,提供的文檔有點粗略,功能顯然依賴於另一段代碼來完成實際的工作,而我不知道C#,所以我不能告訴你所有的東西。

回調函數是給你結果的函數方法,你必須編寫一個接受給定參數集的函數。您在調用RayCast時將該函數作爲參數傳遞,當您找到重疊時您的函數將被調用,您的回調函數可能會返回一些值來指示是否繼續進行射線廣播,我假定您應該返回true或假。

對於只選擇非傳感器陣列燈具的最佳選擇可能是在您的回調函數中檢查此設置,並且只有在滿足該條件時纔會執行此操作。