android - 如何以其中心 : corona SDK 旋转组合物理体

标签 android rotation physics coronasdk

我正在使用 Corona 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)
 --------------------------------------------------------------------------------------

提前致谢...

最佳答案

若简体B位于(xb, yb),轴点C 位于 (xb, yb),并且您想将 B 围绕 C 旋转一个角度t(逆时针方向),B 转到

B' = (xc+(xb-xc)cos(t)- (yb-yc)sin(t), yc+(xb-xc)sin(t)+(yb-yc)cos(t))

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

B' = C + R(B-C)

在哪里

R = cos(t) -sin(t)
    sin(t)  cos(t)

关于android - 如何以其中心 : corona SDK 旋转组合物理体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14516884/

相关文章:

java - Android上的UDP打洞; UDP 服务器

android - findViewById 返回 null

java - 在父 Activity 中初始化的类对象在子 Activity 中重新初始化

c# - 在 C# 中旋转图像的矩阵乘法

c# - 如何计算弹跳角?

algorithm - 飞船推进AI : control the force to land a ship at x=0 and v=0

Android,如何显示来自 onBufferingUpdate 的缓冲百分比

c# - 来回旋转游戏对象

python - 使用 numpy.fft 的时间带宽积(高斯宽度)

javascript - 围绕传单 map 中的点旋转多边形