Game Development Reference
In-Depth Information
Getting ready
Before we begin with more physics-related functions, we should set up the basic applica-
tion.
First of all, we create a new class that extends SimpleApplication .
Later on, we're going to use the following two lists:
private List<Geometry> segments;
private List<Point2PointJoint> joints;
We also need some strings as input mappings: LEFT_CLICK , RIGHT_CLICK , and
TOGGLE_PHYSICS .
We add a RigidBodyControl field called selectedSegment that will contain the
last selected segment in the game.
Since we're strictly making a 2D game, we should change the camera to be orthographic.
This can be done by performing the following steps:
1. Disable flyCam .
2. Find out the aspect ratio by dividing the cam width by its height and storing it.
3. Set cam.parallelProjection to true .
4. Then, change frustrum of the camera to suit and orthographic view as follows:
cam.setFrustum(1, 1000, -100 * aspect, 100 * aspect,
100, -100);
5. We move it some way along the z axis and rotate it back towards the center, as fol-
lows:
cam.setLocation(new Vector3f(0, 0, 20));
cam.setRotation(new Quaternion().fromAngles(new
float[]{0,-FastMath.PI,0}));
Now, we can initialize bulletAppState as we usually do. Turn on the debug mode, and
most importantly, set speed to 0 . We don't want any physics on while we build the bridge.
Search WWH ::




Custom Search