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.

DarkBASIC Professional Discussion / Box2D - Overlapping Object Problem

Author
Message
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Feb 2011 23:34 Edited at: 27th Feb 2011 23:34
In the image here, you can see that there are 6 cars, and many are overlapping. They were dropped to the ground, none of them overlapped before falling. Can anyone tell me what I have done wrong here?



Each vehicle is made up of one body with multiple fixtures...Yes I didn't realise this was possible but apparently it's the recommended way to make odd shaped objects. (Don't weld bodies together to do this, it doesn't work, they prise apart)

I'll post a second debug image to show that each body is represented by the correct fixture. The only other considerations are:

1. The fixtures overlap but from reading other forums, this is OK.
2. The current datum point for all fixtures is top left of the object (1,1)

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Feb 2011 23:36 Edited at: 27th Feb 2011 23:37
And here's the debug shapes...



baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 10:59
When you define the points they must be defined in a clockwise order without closing the shape for each fixture (don't define the first point twice), also make sure the shapes have no concave points.

That said they look well defined in the debug mode... you sure you didn't fix it?

I can send you the code for my Box2D level editor if you like?

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2011 11:42 Edited at: 28th Feb 2011 11:42
You may have hit on something there. I have made my own editor too but some of the checks are manual and not coded into the editor logic.

Shapes not closed -
Shapes concave -
clockwise definition...The wheels may have been defined anticlockwise, I didn't consider this in my rush. And I suppose if just one fixture is defined this way, it could throw the whole simulation out.

We should compare editor notes some time, maybe we could come up with the perfect all-round Box2D editor Screenshot attached of my simple approach.



BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2011 11:53
It was the anti-clockwise wheels They all fall perfectly into place now.

Thanks for the advice, I should have remembered that from the Cloth & Particles pack, the rules are the same there too.

On another side issue, do you know if the 0,0 point in the fixtures defines the centre of gravity? I'm sure I'll work it out but while I have your attention I'll ask the question If it does, I'll be adding it to my editor.

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 12:10
Glad I could help

Quote: "On another side issue, do you know if the 0,0 point in the fixtures defines the centre of gravity?"

I think it might be but I haven't tested the theory. Easy one to test though.

I've attached my editor (un-finished) so you can have a play. Mine's pretty basic and specific for one game in progress at the moment but I'd be happy to collaborate on an editor for general use...?

Oh, just hit enter a couple of times when it loads (I was testing something)

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 12:36
I just tested it and yes it automatically finds the centre of gravity, it's not based on the image at all.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2011 14:39
Nice editor, easy to use. I guess the file formats for static and dynamic objects, and the environment are your own formats?

I've attached my little editor for you and anyone else that finds it useful. It may still be a little bugged until I test it in anger. I plan to do more with it as the need arises. This is for creating individual objects rather than an environment. The simple process is:

1. Load an image
2. Left-Click or "M" to place markers around the image
3. Right-click or "X" to remove a marker
4. Don't worry about number of points, it will automatically Start a new entity (fixture) when required.
5. "N" to manually start a new entity (fixture). The next left-click will start marking again
6. "P" to delete current entity in whole (not recommended, a bit glitchy, just use "X" several times)
7. "S" to save.

Known issues
============

"P" as mentioned is bugged, doesn't reset marker numbers correctly
You must manually ensure no convex angles, and applied clockwise


Notes
======
Save creates a file (e.g myImage.png.b2d) with the following format, all values are saved as 1 string per line, readable in Notepad:

Value 1 - Number of points
Sets of 3 Values:
. Marker Pos X
. Marker Pos Y
. Entity (Fixture) number

To use Saved data
=================

1. Load image
2. Load values into array
3. Create Body
3. Create shapes
4. Create fixtures from shapes
5. Associate image with Body

Planned updates:
================
Enforce concave angles
Enforce clockwise application
Enhance auto-fixture creation to be more seamless

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 14:52
Quote: "I guess the file formats for static and dynamic objects, and the environment are your own formats?"

Yes, just text files but they contain different info so I didn't want them getting mixed up (loading a static object as dynamic would cause a crash). I could just put an additional parameter in there but it works.

I had a few ideas for the clockwise points as well as the concave check. It's actually what all those dots are in my demo... testing some checks.

Checking clockwise and concave is just a case of checking the angle between the first two points against the angle between the second two. It only gets really complicated when you allow the user to place the points in any order.

I'll take a look at your editor when I get a chance.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Feb 2011 15:52 Edited at: 28th Feb 2011 15:53
Hi, glad to see you've fixed the problem. I've been away the last two days so didn't see it until now

I can confirm what you've already worked out:
- Shapes must be defined clockwise (if positive Y is down and positive X is to the right, which is not always the case)
- You can have multiple fixtures on a body and they can overlap and have completely different properties (so you could have certain parts with more friction).
- Whenever possible, the engine automatically calculates the centre of mass, mass and inertia. Obviously the line shapes have no area and so no mass, so for shapes made entirely of line segments you would have to specify the mass, inertia and centre of mass manually or it will use default values.

[b]

Login to post a reply

Server time is: 2026-07-15 22:03:22
Your offset time is: 2026-07-15 22:03:22