Git Product home page Git Product logo

Comments (28)

RandyGaul avatar RandyGaul commented on May 3, 2024 1

These are the faces defining the axis in each picture:

image

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024 1

No problem! :)

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024 1

I just noticed that if a c2Circle's center is over an edge of a c2Poly, then the depth gets very close to 0 and then starts to get bigger again:
depth_zero
I forked your project and did some changes and now the normals look good to me:
better_fix

Edit:
I also found the same behaviour for c2Circle vs c2AABB:
circle_aabb
Furthermore in this case the normal is flipped. I could fix it with some changes:
circle_aabb_better

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

The way to solve these kinds of problems is to render the manifold. Render the contact points, and draw a line along the normal scaled by the penetration depth. Center and draw this line upon each contact point. Disable the code that resolves collisions. Move the shapes together and find a configuration that gives you trouble.

If you see a manifold that does not make sense, after rending it, post it up here.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

Ok it renders each contact point and draws a line from 'contact point' to 'contact point + normal * depth' (I guess thats what you meant). This is what causes the circle to jump:
manifold_big
The normal gets smaller the deeper the circle goes into the polygon, from my understanding that should be the oposite.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

That is definitely incorrect! I'm fixing that now. Thanks for the rendering. Make sure to render any other problem cases you find, and I can quickly tell you if there's a bug.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

I pushed a fix for c2CircletoPolyManifold. I'm having trouble finding a bug involving AABB and poly though.

The thing about the collision normal, is if there are no bugs, the manifold normal should always point from shape A to shape B. A is the shape in the first parameter, and B is the shape in the second parameter. I am guessing in your AABB to poly gif, you have the normal flipped.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

I am testing the aabb case with the rendering right now, ill comment if I can find something.

Ill keep that in mind while testing, thanks for the fix gonna test it too :)

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

I think I found the problem with c2AABB. The normal changes from facing towards the aabb to facing to the opposite direction if I move over a corner of the polygon. That causes the aabb to jump towards the other side of the polygon:
change_dir

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Aaah. Yep. Inconsistent normal direction. I'll get out a fix for that soon. Thanks for gif. I'll add you as a contributor too!

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

Thanks :D I'll keep playing around with tiny2c. Gonna post again if I find something

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Pushed attempted fix for c2PolytoPolyManifold. Let me know if you still have troubles! Ganna close this issue out for now, but feel free to comment more.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

I don't know, the normals still look odd, but if I try to solve the collision everything works as expected. Gif of the normals:
normals_odd

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Looks like a bug in your manifold rendering? I'm not able to reproduce anything like that with my draw function:

void DrawManifold( c2Manifold m )
{
	c2v n = m.normal;
	tgLineColor( ctx, 1.0f, 0.2f, 0.4f );
	for ( int i = 0; i < m.count; ++i )
	{
		c2v p = m.contact_points[ i ];
		float d = m.depths[ i ];
		DrawCircle( p, 3.0f );
		tgLine( ctx, p.x, p.y, 0, p.x + n.x * d, p.y + n.y * d, 0 );
	}
}

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

I adjusted my function:

c2v n = manifold.normal;                                    
for (int i = 0; i < manifold.count; ++i) {
           c2v p = manifold.contact_points[i];
           float d = manifold.depths[i];
           n.x = n.x * d;
           n.y = n.y * d;
 
           // The line
           draw(p, c2Add(p, n));
           // The point
           draw(p, sf::Color::Red);
}

Now I get:
manifold_render

But its late and Im tired so I could be missing something obvious :)

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

If you'd like me to take a look, post a snapshot each shape. Just dump the floats out in a console or something so I can see the verts/normals. I'll copy paste it into my testbed and see what's up.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024
// Create aabb
c2AABB aabb;
aabb.min = c2V(150, 150);
aabb.max = c2V(200, 200);

// Create polygon
c2Poly poly;
poly.count = 4;
poly.verts[0] = c2V(30, 30);
poly.verts[1] = c2V(130, 40);
poly.verts[2] = c2V(100, 80);
poly.verts[3] = c2V(40, 60);

I also created a repo and pushed two of my tests as branches :)

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Are those the exact positions where they are intersecting, that you want me to look at?

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

No but here you go (poly the same as before):

aabb.min = c2V(50, 50);
aabb.max = c2V(90, 90);

My result:
screenshot from 2017-06-20 22-58-16

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024
    c2Poly poly;
    poly.count = 4;
    poly.verts[0] = c2V(30, 30);
    poly.verts[1] = c2V(130, 40);
    poly.verts[2] = c2V(100, 80);
    poly.verts[3] = c2V(40, 60);
    c2MakePoly( &poly );

    c2AABB aabb;
    aabb.min = c2V(50, 50);
    aabb.max = c2V(90, 90);

    tgLineColor( ctx, 1.0f, 1.0f, 1.0f );
    DrawPoly( poly.verts, poly.count );
    DrawAABB( aabb.min, aabb.max );

    c2Manifold m;
    c2AABBtoPolyManifold( aabb, &poly, 0, &m );

    if ( m.count )
    {
        DrawManifold( m );
    }

Gives me:

image

Which looks correct. Normal points from AABB to poly, and the manifold depths look correct.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Oh BTW the bug in your code is that your for loop scales the normal each time it runs (just noticed). Try this:

for (int i = 0; i < manifold.count; ++i) {
           c2v n = manifold.normal;    
           c2v p = manifold.contact_points[i];
           float d = manifold.depths[i];
           n.x = n.x * d;
           n.y = n.y * d;
 
           // The line
           draw(p, c2Add(p, n));
           // The point
           draw(p, sf::Color::Red);
}

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

The normal will always point along the axis of minimum penetration. In the top picture, the normals are pointing along the shortest distance to resolve the collision. As the shapes move deeper into each other and the vertex start hitting the AABB, the axis shifts. Since the axis of minimum penetration shifted, so does the normal; it points along the new direction for the shortest distance to resolve in the bottom picture.

For games, just trusting the manifold contents and performing some kind of collision resolution with disregard to shifting normals should look quite good during gameplay :)

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

Ohhh... Thank you, got it.
Sorry about the confusion I meant to write this:
One last question though:
Why does the position of the contact points change if I move the aabb so it is over the polygon corner?:

aabb.min = c2V(70, 50);
aabb.max = c2V(110, 90);

Old pos:
pos1

New Pos
pos2

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

The axis of minimum penetration used to sit on the polygon in the first picture. The internal algorithm clips the face on the other shape, against the shape the axis belongs to.

In the bottom picture the axis sits on the AABB, and a face on the polygon gets clipped.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

Ok makes sense now. I really appreciate your help and near instantaneous fixes

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

These are very good bugfixes. I am impressed! Please make a pull request with these fixes. I'm very busy this week, and cannot be as responsive as I was :)

The normals in your fixed version look exactly like what I intended. Lets get this into tinyc2 asap.

from cute_headers.

sro5h avatar sro5h commented on May 3, 2024

Thanks :) I'll send the pull request.
The depth should always be positive, right? Because only the normal should indicate the direction

from cute_headers.

RandyGaul avatar RandyGaul commented on May 3, 2024

Yes depth should remain consistently positive.

from cute_headers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.