Java Reference
In-Depth Information
sphere.setTransform(trOrbitingPlanetoid);
appearance.setMaterial(planetoidMaterial);
g3d.render(sphere, trOrbitingPlanetoid);
// now draw the distant stationary planet
sphere.setTransform(trBigRemoteBlueGreen);
appearance.setMaterial(blueGreenMaterial);
g3d.render(sphere, trBigRemoteBlueGreen);
}
Normally in 3D games you need a fair bit of vector and matrix
mathematics to determine if any two objects collide in space. However,
in an FPS game, such as FindingHiggs , which has a high rate of fire and
runs on a mobile phone, performing these calculations to determine if
your shot hit its target can very quickly become a performance bottleneck.
In M3G, collisions can be detected using the pick() method of the
Group class. This method takes two vectors and a RayIntersection
instance as inputs. The first vector is a position in space and the second
is a direction. What happens (see Figure 8.9) is that the pick() method
finds the first object in the group (in z-order) that was intersected by a ray
fired from the position represented by the first vector (the position of the
player in space) in the direction of the second (down the axis of the gun
towards the attackers).
Ray
y +
Higgs Particles
z
Figure 8.9 Detecting collisions in M3G
It only performs the check against group members for which picking
is enabled and on return the RayIntersection instance contains
information such as the Node that was picked, the distance to it, and so
on. If no node was picked, the getIntersected() method returns null.
It should be obvious that this saves us a lot of work in our sample
game. In our context, 'picking' means getting shot, so to determine if we
hit an attacking Higgs particle, we only need to do the following:
private void handleWorldCollisions() {
if(isFiring()) {
...
// extract vectors from current player transform
float[] plyrPos = new float[16];

Search WWH ::

Custom Search