Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to react on warning message?
Started by GamingStudio17 Dec 12 2013 04:48 AM

14 replies to this topic
warning message
[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

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

How to react on warning message and delete polygon?

WARNING: Polygon could not be generated. The polygon outline is invalid, possibly due to holes or self-intersection.

 



[TOPIC: post.html]
#2

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

This is very important, please help.



[TOPIC: post.html]
#3

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

You need to post some code. It is obvious that you're trying to create an invalid polygon, but without your code we can't see what you're doing wrong.



[TOPIC: post.html]
#4

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

Yes, I create the wrong polygon, and my question is how to remove not properly created polygon? A warning message appears, but on the warning i can not react in the code.

 

require "physics"
physics.start()
physics.setDrawMode("hybrid")

local vertices = {-100,-100,100,-100,-110,-150,110,-150}
local polygon = display.newPolygon( 200, 200, vertices )
physics.addBody( polygon, "static", {density=1, friction=0, bounce=0 } )


[TOPIC: post.html]
#5

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

I would start with catching the error in a pcall and handling it from there. If the newPolygon throws an exception it should not return a polygon object, so there is nothing to remove. Handling the exception is what you want to be concerned with:

 

http://docs.coronalabs.com/daily/api/library/global/pcall.html



[TOPIC: post.html]
#6

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

horacebury, pcall not help. Sees no error.



[TOPIC: post.html]
#7

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

what i'm to do?



[TOPIC: post.html]
#8

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

Try rendering the polygon as a line and see if it looks right. I think the coordinates of the third point are wrong.

Does the newPolygon return an object or nil? If nil then there is nothing to remove. I suspect it is that function call which fails, not the addBody call.

[TOPIC: post.html]
#9

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

horacebury, this does not help, try yourself.



[TOPIC: post.html]
#10

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

I was finally able to try it myself. I've been responding on my phone.

 

There is no value or event returned in code that I can find to indicate that the polygon is self-intersecting. This is a shame because it's a very powerful function to have. There are, however, plenty of sites out there which provide code for detecting self-intersecting polygon definitions. Eg:

 

http://geomalgorithms.com/a09-_intersect-3.html



[TOPIC: post.html]
#11

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

[TOPIC: post.html]
#12

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

horacebury, thanks!



[TOPIC: post.html]
#13

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

Get done differently. I used physics.rayCast () to check the intersection. At the time when you draw a new side of the landfill, the beam scans the intersection with other lines.

Attached File  Снимок экрана 2013-12-16 в 0.57.22.png   2.69KB   2 downloads



[TOPIC: post.html]
#14

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,070 posts
  • Corona SDK

You can actually calculate line intersections quite easily yourself. I've written a routine in my mathlib library to do it:

 

http://developer.coronalabs.com/code/line-intersection

 

You'll need this to run with it:

 

https://developer.anscamobile.com/code/maths-library



[TOPIC: post.html]
#15

GamingStudio17

[GLOBAL: userInfoPane.html]
GamingStudio17
  • Contributor

  • 180 posts
  • Corona SDK

To understand that the polygon is not created, you can check object.contentHeight, If = 0 then the polygon intersects.




[topic_controls]
[/topic_controls]