Game Development Reference
In-Depth Information
Now, we will update the
ModelTest.java
file as follows:
• Code for ray picking
• Orthographic camera for displaying FPS and the buttons
•
InputAdapter
to handle the input from user
First, add the code to
MyCollisionTest.java
as follows:
public class MyCollisionTest extends ApplicationAdapter {
PerspectiveCamera cam;
ModelBatch modelBatch;
Environment environment;
MyCollisionWorld worldInstance;
btRigidBody groundBody;
MyContactListener collisionListener;
Sprite box, cone, cylinder, sphere, raypick, tick;
ClosestRayResultCallback rayTestCB;
Vector3 rayFrom = new Vector3();
Vector3 rayTo = new Vector3();
BitmapFont font;
OrthographicCamera guiCam;
SpriteBatch batch;
...
}
Here, we added the custom classes that implement the physics as well as the images,
font, camera, and
SpriteBatch
to control the 2D plane. We also added the
Vector3
objects for ray testing.
Next, we update the
create()
method to initialize our classes as follows:
@Override
public void create() {
...
worldInstance = MyCollisionWorld.instance;
worldInstance.init();
groundBody = worldInstance.create_ground();
int w = -10;
for (int i = 0; i < 10; i++) {