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 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. -
BasePhysicsAppautomatically loads the Libbulletjme native library. -
BasePhysicsAppprovides:-
the
physicsSpacefield to access the space and -
the
visualizeShape()method to visualize the shape of a collision object.
-
-
Whereas
HelloLibbulletjmeusedupdate(intervalSeconds, 0)to simulate one step at a time,HelloSportattempts 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 the tutorial apps will use SPORT. Additional features of SPORT will be introduced as needed.