complex physics body construction

I am trying to setup a complex body setup (actually am trying a very simple example, with two rectangles stacked one on top of other (like an L shaped figure) and pivoted to the ceiling). I tried to follow the car example here: http://developer.coronalabs.com/content/game-edition-physics-bodies I understand the concept but am totally confused as to how to setup up the shape coordinates for the individual two rectangles forming the complex body. Let me give an example here.
The shape is like this:
[html]
____
| |
| |
|__ |______
|_________|
[/html]
[lua]
– A general function for dragging physics bodies
local function dragBody( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage()
if “began” == phase then
stage:setFocus( body, event.id )
body.isFocus = true
– Create a temporary touch joint and store it in the object for later reference
body.tempJoint = physics.newJoint( “touch”, body, event.x, event.y )
elseif body.isFocus then
if “moved” == phase then
– Update the joint to track the touch
body.tempJoint:setTarget( event.x, event.y )
elseif “ended” == phase or “cancelled” == phase then
stage:setFocus( body, nil )
body.isFocus = false
– Remove the joint when the touch ends
body.tempJoint:removeSelf()
end
end
– Stop further propagation of touch event
return true
end
–> Create Walls
–local leftWall = display.newRect (group,0, 0, 1, display.contentHeight)
local rightWall = display.newRect (group,display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect (group,0, -10, display.contentWidth, 10)
local floor = display.newRect (group,0, display.contentHeight, display.contentWidth, 1)
physics.start()
system.activate( “multitouch” )
–physics.addBody (leftWall, “static”, {density=100,bounce = 0.0, friction = 10})
physics.addBody (rightWall, “static”, {density=100,bounce = 0.0, friction = 10})
physics.addBody (ceiling, “static”, {density=100,bounce = 0.0, friction = 10})
physics.addBody (floor, “static”, {density=100,bounce = 0.0, friction = 10})

local obj3 = display.newImageRect( group,“images/level1/iPhone/test.png”,60, 160 )
obj3.x = 30
obj3.y = 80
obj3:setFillColor(20, 150, 200, 100)
shape1 = {-30,80,0,80,0,-20,-30,-20}
shape2 = {-30,-20,30,-20,30,-80,-30,-80}
physics.addBody(obj3, “dynamic”, {density = 1.0, friction = 0.3, bounce = 0.2,shape=shape1},{density = 1.0, friction = 0.3, bounce = 0.2,shape=shape2})
local joint = physics.newJoint( “pivot”, ceiling, obj3, 30, 0 )
obj3:addEventListener( “touch”, dragBody )
[/lua]
test.png is just a simple rectangular image width=60, height=160. This is the bounding rectangle for the entire complex body.

As you can see, the complex shape has two rectangles, with vertices listed in clockwise direction as shape1 and shape2. I am assuming that obj3 has default CenterReferencePoint. Hence, I have calculated the vertices for shape1 and shape2 by assuming that relative origin(0,0) is in the middle of test.png for the obj3 components, dividing test.png in 4 quardants - topLeft,topRight,bottomRight and bottomLeft.
My further assumptions in calculating shape1 and shape2 vertices are:

  1. all x and y coords in topRight are positive
  2. all x and y coords in bottomLeft are negative

Ok, looks all good in theory but when I run this code, the complex body simply does not move at all. It does not respond to drag. In fact, it acts as if it is no more a physics body. If I put another physics object next to obj3, the object wont register any collision with obj3 and will behave as if obj3 does not exist at all.

So, can anyone tell me how to wire up this complex body properly.

Thanks for help.
-Anshu [import]uid: 91950 topic_id: 35932 reply_id: 335932[/import]

Hi Anshu,
In regards to coordinates, you’re thinking along a Cartesian system, but this is actually shifted in Corona. The guide below explains it… and the principle applies to declaring physics bodies.
http://docs.coronalabs.com/guide/start/displayGroups/index.html

You might also want to read the tutorial on multi-element bodies here:
http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
And about physics event contact here:
http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps!
Brent Sorrentino [import]uid: 200026 topic_id: 35932 reply_id: 142835[/import]

Thanks for response Brent. I followed the way you constructed the nebula complex body. So, you too have the local reference point for the nebula in the center(CenterReferencePoint) and divide the whole image in 4 quadrants. I realized that bottom right quadrant has both x and y positive and top left quadrant has both x and y negative. This coordinate system finally gave me the right coordinates for the complex body component shapes. The complex body now works perfect.

-Anshu [import]uid: 91950 topic_id: 35932 reply_id: 142969[/import]

Hi Anshu,
In regards to coordinates, you’re thinking along a Cartesian system, but this is actually shifted in Corona. The guide below explains it… and the principle applies to declaring physics bodies.
http://docs.coronalabs.com/guide/start/displayGroups/index.html

You might also want to read the tutorial on multi-element bodies here:
http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
And about physics event contact here:
http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps!
Brent Sorrentino [import]uid: 200026 topic_id: 35932 reply_id: 142835[/import]

Thanks for response Brent. I followed the way you constructed the nebula complex body. So, you too have the local reference point for the nebula in the center(CenterReferencePoint) and divide the whole image in 4 quadrants. I realized that bottom right quadrant has both x and y positive and top left quadrant has both x and y negative. This coordinate system finally gave me the right coordinates for the complex body component shapes. The complex body now works perfect.

-Anshu [import]uid: 91950 topic_id: 35932 reply_id: 142969[/import]

Hi Anshu,
In regards to coordinates, you’re thinking along a Cartesian system, but this is actually shifted in Corona. The guide below explains it… and the principle applies to declaring physics bodies.
http://docs.coronalabs.com/guide/start/displayGroups/index.html

You might also want to read the tutorial on multi-element bodies here:
http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
And about physics event contact here:
http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps!
Brent Sorrentino [import]uid: 200026 topic_id: 35932 reply_id: 142835[/import]

Thanks for response Brent. I followed the way you constructed the nebula complex body. So, you too have the local reference point for the nebula in the center(CenterReferencePoint) and divide the whole image in 4 quadrants. I realized that bottom right quadrant has both x and y positive and top left quadrant has both x and y negative. This coordinate system finally gave me the right coordinates for the complex body component shapes. The complex body now works perfect.

-Anshu [import]uid: 91950 topic_id: 35932 reply_id: 142969[/import]

Hi Anshu,
In regards to coordinates, you’re thinking along a Cartesian system, but this is actually shifted in Corona. The guide below explains it… and the principle applies to declaring physics bodies.
http://docs.coronalabs.com/guide/start/displayGroups/index.html

You might also want to read the tutorial on multi-element bodies here:
http://www.coronalabs.com/blog/2013/01/08/working-with-multi-element-physics-bodies/
And about physics event contact here:
http://www.coronalabs.com/blog/2012/11/27/introducing-physics-event-contact/

Hope this helps!
Brent Sorrentino [import]uid: 200026 topic_id: 35932 reply_id: 142835[/import]

Thanks for response Brent. I followed the way you constructed the nebula complex body. So, you too have the local reference point for the nebula in the center(CenterReferencePoint) and divide the whole image in 4 quadrants. I realized that bottom right quadrant has both x and y positive and top left quadrant has both x and y negative. This coordinate system finally gave me the right coordinates for the complex body component shapes. The complex body now works perfect.

-Anshu [import]uid: 91950 topic_id: 35932 reply_id: 142969[/import]