raigan wrote:Wouldn't this cause problems, in that the effective mass of a cloned object would be scaled by the number of copies currently locked together? If a body is locked to a duplicate of itself, it will feel twice as heavy to the solver.
My thought was that since each body will be locked to the same number of duplicates (a constraint which would have to be very carefully imposed), the effective mass ratios will still come out to be equal. But even so, we'd have redundancy in the solver, for sure, and I don't know off the top of my head what unforeseen effects that might cause...
There will always be certain situations that no bounded number of duplicates could account for, as well - imagine one really long toothpick sitting in the world at an angle, it could wrap around the torus as many times as we want, and up to a constant, the number of wraps would be the number of domains/copies we'd need to consider to get the dynamics right.
Really you don't even want 4 different bodies, you should need only a single body state, interpreted in four different ways -- and "interpreted" means simply that the position is shifted. Orientation, velocity, etc could all be left alone since wrapping should have no effect on them.
Of course I'm not clear on how this could be nicely implemented, aside from adding code in all places where you calculate the vector from one position to another (to make sure you always consider the shortest-path to be the actual delta). You'd probably also want to use a grid/hash for collision since this can handle wrapping spaces naturally.
Yes, that would be ideal. The problem would be, as you mention, figuring out where to get this done.
I'm kind of half wondering whether modifying the vector math ops might be able to account for this; the issue there is that Box2d doesn't distinguish between vectors in position space and vectors in the tangent space, and the equivalence should only apply to those in position space.
I think ultimately to get something like that to work it would probably take a lot of internal edits, so it might not be plausible without someone really interested/committed/knowledgeable stepping in to see it through; further, I don't know that Erin would want so much special purpose code getting in to the trunk, as it would complicate later additions quite a bit.
Another possibility I'm considering is to subclass b2World and b2Body and bake in all sorts of special handling code to deal with wrapped worlds, manually updating the broadphase and patching up the contact graph as necessary. This would require re-writing a lot of the solver routines and whatnot, and manually checking collisions over the boundaries, but it just might be possible to do it with some work, or at least do it well enough to approximate the right behavior (let's ignore cases like the really long toothpick).
In the end, after all, the most common reason for needing something like this is probably just to have a simple asteroids-like world. I don't think most people are looking for perfect solver behavior across the boundaries, or stacks that wrap around the world several times.