none
Physics Engine Problem RRS feed

  • Question

  • Hi there guys! It's been some time because I am focusing on C++ with Allegro.

     

    I tried to code something like a little physics engine in small basic some time ago. Now I started working on it again.

    As you can see the box rotates and the box center moves around the corner as soon as it's touching the ground. But as you can also see, the corner slides a little around on the floor. How do I get rid of this? I want the corner to stay on the same spot till it's in the air again. I tried for so long, but I just couldn't find a solution!

     

    IMPORT CODE: TJS151

    [EDIT]

    Uploaded an updated version of the code. The bug is still there though.

     


    Live for nothing, OR CODE FOR SOMETHING!
    Wednesday, May 5, 2010 3:47 PM

Answers

  • There are a couple of issues.

    1] Small rounding errors (<1e-6) can cause the Y coordinate to be not on the ground (Y = 499.99999) after the rotations

    2] Must be careful to only have one corner on the ground at any point in time - needs checking first due to the tolerance introduced for the above reason.

    Modified code, Import RHN644-0

    • Marked as answer by Dudeson Monday, May 10, 2010 11:23 PM
    Wednesday, May 5, 2010 6:53 PM
    Moderator

All replies

  • There are a couple of issues.

    1] Small rounding errors (<1e-6) can cause the Y coordinate to be not on the ground (Y = 499.99999) after the rotations

    2] Must be careful to only have one corner on the ground at any point in time - needs checking first due to the tolerance introduced for the above reason.

    Modified code, Import RHN644-0

    • Marked as answer by Dudeson Monday, May 10, 2010 11:23 PM
    Wednesday, May 5, 2010 6:53 PM
    Moderator
  • 1] Small rounding errors (<1e-6) can cause the Y coordinate to be not on the ground (Y = 499.99999) after the rotations

    What does "(<1e-6)" mean?

     

    2] Must be careful to only have one corner on the ground at any point in time - needs checking first due to the tolerance introduced for the above reason.

    I don't get why we have to check that. I mean, how will we to detect if 2 corners are touching the ground so the object stops rotating??

     

    I worked on the code:

    - Added support for every kind of polygon. That means:

        You can set the corner amount and the maximum radius of the shape, and it will automatically generate a polygon.

    - You can grab the object with the left mouse button now.

    - Collisions are also being detected with the walls and the ceiling in the "Object_Checkwalls" Subroutine.

         But the Object just doesn't collide with the left wall... [FIXME PLEASE]

    - The Object's X and Y is the center of mass now.


    Import Code: SPF482
    Live for nothing, OR CODE FOR SOMETHING!
    Sunday, May 9, 2010 6:20 PM
  • Sorry, 1e-6 is shorthand for 0.000001 or 10^-6, a very small number. < is 'less than'.

    Of course if you want the shape to stop rotating when two corners are on the ground then you need more logic.  I have no idea what your final objectives are (collisions, deformation, angular momentum transfer ....) only help with the question you raised and the code you supplied:

    the corner slides a little around on the floor. How do I get rid of this? I want the corner to stay on the same spot till it's in the air again .

    With regard to you question (But thh e Object just doesn't collide witthe left wall... ) - the reason is:

    The shape is rotating round the screen clockwise, so say it starts on the bottom, it moves from bottom -> right -> top -> left.

    As it moves from one wall to the next it momentarily has two corners touching walls .  As before this need careful thought.  The results will depend on which one is used to update the shape centre (exactly as your original code problem) - only one can be used (the centre of the shape can only be set once, based on one corner point - how can we set the centre based on two different touching corners - these are different shape centres).  You check them in Object_Checkwalls in the order (bottom, left, right, top).

    When we move from bottom to right (both corners touching) your code centres the object on right (after bottom in your checking order).  Likewise top comes after right in your order, but left comes before top, therefore when you have top and left corners touching, your code centres the object on the left corner, then does it again (overwriting) for the top and therefore moves along the top, ignoring the left wall.

     

    Sunday, May 9, 2010 6:55 PM
    Moderator
  • I see...

    Thanks!

     

    I'm gonna start a new discussion then.

    My goal is actually to make a simple physics engine. No deformation and stuff. Just something simple that works with polygons. Maybe not even detection if sides of a polygon are touching, just the corners.


    Live for nothing, OR CODE FOR SOMETHING!
    Monday, May 10, 2010 2:09 PM