1

我正在用电晕 SDK 做一个物理应用程序。在那,我正在创建一个带有关节的组合物理体。我需要的是:'我需要用它的中心旋转新的组合体'。我正在给出代码。任何人请帮助...

  --------------------------------------------------------------------------------------
  local physics = require( "physics" )
  physics.start()
  physics.setDrawMode("debug")
  ---------------------------
     -- Creating bodies --
  ---------------------------
  local body_1 = display.newRect(0,0,40,40)
  local body_2 = display.newRect(0,0,40,40)
  local body_3 = display.newRect(0,0,40,40)
  local base_1 = display.newRect(0,display.contentHeight,display.contentWidth,display.contentHeight)
  body_1.x = 100; body_1.y = 250;
  body_2.x = 100; body_2.y = 300;
  body_3.x = 150; body_3.y = 275;

  ---------------------------
     -- Adding Physics --
  ---------------------------
  physics.addBody( body_1, { density=1.6, friction=0.5, bounce=0.0} )
  physics.addBody( body_2, { density=1.6, friction=0.5, bounce=0.0} )
  physics.addBody( body_3, { density=1.6, friction=0.5, bounce=0.02, radius = 20} )
  physics.addBody( base_1, "static", { density=1.6, friction=0.5, bounce=0.2} )

  ---------------------------
     -- Creating Joints --
  ---------------------------
  local myJoint_1 = physics.newJoint( "weld", body_1, body_2, 100,250 )
  local myJoint_2 = physics.newJoint( "pivot", body_1, body_3, 100,250 )
  local myJoint_2 = physics.newJoint( "pivot", body_2, body_3, 100,300 )

  ---------------------------
      -- My Function --
  ---------------------------
  local function rotateTheGroup()
       -- I want to rotate the combined body here. And I need to know the newBodie's referencepoint.
  end
 Runtime:addEventListener("tap",rotateTheGroup)
 --------------------------------------------------------------------------------------

提前致谢...

4

2 回答 2

2

如果简单体B位于 (x b , y b ),并且轴点C在 (x b , y b ),并且您想将BC旋转角度 t(逆时针),则B去至

B' = (x c +(x b -x c )cos(t)-(y b -y c )sin(t), y c +(x b -x c )sin(t)+(y b - y c )cos(t))

您可以用矩阵表示法更简洁地表达这一点:

B' = C + R ( B - C )

在哪里

R = cos(t) -sin(t)
    sin(t)  cos(t)
于 2013-01-26T15:46:44.220 回答
1

谢谢@Beta,但我已经找到了解决方案。我只是使用下面的代码给身体一个角度脉冲并连续应用它,我完成了工作。

  body_3:applyAngularImpulse( -1000 )

感谢你们的支持。

于 2013-01-28T06:35:17.367 回答