A 2D impulse-based physics engine designed around data-driven constraints. This is a port/expansion of a physics engine I spent over 2 years making into java after it outgrew its previous platform in scale and needs.
A 2D impulse-based physics engine designed around data-driven constraints. This is a port/expansion of a physics engine I spent over 2 years making into java after it outgrew its previous platform in scale and needs.
GJK Algorithm:
I worked on porting my implementation of GJK over to the new Java physics engine.
I added a system of saving points and lines to be rendered each frame for debugging. To save these, I created new classes to save color data along with their respective points and lines. With the introduction of drawing specific data, I split the multi-threading synchronized lock into separate drawing data and object data locks.
I added keyboard input logging. It keeps track of when keys are pressed and released. So far, it is only used to pause the simulation using the space key. This was important for inspecting the data of individual frames to find errors. Soon, I plan to add more frame controlling keys to quickly recreate and debug issues.
With the help of the new debug tools, I was able to pause and inspect frames for what went wrong instead of attempting to make sense of hundreds of console debug lines.
GJK works off of a simple idea to determine collisions. Imagine a shape where a point was created from all possible combinations of shape A’s points subtracted from shape B’s points. If that new shape contained the coordinates (0,0), then the two shapes are colliding. However, calculating all of these (mostly interior) points is quite computationally expensive. Instead, you can find the points furthest in opposite directions to guarantee a perimeter point. In addition to that, by specifying the target direction (relative to the other found points and the origin) you can find whether the new shape contains the origin with only 3 points. Although does occasionally require a few iterations to create a working simplex, it is significantly more efficient.
Log in to leave a comment
Base engine:
I started porting my engine a little over a week before I decided to submit the file to flavor town.
I started off learning Java Swing and Jframe, as well as how to keep my code thread-safe. Once I had a solid base to transfer information back and forth between threads, I began working on a rendering system.
While working on the rendering, I also started defining the class for physics objects. To simplify functions and allow the return of both x and y coordinates from them, I created a Vector class that holds both coordinates and functions that use or modify coordinates.
To help test future collisions, I added the ability to move/throw shapes by dragging them.
Of the three stages of Collision (AABB, GJK, and EPA), so far I have completed AABB, or Axis Aligned Bounding Box. This is a lightweight check designed to identify objects that could not be touching. Currently, I’m working on implementing GJK and EPA to detect collisions between objects.
Log in to leave a comment