Games [XUI2D] Floating Bodies Simulation

Discussion in 'Game Development' started by Erel, Oct 15, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User



    This is a small and nice example of simulating bodies thrown into water.
    It is inspired by this tutorial: http://www.iforce2d.net/b2dtut/buoyancy
    The implementation is different.

    The main task is to find the volume and center of mass of the underwater body. The floating force is -gravity * underwater volume. Volume = mass / density.
    The force is applied to the underwater center of mass.

    If you run it with debug drawing enabled you will see a green dot that marks the center of gravity of the underwater bodies:
    [​IMG]

    I used a "brute force" approach to find the mass and center of mass.
    We take the rotated CompressedBC object and count the the number of non-transparent pixels in each row.
    There is an assumption that there are no holes in the body (only relevant for the center of mass).

    The code to go over the CompressedBC pixels is based on CompressedBC internal structure. It is not part of the public API of BitmapCreator.

    This example is included in the example pack.

    It is recommended to use BitmapCreator v4.31+ with this example.
     
    Marcus Araujo, fredo, jmon and 9 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice