Comments (28)
These are the faces defining the axis in each picture:
from cute_headers.
No problem! :)
from cute_headers.
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:
I forked your project and did some changes and now the normals look good to me:
Edit:
I also found the same behaviour for c2Circle
vs c2AABB
:
Furthermore in this case the normal is flipped. I could fix it with some changes:
from cute_headers.
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.
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:
The normal gets smaller the deeper the circle goes into the polygon, from my understanding that should be the oposite.
from cute_headers.
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.
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.
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.
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:
from cute_headers.
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.
Thanks :D I'll keep playing around with tiny2c. Gonna post again if I find something
from cute_headers.
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.
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:
from cute_headers.
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.
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);
}
But its late and Im tired so I could be missing something obvious :)
from cute_headers.
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.
// 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.
Are those the exact positions where they are intersecting, that you want me to look at?
from cute_headers.
No but here you go (poly the same as before):
aabb.min = c2V(50, 50);
aabb.max = c2V(90, 90);
from cute_headers.
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:
Which looks correct. Normal points from AABB to poly, and the manifold depths look correct.
from cute_headers.
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.
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.
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);
from cute_headers.
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.
Ok makes sense now. I really appreciate your help and near instantaneous fixes
from cute_headers.
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.
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.
Yes depth should remain consistently positive.
from cute_headers.
Related Issues (20)
- [cute_sound.h v2.x] Support multiple contexts. HOT 2
- http://randygaul.net is taken over by squatters HOT 1
- cute_net.h times out over the internet HOT 5
- Dynamically set panning for an individual playing sound HOT 2
- cute_aseprite.h - v1.3 Tilesets Discussion HOT 4
- cute_aseprite.h - Aseprite v1.3 property map support
- Cute_tiled "staggered" causes warning HOT 1
- inclusion of infinite maps and chunks HOT 3
- c2TOI returning wrong contact point
- cute_tls - allow ignoring certificate errors HOT 1
- cute_tiled: Force loading RGBA for tintedcolor
- cute_tiled: object `type` field HOT 4
- cute_2d c2PolytoPolyManifold issue HOT 2
- [Cute_Net.h] Knowing if a packet has been sent. HOT 3
- [cute_tiled_h]: Field `name` points to wrong memory address. HOT 2
- cute_aseprite.h "warning C4456: declaration of 'frame' hides previous local declaration"
- Usage of c2x and rotation HOT 1
- cute_aseprite.h crash with both 9-slice and pivot enabled. HOT 1
- cute_sound 2.x has no equivalent of 1.x cs_stop_sound
- cute_aseprite Crash on tags user data
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cute_headers.