i'm trying understand box2d , created 2 bodies(a ground , dynamic body floating). when dynamic body affected gravity, collides ground body, seems inside ground body.
is correct behaviour? or have bug in graphics renderer?
this "correct" behavior or not.
whether it's correct depends on details don't appear provided , define "correct". details how many iterations being used or sizes , densities in box2d terms of shapes displayed. , whether our definition of correct, based on box2d's documented behavior or expected physical behavior of solid bodies. sake of answer, i'll use former definition.
the b2world::step
method works resolve overlaps. positional resolution apply impulses bodies drive them towards target depth of penetration within bodies' skins. skin radius away vertices. polygon shapes, radial value b2_polygonradius
.
if shapes' skinned perimeters drawn, when zoomed in enough, we'll see shapes overlap each other fraction of skin radiuses. that's how box2d implemented @ least standard, overlap correct. on other hand, if shapes' vertices , edges drawn, shapes appear float on top each other when zoomed in enough.
we can see these behaviors break down when size or density of upper circle greater size of lower circle.
modifying testbed "heavy on light" test code larger circle has radius of 50.0 (instead of 5.0) while smaller circle has radius of 0.5 shows lower circle overlapped seen in following image: meanwhile increasing density of larger circle 10.0 1000.0 (instead of increasing radius beyond 5.0) shows overlap:
the box2d documention says things like:
in particular, box2d has been tuned work moving shapes between 0.1 , 10 meters. means objects between soup cans , buses in size should work well. static shapes may 50 meters long without trouble.
and like:
the suggested iteration count box2d 8 velocity , 3 position. can tune number liking, keep in mind has trade-off between performance , accuracy. using fewer iterations increases performance accuracy suffers. likewise, using more iterations decreases performance improves quality of simulation.
so based on box2d documentation, seemingly behavior can expected in combinations of settings , example picture considered correct. netero suggested, can trying increasing position iteration count see if improves matters. waiting longer while b2world::step
called more may reduce overlap. or changing sizes/densities.
as whether have bug in renderer, that's possible. again answer depends on details don't appear provided. details source code doing rendering. instance, if we're seeing result of rendering outlines of rectangles, want change instead rendering pixel wide lines between vertices or rendering solid innards defined vertices.
Comments
Post a Comment