Back to Home

Launching the Bullet Physics physics engine on Android x86 / Intel Blog

android development · android ndk · game development · x86 · physics engine · mobile

Launching the Bullet Physics physics engine on Android x86

  • Tutorial

Photo source The
ever-increasing computing power of mobile devices is driving the development of mobile games. A whole class of games has appeared in the mobile segment, which is famous for realistic graphics and believable physics. Effects such as a grenade explosion in a shooter, skidding of a car in a race fall on the shoulders of a physical engine. The physical engine is based on mathematical models that are calculated during the game. As a rule, these are computational tasks, and the attractiveness of the game depends on how quickly and efficiently the physical engine copes with them.
This article shows how to build and port the Bullet Physics physics engineto the Android platform based on the Intel Atom processor.

Bullet physics


Bullet Physics Library is a real-time physical engine that is actively used in computer games, films, three-dimensional modeling programs, as a component of other game engines, and in many other more specific cases. In mid-2011, a version appeared that supported the Android OS and included functions optimized for ARM NEON.
Bullet Physics builds out of the box for ARM architecture. Such an application on phones with an Intel Atom processor will work through an emulator.
DeviceARM versionx86 version
Samsung Galaxy tab 3 10.130 FPS60 FPS

Table 1. Performance comparison (FPS - frames per second) of the ARM and x86 versions of the demo application from Bullet Physics.
Table 1 shows a comparison of application launches compiled for different architectures. Measurements were made using the Intel GPA graphics profiling tool . In order to achieve maximum efficiency and performance on devices based on Intel Atom - the application must be ported to the x86 architecture.
By increasing the speed of computing physics in his game, the developer receives an additional time frame budget, which he can spend either on more realistic graphics or on a more physical model.

Training


To build and port, we need:

The whole process will take place on Windows, for Linux / Mac OS it will not fundamentally differ. We will make test launches on the Lenovo K900 and Samsung Galaxy Tab 3 10.1. Both devices are based on the Intel Atom Z2460 processor.
A script is attached to the article, which performs all the described actions in automatic mode. Next, we will see how to assemble Bullet Physics in manual mode.

Assembly


First, build and run the PfxApp_1_Simple demo application under ARM.
image
Figure 1. PfxApp_1_Simple demo application (Samsung Galaxy tab 3 10.1 device).
Let's assemble the main component of the physical engine - the PfxLibrary library. To do this, go to the project directory of the library:
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary\jni

Is the path that the bullet-2.80-rev2531 project is on. In this directory, open the file “Android.mk”, find and change the variable
LOCAL_PATH := \bullet-2.80-rev2531\Extras\PhysicsEffects

Next, open the console. In the console, let's go along the path
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary

and execute the command:
ndk-build

We have compiled the PfxLibrary library under armeabi-v7a.
Now we will collect the demo application itself. To do this, transfer to the directory
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple\jni

In this directory, open the file “Android.mk”, change the variable
LOCAL_PATH := “\bullet-2.80-rev2531\Extras\PhysicsEffects

Next, open the console. In the console, go to the application project directory on the way
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple

and execute the “ndk-build” command. In order to run the assembled application PfxApp_1_Simple on the device, we will use Eclipse. In Eclipse, we import the project:
File => Import => Android => Existing Android Code Into Workspace => Browse ... => \ bullet-2.80-rev2531 \ Extras \ PhysicsEffects \ project \ Android \ PfxApp_1_Simple \ ”=> OK => Finish
and run the application on the device. To do this, right-click on the project and click: Run As => Android Application.
image
Figure 2. Launching the application from the Eclipse IDE.
The PfxApp_1_Simple application has started but works in emulation mode.

Porting


Build and run PfxApp_1_Simple under x86. First, port the PfxLibrary library to x86. To do this, go back to the library project directory
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary\jni

Open the file “Application.mk”, in which we change the variable
APP_ABI := x86

Then open the file “Android.mk”, in which we change the variables
LOCAL_PATH := \bullet-2.80-rev2531\Extras\PhysicsEffects
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -DUSE_PTHREADS –pthread
LOCAL_ARM_NEON := false

and delete the lines from LOCAL_SRC_FILES to remove the source files optimized for ARM Neon:
src/base_level/solver/pfx_constraint_row_solver_neon.cpp
include/vecmath/neon/vectormath_neon_assembly_implementations.S

Rebuild the physics engine. In the console, let's go along the path:
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxLibrary

and execute the “ndk-build” command. We have compiled the PfxLibrary library under x86. Now let's build the application under x86. To do this, go to the application project directory
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple\jni

In this directory, open the file “Application.mk”, change the variable
APP_ABI := x86

Then open the file “Android.mk”, in which we change the variables
LOCAL_PATH := “\bullet-2.80-rev2531\Extras\PhysicsEffects
LOCAL_SRC_FILES := project/Android/PfxLibrary/obj/local/x86/libpfxlibrary.a
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%)
LOCAL_ARM_NEON := false

and delete the lines from LOCAL_SRC_FILES, such as
         “sample/test_ARM_NEON_performance/neon_dot_product.S \”,
       	 “sample/test_ARM_NEON_performance/neon_cross_product.S \”,
         “sample/test_ARM_NEON_performance/neon_matrix4_operator_multiply.S \”,
         “sample/test_ARM_NEON_performance/neon_matrix3_operator_multiply.S \”,
       	 “sample/test_ARM_NEON_performance/neon_orthoInverse_transform3.S \”,
       	 “sample/test_ARM_NEON_performance/neon_transform3_operator_multiply.S \”,
       	 “sample/test_ARM_NEON_performance/neon_transpose_matrix3.S \”,
         “sample/test_ARM_NEON_performance/test_neon_cross_product.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_dot_product.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_matrix3_operator_multiply.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_matrix4_operator_multiply.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_orthoInverse_transform3.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_transform3_operator_multiply.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_transpose_matrix3.cpp \”,
         “sample/test_ARM_NEON_performance/test_neon_solve_linear_constraint_row.cpp”.

Next, in the console, go to the project directory on the way
\bullet-2.80-rev2531\Extras\PhysicsEffects\project\Android\PfxApp_1_Simple

and execute the “ndk-build” command. We launch the application on the device.
To check the result, the APK Info application was used .
image
Figure 3. Screenshots of APK Info (Lenovo K900 device).

Conclusion


The article provides step-by-step instructions on how to build and port the Bullet Physics physics engine. The result of successful porting to the x86 architecture, for a specific example, can be considered a twofold acceleration of physics calculations, as a result - an increase in the frame refresh rate (FPS).

About Authors


Ilya Kryukov ([email protected])
Denis Smirnov ([email protected])

Read Next