Visualization using the SPORT graphics engine
The HelloLibbulletjme
app
(introduced on the previous page)
is simple, readable and complete.
However, as a console app, its output is limited to text.
Text provides scant insight into what the 3-D physics simulation is doing. For most people, pictures are much easier to understand.
For the purpose of this tutorial series, we’ve created a graphics engine named SPORT (the Simple Physics-ORienTed engine). SPORT enables us to visualize physics objects without adding much code to the tutorial apps. It is open-source, written in Java, and available from GitHub and Maven Central.
HelloSport
HelloSport (also in Kotlin)
is a direct conversion of HelloLibbulletjme
into a SPORT app.
Details to note:
-
The app is declared as a subclass of
BasePhysicsApp<PhysicsSpace>
, indicating that it will simulate a plainPhysicsSpace
. -
The app implements the 3 abstract methods of
BasePhysicsApp
(createSpace
,populateSpace
, andupdateSpace
), which are all invoked automatically. -
BasePhysicsApp
automatically loads the Libbulletjme native library. -
BasePhysicsApp
provides:-
the
physicsSpace
field to access the space and -
the
visualizeShape()
method to visualize the shape of a collision object.
-
-
Whereas
HelloLibbulletjme
usedupdate(intervalSeconds, 0)
to simulate one step at a time,HelloSport
attempts real-time simulation usingupdate(intervalSeconds)
.
Running HelloSport
should open a window on your computer’s desktop
and play a brief animation of a sphere falling onto a horizontal surface.
Pressing Esc should close the window and terminate the app.
Hereafter, all our tutorial apps will use SPORT. Additional features of SPORT will be introduced as needed.