0XDE57 / SpaceProject

An arcadey physics based top-down 2D, procedurally generated asteroid miner sandbox game using libGDX.
Apache License 2.0
38 stars 9 forks source link

destructible asteroid producing too many pieces #2

Open 0XDE57 opened 1 year ago

0XDE57 commented 1 year ago

sometimes extra shards are produced when shooting asteroids. duplicate vertices?

0XDE57 commented 1 year ago

" Box2D expects Polygons vertices are stored with a counter clockwise winding (CCW). We must be careful because the notion of CCW is with respect to a right-handed coordinate system with the z-axis pointing out of the plane.

The body definition gives you the chance to initialize the position of the body on creation. This has far better performance than creating the body at the world origin and then moving the body.

Caution: Do not create a body at the origin and then move it. If you create several bodies at the origin, then performance will suffer. A body has two main points of interest. The first point is the body's origin. Fixtures and joints are attached relative to the body's origin.

The second point of interest is the center of mass. The center of mass is determined from mass distribution of the attached shapes or is explicitly set with b2MassData. Much of Box2D's internal computations use the center of mass position. For example b2Body stores the linear velocity for the center of mass. When you are building the body definition, you may not know where the center of mass is located. Therefore you specify the position of the body's origin. You may also specify the body's angle in radians, which is not affected by the position of the center of mass. If you later change the mass properties of the body, then the center of mass may move on the body, but the origin position does not change and the attached shapes and joints do not move. "

see:

        B2D::body->GetLocalCenter()
        GeometryUtils.polygonCentroid()

        API Addition: Polygon methods setVertex, getVertex, getVertexCount, getCentroid.
        API Addition: GeometryUtils,polygons isCCW, ensureClockwise, reverseVertices
0XDE57 commented 1 year ago

broken origin is also affecting drops location not being centered on asteroid. shifted origin visible with b2dddebug on

EDIT: moved to it's own issue -> #30

0XDE57 commented 1 year ago

didn't mean to close.

0XDE57 commented 1 year ago

[AsteroidShatterSystem] WARNING: polygonCentroid disagreement [AsteroidShatterSystem] Duplicate point! Discarding triangle

0XDE57 commented 1 year ago

I must ensure all shapes I pass into box2d are legal and no vertices overlap. todo: also look into removing co-linear points?

see: https://github.com/erincatto/box2d/pull/735 for hints on valid hull shapes.