2011-07-03 26 views
3

我在旋轉Farseer物理引擎中的Fixture(使用XNA)時遇到了一些麻煩。基本上,我有一個固定裝置,設置爲這樣:Farseer physics(Box2D) - Fixture rotation around point

private void setUpPhysics(World gWorld, Vector2 position) 
    { 
     body = new Body(gWorld); 
     body.BodyType = BodyType.Dynamic; 
     carFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(21f), ConvertUnits.ToSimUnits(35f), 5f, ConvertUnits.ToSimUnits(position), body); 
     carFixture.Restitution = 4f; 
     carFixture.Friction = 5f; 
     carFixture.Body.AngularDamping = 1f; 
     carFixture.Body.LinearDamping = 1f; 
    } 

然後我使用的代碼

carFixture.Body.Rotation -= 0.01f; 

工作正常轉動。問題是,它總是圍繞矩形的左上角旋轉,我需要它圍繞中心旋轉。我將如何圍繞它的中心旋轉燈具? (我爲我的愚蠢道歉 - 我是Farseer/Box2D的新手,我毫不懷疑這是造成這個問題的主要原因,但我一直在網上搜索幾個小時,但一無所獲。)

+0

的主體圍繞其原點旋轉,所以你需要把夾具,使旋轉夾具以(0,0)爲中心。這個AttachRectangle函數看起來像一個偏移量,看起來就是爲了這個目的。 – iforce2d

回答

1

這解決了我自己 - 原來身體是圍繞其中心旋轉,但是被連接到它的質地是圍繞其角