Game Development Reference
In-Depth Information
Now we have a situation similar to the steel ball in the ocean, only this time it is a tiny
silicon ball in the ocean of air surrounding the earth. When the sensor is moved deeper
or shallower in the atmospheric ocean, the pressure on the outside of the diaphragm
changes. This causes the pressure differential to change and a force to be exerted on the
silicon diaphragm. This force causes a deflection that changes the resistance of the pie‐
zoresistive material and can therefore be measured by the sensor. This part will be taken
care of by the hardware and the encoded value sent to the operating system.
To give you an example, in the Android operating system, the API has a public method,
getAltitude(float p0, float p) , to determine altitude, in meters, between the sen‐
sor pressure and the pressure at sea level. It usually reads the current atmospheric pres‐
sure, p , from the sensor by listening to sensor manager callback interface method ab
stract void onSensorChanged(SensorEvent event) . Here the class event holds the
sensor values, the accuracy of those values, a reference to the sensor itself, and a time‐
stamp for when the event occurred. The pressure is reported in hectoPascals (hPa) or
100 N/m 2 . The sea-level pressure, p0 , that this is compared to is either obtained from
an online database or is set at the constant SensorManager.PRESSURE_STANDARD_ATMOS
PHERE . As pressure at sea level changes with different weather conditions, we obtain
higher accuracy by retrieving it from a nearby airport or other weather station via the
Internet. To get the change in altitude between two points, you must repeat this process
twice as follows:
float altitude_difference =
pressure_at_point2) -
At first it may seem strange for your cell phone to have a barometer in it; however, the
barometer's ability to detect the air pressure allows you to make a good guess on your
altitude. As shown in Chapter 22 , in order to determine your position via GPS you have
to solve a four-dimensional set of linear equations. The time required to solve these
equations can be dramatically decreased if you know approximately where you are to
begin with. Currently, the position of which cell phone tower your phone is connected
to is used as a starting point. Using a barometer allows the device to guess its altitude
to further reduce the time to obtain a GPS fix.
While the sensor was included for a specific purpose, it can also be adapted as an input
device. For instance, the Bosch BMP180 currently being included in devices is accurate
to plus or minus one meter. In fact, Google Maps now provides indoor directions, in‐
cluding knowing what floor you are on in airports and shopping malls. This function‐
ality could be used to aid in the location-based gaming discussed in Chapter 22 by giving
it greater resolution in the vertical dimension. It could also be used to determine if the
user is holding the phone near her feet or her head, further augmenting the orientation
Search Nedrilad ::

Custom Search