Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Finding the outline/convex hull of a series of polys

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Oct 2017 06:28 Edited at: 26th Oct 2017 08:07
Here is my problem;
I am trying to find the outline of a shape which consists of a series of polys (I'm reading the shape in from a .obj file so the vertex are sorted by poly)
I have tried Jarvis and Graham's convex hull algorithms and they seem to be culling vertex (which i don't want)
I have all the information of an .obj file at my disposal.
Can anyone help me solve this problem? I need to be able to draw the outline starting from any point and then continue clockwise.
Any help would be greatly appreciated



*** EDIT *** Added some code as an example
Red/Green dots are points (Green dot is the starting point)
White lines are the Jarvis Convex hull

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Oct 2017 08:41
My theory (which I haven't tested) is to use collision.
Choose a starting point, then rotate a line clockwise until it collides with the shape.
Now you have your first face and a tangent.
Repeat from the new point. If you rotate beyond 180 degrees from the previous tangent, you have a concave angle and must start a new shape. Close the previous shape with its first point.

I have implemented this as a manual process, drawing lines around a shape, and having program logic to detect the concave angles.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th Oct 2017 08:57 Edited at: 26th Oct 2017 09:03
i found a old vb6 code example here (green download button) , it have a small module data and pointgeometry, i think you can easy convert for your needings.
the files you can open with notepad.
http://www.vb-helper.com/howto_convex_hull.html
Single = Float
byref = ref (agk integer only via a type i believe)
between With and End With you must use the whole name in agk.
in form there is only load/save points and the visuals, to start outline it begings here EditorForm mnuTestsConvexHull_Click() event.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS High Sierra (10.13)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Oct 2017 09:00 Edited at: 26th Oct 2017 09:05
Here's the thing. If you look at the points in the image i posted, it could be at least two different shapes.
How can a generic algorithm determine which shape that group of dots is (Just using the series of dots)?

Same points different shape

Attachments

Login to view attachments
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Oct 2017 10:10 Edited at: 26th Oct 2017 10:14
What is it that you're trying to achieve?
It looks like you want to create a 2D convex hull from a 3D file.
Is that correct? And if so is it just for a single specified project of the 3D object?

And a side note:
There is only one shape that could be generated using a convex hull algorithm. The second shape would be rejected because it is concave.
[Edit] Come to think of it ... the first shape is also concave and would be rejected by the algorithm.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Oct 2017 11:36 Edited at: 26th Oct 2017 11:39
Yes. It is a requirement that the 2D shapes are defined by a 3D model (The z vertex is thrown away). There are 33 individual shapes in this set and let's say 8 sets
It must be possible because if i trace each poly i get the shape. its just trying to figure out how to trace around the edge of those polys
Bat Vink's idea has given me something to think about.
I'll percolate a bit on it

My ultimate goal is to produce shapes that can be used by the 2D Physics commands; SetSpriteShapePolygon ( iSpriteIndex, numPoints, index, x, y )
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th Oct 2017 13:28 Edited at: 26th Oct 2017 13:33
if you think in lines of each triangle, you can remove this one which have the same start end (overlap), then the rest of lines are the outline.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS High Sierra (10.13)

Attachments

Login to view attachments
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 26th Oct 2017 14:23
Quote: "My ultimate goal is to produce shapes that can be used by the 2D Physics commands; SetSpriteShapePolygon ( iSpriteIndex, numPoints, index, x, y )"

Finding a work around for that car of yours eh?

Sweet!

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Oct 2017 20:19
Quote: "if you think in lines of each triangle, you can remove this one which have the same start end (overlap), then the rest of lines are the outline."

Yes! I thought of exactly that last night. Couldn't get to sleep. Using Bat Vink's idea i could then calculate the angle of each attached vertex, adjust it so it's relative to the angle of the last found edge and the smallest angle is the next edge

Quote: "Finding a work around for that car of yours eh?"

Haha. Maybe
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Oct 2017 04:16 Edited at: 27th Oct 2017 04:16
After much gnashing of teeth and finally getting what BatVink and Markus were saying it worked

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Oct 2017 11:28
Congrats
I could do this semi-manually, but you have done well to automate it.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Oct 2017 12:18
I agree. but there are other steps and elements and i didn't want to complicate things. The freedom to design in a modelling proggy is very powerful i think
Thanks to you and markus very much. I would have been floundering without your direction
Hopefully i can make something of this.
I'm sure i'll have a lot more questions
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Oct 2017 01:56
I can have a shape poly that is a line. Is that right?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Oct 2017 19:59 Edited at: 29th Oct 2017 19:59
ok. mapping the box2d shapes to 3D. Sorry the recording is a bit crappy, but you can get an idea of whats happening.
I think i can add some pitch and yaw post box2D
Is it proper car physics? I don't think so
Will it be fun?! I think it just might

Thanks heaps to Mr BaxSlash for the 2D car physics

puzzler2018
User Banned
Posted: 29th Oct 2017 20:36
pixel-perfect collision is what you need - Phealax done a great job



puzzler2018
User Banned
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Oct 2017 01:14 Edited at: 30th Oct 2017 01:15
I'm not sure i need pixel perfect collision as i will make sure the cars are a rectangle shape.
I did have to do some work to get the 2D/3D numbers to line up but i think it's ok now.
If you download the app and run it you will see the 2D render doesn't match the 3D render but that's just a perspective thing. The collision is perfect IMHO

The magenta object is a flat 3D model and the Green object is a 3D cube. Take it for a spin and tell me what you think!

Attachments

Login to view attachments
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 30th Oct 2017 08:10 Edited at: 30th Oct 2017 08:10
That's a thing of beauty. Nice work!
The steering could do with being more responsive but the collision is bang on.

You've got the makings of one of my all time favorite games there ... Super Skidmarks for the Amiga. If you can replicate anything close to that you'd have a fine game indeed
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Oct 2017 08:54 Edited at: 30th Oct 2017 08:54
That looks nifty. I'm going for a mario kart type setup but i'm sure you could achieve any kart type game.
Added a camera (Very wonky right now)

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Oct 2017 03:36
Going back to the original question, couldn't you just determine which edges are not shared? Outer edges would only belong to a single polygon. Assuming the vertex data is in a sorted order.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Oct 2017 03:53


1. I was able to make the shapes but the 2D Physics system wouldn't interpret them properly

2 In the end i just created a shape for the inside of the track and a shape for the outside i then created a sprite shape with two points for each edge. I think this will work out better in the long run because i can have multiple shapes making multiple paths

Login to post a reply

Server time is: 2024-04-19 01:31:48
Your offset time is: 2024-04-19 01:31:48