Improvements and ideas #399
Replies: 66 comments 3 replies
-
@Genbox Thank you for contacting me and expressing your interest in my fork of Box2D! I've been using the top-level REAME.md file to provide an overview of the changes that I've made in my fork. I believe it should be the file that GitHub presents at the top-level of the fork. Sounds like this information isn't as easy to find however as I'd like it to be. Here's the "run-down" that I've mentioned in that file:
I've been considering putting this information into a CHANGES file in the hopes of making it easier to find. Please let me know if you have any suggestions to this effect. Another place on GitHub where I've been documenting this kind of info is in the Projects tab. Hmm... maybe the Wiki would be even better for this. |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 6, 2017 20:38 @louis-langholtz I should have clarified. I read the list of changes you made in the readme, but I just expect there to be more hidden in the ~1400 commits you have made. There always are :) Your list is a place to start. Velcro Physics is written in C# where many of the changes you have made (namespaces, solution, global variables, non-member function etc.) is best practices, so I already did them way back in 2007 when I first ported Box2D. However, I'm very interested in rounded corner collisions, stable stacking and the physics stuff, as I think it can really improve the physics experience. I'd also be very interested in the unit tests you wrote (wow - 400 seems like a lot). I am a big fan of formal verification, and I always planned to have code contacts implemented, but since Microsoft pretty much killed it along with XNA (the framework I used for drawing in Farseer Physics Engine), I have to fall back to comprehensive unit tests instead. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the clarification. Erin Cato wrote about the mathematics he used in publications that I've read which have impressed me. I'd like to do the caliber of formal mathematical analysis that he's done but I'm afraid my math skills right now aren't up to his level (particularly in regards to differential equations - ODEs and PDEs). If they were, I'd love to relate what I did regarding rounded corner collisions and other physics stuff that way. I have made some posts in which I discussed the physics changes in what I suppose could be called more like "layman's terms". My posts haven't been comprehensive either as really I've been having a blast working on evolving the C++ library into my own vision for it and haven't paid much attention to documenting about it; perhaps at least not as much as I should. What do you see a conversation about the physics changes looking like or what would you like that to look like? |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 7, 2017 22:43 I guess I will have a better idea once I dive into the code and dig up some of the changes. For now, I have to go though ALL of Box2D and synchronize my port with changes made the past 4 years. After I'm done with that, I'll come back here and take a deeper look into what changes you made. As for the formal verification, I'm much like you. Eric is on a level I can only dream of, so most of the formal verification will be against a specification based on behavior rather than the math. It is more setting up some constraints on what input/output a method works with, and then have a static analysis tool sit in the background and analyse if you break those rules at any point in time, while developing. |
Beta Was this translation helpful? Give feedback.
-
Just an FYI update to this thread: I just added compile-time support for strongly-typed physical units. So no more needing to guess what the units are supposed to be for any given functions (unless they required unit-less, a.k.a. dimensionless, value like ratios). So for example, if the function or method took a length, it now takes that parameter as a |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 13, 2017 11:0 Are those some sort of type constraints in newer versions of C++? I mean, like functional languages where you can define an integer to have only the numbers from 5 to 10? |
Beta Was this translation helpful? Give feedback.
-
This new units interface places no restrictions on the range of the values; only on the types of the values. That said, I've also been working on ideas and code for doing range restrictions. Some of which is already in place. Like for iteration count types such as |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 13, 2017 22:17 I've just stumbled upon one of the things I made this issue for. Since the engine itself would never give an AABB in the wrong order, I think it would be for the better to implement it only for user supplied data for performance reasons. |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 13, 2017 22:32 I only now notices that Box2D never uses the constructor itself, only user supplied data goes in the constructor. |
Beta Was this translation helpful? Give feedback.
-
Is there an improvement you have in mind for the AABB class then? I'm not sure that I understand your last two comments about the AABB implementation/design but would like to be sure. :) |
Beta Was this translation helpful? Give feedback.
-
Just looked at the use of the AABB class more. Yes, there are places in the code where the AABB gets initialized with already minimized and maximized points only to have the constructor recheck that to ensure it's invariant about that. I am updating the AABB interface to avoid this recheck while still being able to enforce the invariant. |
Beta Was this translation helpful? Give feedback.
-
Update: with commit d361c51, I've just introduced what I consider a major change to the By design, this change does away with need of "ghost-vertices" at least for level surfaces. For a tutorial on what "ghost-vertices" are and why they were necessary see iforce2d's Box2D C++ tutorials - Ghost vertices. A shortcoming with the "ghost-vertices" solution was that it only solves the polygon getting stuck while being dragged across chained edge-shapes problem. It doesn't apply to dragging a polygon across a level floor made of rectangles for instance. The new manifold calculation mechanism though solves this problem for any shapes forming a level surface. |
Beta Was this translation helpful? Give feedback.
-
Commit a952a62 introduces vertex-radius respecting |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 30, 2017 9:28 Wow Louis. I have a couple of questions:
|
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 30, 2017 9:44 I tested the performance of different line intersection algorithms, I found that it is sometimes faster to do a quick AABB check before the intersection code. The AABB check is just a couple of range comparisons compared to at least 2 div instructions and sometimes sqrt. It might be different with C/C++ compilers though which are usually more aggressive in their optimizations compared to C#. |
Beta Was this translation helpful? Give feedback.
-
dynamic/relative penetration/slop sounds nice. maximum usable scale differences are of importance to me at least - and proper interaction between something human-sized and possibly moon-sized (or at least multiple magnitudes larger) sounds awesome. i'd gladly trade performance for possibility in that case. |
Beta Was this translation helpful? Give feedback.
-
I've seen some interesting idea in gpu-physics.js by schteppe: gif maybe interpreting small objects as radius-vertex geometry instead of volume geometry when interacting with big objects can ease resolving the conflict, maybe even consider a group of small objects as an area-rectangle interacting with big object, but that for sure will require lots of nancy stuff, just the extra thoughts. Relative slop & penetration may help, but the performance hit is still tremendous for TOI when huge asteroid of 500 fixture-triangle geometry flies upon 100 tiny triangles. I know very few how this stuff works, but the TOI not being optimized for multiple contacts incoming is an experimental observation as it lags all the way since small stuff is radius-close to the big object, that's when TOI starts to predict solving equation or something. That is not a very common scenario yet it happens. |
Beta Was this translation helpful? Give feedback.
-
@Hexlord performance hit: huge astroid could be represented by single/few chain shapes or chained boxed just representing it's surface. worked way faster for me when doing some tests with box2d a while ago. and the 100 tiny triangles, should they all be of equal size, could be done using particlesystem like in liquidfun. if it's 100 unique objects, i guess that'll be slow(er) even without any astroids around. |
Beta Was this translation helpful? Give feedback.
-
@ninnghazad yep, but chain shapes do not support holes. triangles are just the result of triangulation of geometry with holes, so liquidfun solution sadly won't work. 100 small objects work just fine if they meet small objects like eachother... Well that seems to be quite another problem as one mentioned before, yet still. |
Beta Was this translation helpful? Give feedback.
-
Incidentally, I've been considering what it'd take to implement a "negative" of a shape for implementing holes. I'd like that very much as we could for example have an inner disk (circle) shape be the negative of an outer one and have fully round rolling without jagged approximations. I believe that the plausibility of negative shapes has some corroboration in the implementation of the false condition of the joint collide connected property. It may be a while to implement negative shapes though since I first want to refactor contacts and joints into being subclasses of a constraint base class and then develop a better understanding of how ordering effects simulations. Ordering I can see then begetting constraint hierarchy which seems necessary for negative shapes. |
Beta Was this translation helpful? Give feedback.
-
@Hexlord Help me understand what you're describing in:
Do you mean simulating only velocity and acceleration and not simulating collisions? If you could reference specific code perhaps, that'd help me a bunch! Also, it's absolutely critical to make sure that we're using a release build of the library — i.e. with compiler optimization enabled to the fullest ( |
Beta Was this translation helpful? Give feedback.
-
@louis-langholtz Sorry for my puzzling description of what I mean. I did not inspect the new code very precisely, but it seems like some checks are unavoidable even if all vertices of all the bodies have 0 radius, slowing the performance. They seem relatively cheap for 0-radius case, but still that is the only misstep from max-performance way, so that probably should be optional (#ifdef PLAYRHO_VERTEX_RADIUS or smth). I support run-time configuration, but this functionality is high-load and four if-s can really mess the cpu performance... |
Beta Was this translation helpful? Give feedback.
-
@Hexlord I agree that four if's looks concerning but how concerning is it on a given hardware architecture in terms of reliably measurable performance loss? I ask because I don't know. My hope is that the Benchmark application will be increasingly used to measure these places (by calling the existing routines) and also to measure alternative coding strategies. Alternative functions can be added directly within the Benchmark itself to start with and possibly get migrated into the library as they prove useful. In terms of preprocessing out some of the Incidentally, what I'm more sure of is that I really dislike the length and complexity of the As another related side note, the alternative method for detecting almost equal that you'd provided for instance showed itself to be faster (which I saw after I increased the sensitivity of many of the tests in the benchmark application). It or the almost equal related unit tests however need some tweaks worked on since they don't match up exactly and can only be used on platforms where float and double are is_iec559 compliant I believe (in case you're interested in that 😄 ). |
Beta Was this translation helpful? Give feedback.
-
@louis-langholtz Actually if you always use zero radius that would be just one tick thanks to prediction, so not a problem at all... Cool stuff! Could be an experimental feature, but probably its win is not considerable in the whole simulation. |
Beta Was this translation helpful? Give feedback.
-
Just for reference, I'll note that Algodoo gives the ability to use shapes to clip one another, kind of like Snipperclips. Closed source code though :( |
Beta Was this translation helpful? Give feedback.
-
@NauticalMile64 yes but it converts those clipped shapes into polygon shapes, so basically it's just a way to edit polygon shapes; internally it doesn't support a colliders described by booleans I think (I'm pretty sure). |
Beta Was this translation helpful? Give feedback.
-
Hi, it seems flipping (vertically) bodies in Box2D is an obstacle for many users, since its quite common for 2D games with a side perspective. I did recently came into this problem, which feels like a dead end for my project. Imagine I have an excavator with multiple joints (wheels and a boom, which has a bucket jointed to it). If its facing a direction and then wants to move the other way, it has to flip/mirror/reflect vertically. Currently, the only solutions are quite complex. Recreating all the bodies, shapes, fixtures and joints, plus all the joints' bodies. Or having pre-created bodies of both directions and "hide" one of the direction from the Box2D and switch when a flip needs to happen. I was wondering what do you think about this and if a feature to simplify this would have a chance to be implemented. It would really help us less experienced users and may be migrate more Box2D users over to PlayRho. |
Beta Was this translation helpful? Give feedback.
-
@iderik Hello and thanks for your suggestion! Here's some thoughts that come to me at the moment regarding your proposal. The flipping that you're asking about sounds in part like a reflection transformation matrix applied to the coordinates of the shapes in order to derive reflected shapes. A free function operating over an iterable range of shapes that mutated those shapes per the transformation sounds doable and appealing to provide. This could probably benefit from extending the Reflecting joints sounds like another part to what you're asking for. I think it'd be a more involved than the former part of this and probably has to be done on a joint type by joint type basis. I've been considering a redesign of joints to replace the use of public inheritance with the same kind of on-use polymorphic design that I suspect the overall functionality would still need to effectively do the complex solution. I like the idea of providing free function code that takes care of those details however so to the user this at least looks simpler. |
Beta Was this translation helpful? Give feedback.
-
I've just merged in pull request #346. This introduces some new changes that I'm very excited about and greatly improve this library in my opinion. Here's a partial list of these improvements:
|
Beta Was this translation helpful? Give feedback.
-
Just an update to this topic... My most recent experimental work has been on a redesign of the fixture-and-shape types. If you're interested in what the actual code changes may look like, please take a look at the Fixtures have historically been like body specific customizations of shapes. Another way to look at fixtures, is as attributes, that all attachments of parts to bodies, have in common. Things like: the mass-data (such as mass-areal density), filter-properties, and the shape-body pair that this data associates with. In software I've already release, I'd begun moving some of these attributes around and had for instance shifted the mass-data to the This redesign has taken this idea further by eliminating the With this redesign, memory-wise, instead of each reference to a shape basically taking 16 bytes (on clang-LLVM based builds), the new identification based references take only 2 bytes. That's not so much for a single shape but for say a simulation with 1000 bodies each formerly having 1 fixture and all using the same shape, this represents a change from Speed-wise so-far, for at least the
So things are far from finished but I'm leaning towards eventually merging this change in and calling the result PlayRho 2.0. |
Beta Was this translation helpful? Give feedback.
-
From @Genbox on April 2, 2017 11:46
Hi Louis,
I've seen you active around the Box2D project, and it seems like you are keen to improve it and add features. I'm working on Velcro Physics, which is a Box2D port in C#, but extended with many new features such as path generators, better performance, concave polygons etc.
I'm interested in your port as it seems like you made some improvements and new features, but I have a hard time going through hundreds of files and look for them, so could we have a discussion here on what improvements you have made?
Copied from original issue: louis-langholtz/Box2D#12
Beta Was this translation helpful? Give feedback.
All reactions