Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

a problem with newOutline and physics bodies
Started by rune7 Mar 18 2014 03:15 AM

16 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Hi,

 

I'm trying to use the newOutline API to construct a physics body. however, there seem to be a problem when trying to use the outline to construct the physics body. 

In the game I use a picture and I then add a physics with a set of coordinates as outline.

 

In order to illustrate the issue, i've created a small app that takes the list of coordinates and creates a polygon object. if I simply create a physics object from the polygon, the created body is accurate.

However, If I use the set of coordinates as outline to the physics body, the generated body is completely wrong.

 

Any idea what might be wrong here?

 


local w = display.actualContentWidth
local h = display.actualContentHeight
 
local physics = require ("physics")
physics.start()
physics.setDrawMode( "hybrid" )
local createSegment = function()
    local imageOutline = {1,0,86,6,132,15,175,28,230,53,313,108,363,128,404,130,438,124,479,106,512,86,512,178,0,178,0,0}
    local line = display.newPolygon( 0, 0, imageOutline )
    line.y = 100
    line.x = 260
 
    physics.addBody(line, "static", { outline=imageOutline, density=1000, friction=0.0, bounce=0.0, filter=filter})
    --physics.addBody(line, "static", { density=1000, friction=0.0, bounce=0.0, filter=filter})
    
end
createSegment()



[TOPIC: post.html]
#2

ingemar

[GLOBAL: userInfoPane.html]
ingemar
  • Corona Geek

  • 2,733 posts
  • Enterprise

It looks like the polygon isn't closed.



[TOPIC: post.html]
#3

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

If you change the first point to be like the last (0,0), the polygon will not be created. The list of points is the output from newOutline API method, so this essentially should work, at least according to Corona samples.

 

You have an interesting point. When I add these lines to close the shape (after creating the polygon):

    table.insert(imageOutline, imageOutline[1])

    table.insert(imageOutline, imageOutline[2])

The physics body is created accurately.

But, when I use my actual images instead of the polygon, the physics body is still not created properly (instead its just a rect of the image size),

 

This looks like a bug.



[TOPIC: post.html]
#4

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

I'm not following where you're getting these coordinates. You state they come from the newOutline() API, but that's not in your code, so I can't see what kind of "coarseness" you had set upon it, nor the original graphic that you're pulling these coordinates from. Can you supply more details please?

 

Thanks,

Brent



[TOPIC: post.html]
#5

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Hi Brent, I just saved the trouble of extracting the outline and provided the actual coordinates to reduce the amount of steps.

I've used coarsenes level of 2. I've filed a bug report as well and I can send you the actual images used to create the outline from, if you let me know to which mail to send it.



[TOPIC: post.html]
#6

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

I'm not 100% sure, but you may be using the "outline" parameter in a way it wasn't intended to be used. If you modify the coordinates that newOutline() generates (i.e. by adding coordinates at the end), it may fuss and reject that application. May I ask why you're not just doing a multi-body physics shape?

 

Brent



[TOPIC: post.html]
#7

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Hi Brent, 

 

I was not modifiying the coordinates in my initial post.But Ingemar noted that the polygon is actually not closed, so I tested this by adding another point at the end to close the shape. It did do some good, but not solve the issue entirely. I've sent your support the original image files.



[TOPIC: post.html]
#8

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Any update on the subject?

I didn't get any news for the bug submitted either and this issue blocks our project.



[TOPIC: post.html]
#9

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

I really don't recommend trying to manually adjust coordinate points in the "outline" parameter table. Despite some documentation hinting that this could be done (I've since corrected it, and I apologize that it slipped out under my watchful eye), the "outline" parameter is meant to work alongside "graphics.newOutline()". However the image is "traced" and the output constructed cannot be guaranteed to follow the predictable Box2D rules. Thus, I sincerely urge you to build your physics bodies with multiple parts using the "shape" parameter and a capable physics body editor.

 

Best regards,

Brent



[TOPIC: post.html]
#10

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Hi Brent,

 

I'm sorry but I do not know why you keep getting at the maunal coordinates instead of addressing the issue. I've provided your team with both the original sample source code which uses the newOutline method along with my images in the bug report. There is no manupulation of line coordinates. this feature simply doesn't work on the samples I provided, despite having a proper alpha channel in all images.

 

Again, the example here, is just to save the time of using newOutline, see the actual numbers behind and to demonstrate that the problem may be in the body construction and not in the outline feature.

 

I hope you can address this issue promptly, as our project largly depend on it.



[TOPIC: post.html]
#11

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

Do you have a bug report number for me?

 

Thanks,

Brent



[TOPIC: post.html]
#12

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Case 31361



[TOPIC: post.html]
#13

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

I experimented with your 3 images and was able to get the expected results by adjusting the coarseness level to 2, 3, and 2 respectively. Much of using outlines will depend on this setting, and there's not one "magic value" that will provide the perfect outline on all images… you'll need to experiment with this value for each image. Or, if you want "perfect" outlines, you'll need to use the shapes method and a tracing application like Physics Editor.

 

Below is a screenshot of my results.

 

Best regards,

Brent

Attached Files



[TOPIC: post.html]
#14

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

Hi Brent,

 

Thanks for checking this.

I used coarseness level 2 on all three. and it failed for some. problem is, I have many such terrain images and I can not 'play' with the coarseness level in run time as there is no way to know that the method failed. I need it to work perfectly for some value. Currently, this feature is broken for us.



[TOPIC: post.html]
#15

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Why not just test these in advance and assign a look-up table to each one? It's a simple solution and could be overcome in a short time (an hour) or so. And it would provide you with the level of detail that matches each object… perhaps some can use 2, others use 5, others use 10, and you can optimize your body shapes by choosing the number that best suits each.

 

local coarsenessLookup = {
    forestFloor1 = 2,
    forestFloor2 = 3,
    forestFloor3 = 2,
}
 
--later
local imageName = "forestFloor1"
local imageOutline = graphics.newOutline( coarsenessLookup[imageName], imageName..".png" )
 

local image = display.newImage( imageName..".png" )
 
physics.addBody( image, { outline=imageOutline, bounce=0.5, friction=0.1 } )



[TOPIC: post.html]
#16

rune7

[GLOBAL: userInfoPane.html]
rune7
  • Contributor

  • 353 posts
  • Corona SDK

I have many images. and they may change during QA. I do not want to return and test it each time. It also raises fears that on some devices in runtime, the newOutline API will fail and we will not know about it. The players will simply fall from the floor and the game will be broken.

 

Note, In the example above, I took a step further and extracted the actual numbers for each image and then fed it to the physics add body method. it failed for the given coarsness level I used, when using the outline property. However, when I create a polygon with these values and set its physics body, it works. some thing there is now working properly and I cannot debug the source, so I need to rely on your team to iron this out.

 

I'm afraid this is not a viable solution for now.



[TOPIC: post.html]
#17

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @rune7,

The newOutline API won't succeed on some devices while failing on others, so in your testing and QA, what you see in the Simulator with "hybrid" mode should be what happens in the game.

 

At this point, I can think of three possible options:

 

1) Apply a coarseness level of 3 to everything. This seems to work on all three images you provided, and the level of accuracy is enough that I believe the game would "feel" correct in its physics behavior. If you test this in QA and notice that one object fails, implement the lookup method that I suggested, or use a coarseness level of 4.

 

2) If you need more fine-tuned shapes, i.e. if a complex wheeled vehicle will be rolling across this terrain, then define the objects using shapes. This is ultimately and by a great distance the best solution, without relying on any algorithm or tracing system. Unfortunately it's also the most time consuming… but there are several tools which help you do this, and easily modify/export shape definitions if you decide to tweak your images in QA.

 

3) Wait for our engineering team to investigate the issue… we have the bug report, but I know the primary engineer who worked on this feature is busy with several other high-priority tasks at the moment, so I can't provide an ETA on when this issue will be re-investigated.

 

Best regards,

Brent




[topic_controls]
 
[/topic_controls]